按钮的标题中的换行字符 [英] Newline character in caption of button
问题描述
我正在构建一个应用程序,其中我想在表单上显示一个按钮。我想在两行显示按钮的标题。我已经尝试在表单的OnCreate事件中使用以下代码,但它没有显示新行。
Button.Caption:= '你好'+#13#10 +'world';
添加新行的任何其他方法?
对于非常旧的不具有WordWrap属性的Delphi版本:
在设置标题之前使用以下代码:
SetWindowLong(Button1.Handle,GWL_STYLE,
GetWindowLong(Button1.Handle,GWL_STYLE)或BS_MULTILINE);
但棘手的部分是这个代码需要多次执行。当重新创建按钮时,您的多行设置将丢失。类似于这个困境。
如下:
type
TButton = class(StdCtrls.TButton)
protected
procedure CreateParams(var Params:TCreateParams);覆盖
结束
TForm1 = class(TForm)
...
程序TButton.CreateParams(var Params:TCreateParams);
begin
继承CreateParams(Params);
Params.Style:= Params.Style或BS_MULTILINE;
结束
I am building an application in which I want to display a button on a form. I want to display the Caption of the button on two lines. I have tried using the following code in the form's OnCreate event but it is not showing the new line.
Button.Caption := 'Hello' + #13#10 + 'world';
Any other method to add a new line?
For very old Delphi versions which do not have the WordWrap property:
Use following code prior to setting the caption:
SetWindowLong(Button1.Handle, GWL_STYLE,
GetWindowLong(Button1.Handle, GWL_STYLE) or BS_MULTILINE);
But the tricky part is that this code needs execution on a number of occasions. When the button is recreated, then your multiline setting is lost. Kind of similar to this dilemma.
Luckily the VCL provides a solution, but you have to subclass the TButton type, e.g. as follows:
type
TButton = class(StdCtrls.TButton)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
TForm1 = class(TForm)
...
procedure TButton.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or BS_MULTILINE;
end;
这篇关于按钮的标题中的换行字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!