按钮的Caption自动回行问题 - C++ Builder / Windows SDK/API
SetWindowLong(Button1->Handle, GWL_STYLE,
GetWindowLong(Button1->Handle, GWL_STYLE)|
BS_MULTILINE);
上面的可以实现Button自动回行...现在我想让BitButton也能达到这种效果...用同样的方法为啥不灵呢
SetWindowLong(BitBtn1->Handle, GWL_STYLE,
GetWindowLong(BitBtn1->Handle, GWL_STYLE)|
BS_MULTILINE);
[解决办法]
感觉是因为TBitBtn上面有图形,它每次重绘时会重设button的STYLE,所以你在外面改了没用,要研究一下源码才明白了
[解决办法]
SetWindowLong(BitBtn1-> Handle, GWL_STYLE , GetWindowLong(BitBtn1-> Handle, GWL_STYLE) & ~BS_OWNERDRAW | BS_MULTILINE);
截取WM_DRAWITEM消息,画图形
或者,再添加一个属性,以下是delphi的代码
type
TMultCapProperty = Class(TCaptionProperty)
Public
Function GetValue: string; Override;
Procedure SetValue(const Value: string); Override;
End;
procedure Register;
function TMultCapProperty.GetValue: string;
begin
Result := GetStrValue;
//计算长度,去掉 '\n '
end;
procedure TMultCapProperty.SetValue(const Value: string);
var
Caption : string;
begin
Caption := Value;
//计算长度,添加 '\n '
SetStrValue(Caption);
end;
procedure Register;
begin
RegisterPropertyEditor(TypeInfo(TCaption), TLabel; , 'Caption ', TMultCapProperty);
RegisterPropertyEditor(TypeInfo(TCaption), TButton; , 'Caption ', TMultCapProperty);
end;