一些小技巧和杂项

  • 如果想让一些控件有多行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;

  • 在窗口的任意位置放置字符
http://topic.csdn.net/t/20020828/22/978607.html#r_achor
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均相同
http://hackdiy.com/I-7441885.html
有时候平面效果看起来更顺眼, 而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
http://topic.csdn.net/u/20080603/16/78e83d17-2cbe-4525-beec-110c15f5c019.html    的15楼, 感谢blazingfire
要控制外部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句是关键






待续...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值