checkbox 只读 不想用enable 那样灰灰地不好看 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 checkbox1.State:=cbGrayed; 把CheckBox放在一个Panel里面,然后把Panel的Enabled设置为False。 //------------------------------------------------------------------------------// 控件只读设置//------------------------------------------------------------------------------procedure EnableControl(AControl: TWinControl; Enable: Boolean);begin with AControl do if Enable then SetWindowLong(Handle, GWL_STYLE, (not WS_DISABLED) and GetWindowLong(Handle, GWL_STYLE)) else SetWindowLong(Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(Handle, GWL_STYLE));end;procedure TForm1.Button1Click(Sender: TObject);begin EnableControl(CheckBox1,False); //end;procedure TForm1.Button2Click(Sender: TObject);begin EnableControl(CheckBox1,True);end; 二楼三楼都是非常不错的答案例如二楼原理: Enabled=False的窗口(在二楼是一个Panel),不会获得焦点. 这就象在MainFrm模态显示一个窗体, 实际上就是令MainFrm.Enabled=False一样的道理. 3楼的方法可能是好的,但是似乎要按button1才起效(这时看起来是亮的),放在FormCreate或FormActivate都不行,是灰的。都感谢。 试了一下,不能放在FormShow, 可以放在FormOnActive里:procedure TForm1.FormActivate(Sender: TObject);begin Self.Update; SetWindowLong(Self.CheckBox1.Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(Self.CheckBox1.Handle, GWL_STYLE));end; 老大,在你的机器上checkbox是亮的吗?如在10楼,在我这灰灰的,和enable=false一样。 注意我用的是OnActive,并且加了一句Self.Update; 我找到了在我这灰灰的原因,我把它和一个groupbox叠放就是灰灰的,把蛇单放在Form上就不灰了。但我还是想把它放在proupbox上,无论如何感谢。请到我下贴中领分(其中预留有你的)。http://topic.csdn.net/u/20080925/13/e5d14fea-37f9-45da-a954-63896f7d081a.html烦心的Application.OnMessage:= 在主程序中部分无效 如何把一个窗体装载道另一个窗体的一个TPanel上 如何实现一个网络对战五子棋的设计,希望高手指点! 紧急求救一sql语句,谢谢啦 有关treeview删除节点的操作!! 怎样在ClientSocket发送数据时,在ProgressBar中显示进度? 想问问大伙的看法 MDI子窗口切换! 关于delphi存储过程控件使用碰到的一个问题,在线等待!!! spcomm控件应用 有关midas,ado,dcom编程的问题 希望版主增加一个无满意揭帖区,或发贴的时候显示同时显示无满意揭帖率 TWebBrowser 脚本
checkbox1.State:=cbGrayed;
//------------------------------------------------------------------------------
// 控件只读设置
//------------------------------------------------------------------------------procedure EnableControl(AControl: TWinControl; Enable: Boolean);
begin
with AControl do
if Enable then
SetWindowLong(Handle, GWL_STYLE, (not WS_DISABLED) and GetWindowLong(Handle, GWL_STYLE))
else
SetWindowLong(Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(Handle, GWL_STYLE));
end;procedure TForm1.Button1Click(Sender: TObject);
begin
EnableControl(CheckBox1,False); //
end;procedure TForm1.Button2Click(Sender: TObject);
begin
EnableControl(CheckBox1,True);
end;
试了一下,不能放在FormShow, 可以放在FormOnActive里:procedure TForm1.FormActivate(Sender: TObject);
begin
Self.Update;
SetWindowLong(Self.CheckBox1.Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(Self.CheckBox1.Handle, GWL_STYLE));
end;
http://topic.csdn.net/u/20080925/13/e5d14fea-37f9-45da-a954-63896f7d081a.html
烦心的Application.OnMessage:= 在主程序中部分无效