- 如果想让一些控件有多行caption, 如下:
http://topic.csdn.net/t/20020828/22/978607.html#r_achor
复选框:
chk1.Caption := 'Line1 '#13#10'Line2 ';
SetWindowLong(chk1.Handle, GWL_STYLE,
GetWindowLong(chk1.Handle, GWL_STYLE) or BS_MULTILINE);
chk1.Refresh;
按钮:
btn1.Caption := '按钮标题1'#13#10'标题2';
SetWindowLong(btn1.Handle, GWL_STYLE,
GetWindowLong(btn1.Handle, GWL_STYLE) or BS_MULTILINE);
btn1.Refresh;
- 在窗口的任意位置放置字符
var
MyRect: TRect;
const
str = '万一的 Delphi 博客';
begin
MyRect.Left := 0;
MyRect.Top := 50;
MyRect.Right := 0 + 100;
MyRect.Bottom := 0 + 100;
DrawText(lv1.Canvas.Handle, str, -1, MyRect, DT_LEFT);
end;
- 如果有有2个窗体, 之间想要相互控制各自的控件, 肯定要uses对方的.pas了,
但是不能2个都在interface下加, 其中一个可以加在
//unit2.pas中
implementation
uses Unit1;
//unit1.pas中
interface
uses Unit2;
- 改变listview的选中行颜色
設置 listview 的
hottrack:=true;
houtrackstyle:=[htHandPoint] //很奇怪﹐一定要設置這個才行 (注:测试过, 没设置也是可以的)
rowselect:=true;
再寫 ONCustomDrawItem 如下就可以了
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
DefaultDraw:=false;
if cdshot in state then
begin
listview1.Canvas.Font.Color:=clred;
listview1.Canvas.Brush.Color:=clblack;
end;
DefaultDraw:=true;
end;
以上照做后, 只是在鼠标指向的时候变色, 离开恢复
如果想点击后, 改变被点击行的底色, 则
OnCustomDrawItem事件中
if Item.Selected then
begin
Item.ListView.Canvas.Brush.Color:=$00CF724B;
end
else
begin
Item.ListView.Canvas.Brush.Color:= clInactiveCaptionText;;
end;
即可
- CheckBox的平面效果 // Button, RadioButton 设置方法function均相同
有时候平面效果看起来更顺眼, 而Ctl3D的设置却无效果.
一开始的type定义里面加上 procedure SetFlat; 然后 procedure TForm1.SetFlat;//设置为平面效果 var a: Integer; begin a := GetWindowLong(Form1.chk1.Handle, GWL_STYLE);// 获得原窗口风格 SetWindowLong(Form1.chk1.Handle, GWL_STYLE, a or BS_FLAT); //设置为平面风格 Form1.chk1.Invalidate; // 重画CheckBox end; 然后一般在formCreat的时候就运行一次SetFlat, 即可
- 控制外部ComboBox
要控制外部ComboBox选中摸一个选项的命令
SendMessage(ComboBox.Handle, CB_SELECTSTRING, 0, Integer(PChar('111'))); //这行选中 111 的这个项
SendMessage(ComboBox.Handle, CB_SETCURSEL, cbbIndex, 0); //cbbIndex是指外部combobox的第几个选项
这2行选一, 都是操作外部combobox选中所需项
SendMessage(ComboBox.Handle, CN_COMMAND, MakeLong(0, CBN_SELCHANGE), 0); //如果目标是Delphi程序,让ComoBox触发其OnChange事件
对于控制外部程序, 第2句是关键
待续...