我想让FORM 的右上角的关闭按钮不能用,只用一个最小化按钮,如何做? 我想让FORM 的右上角的关闭按钮不能用,只用一个最小化按钮,如何做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BorderIcons := [biMinimize]; 在bordericos 里面设置就可以了 form->BorderIcons -> only bMinimizi is True other all are false 在OnClose事件 里面写 Abort就可以了。当然你真的想要关闭的时候,就要多做一点事情了。 以下程序改自网上代码,前提是把Form的BorderIcons的biSystemMenu设为Falseunit Unit1;interfaceuses Windows, Buttons, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) procedure FormResize(Sender: TObject); private { Private declarations } public { Public declarations } CaptionBtn:TRect; procedure DrawCaptButton; procedure WMNCPaint(var Msg:TWMNCPaint);message WM_NCPaint; procedure WMNCActivate(var Msg:TWMNCActivate);message WM_NCActivate; procedure WMSetText(var Msg:TWMSetText);message WM_SetText; procedure WMNCHitTest(var Msg:TWMNCHitTest);message WM_NCHittest; procedure WMNCLButtonDown(var Msg:TWMNCLButtonDown);message WM_NCLButtonDown; end;var Form1: TForm1;implementationconst htCaptionBtn=htSizeLast+1;{$R *.dfm}procedure TForm1.DrawCaptButton;var xFrame,yFrame,xSize,ySize:Integer; R:TRect;begin xFrame:=GetSystemMetrics(SM_CXFRAME); yFrame:=GetSystemMetrics(SM_CYFRAME); xSize:=GetSystemMetrics(SM_CXSIZE); ySize:=GetSystemMetrics(SM_CYSIZE);// caption:=inttostr(ysize); //按钮属性调整->> CaptionBtn:=Bounds(Width-xFrame-5*xSize+2,yFrame+2,xSize+13,ySize-4); Canvas.Handle:=GetWindowDC(Self.Handle); Canvas.Font.Name:='宋体'; //Canvas.Font.Color:=clblack; //Canvas.Pen.Color:=clYellow; Canvas.Brush.Color:=clBtnFace; try DrawButtonFace(Canvas,CaptionBtn,1,bsAutoDetect,False,False,False); R:=Bounds(Width-xFrame-5*xSize+3,yFrame+3,xSize+10,ySize-7); with CaptionBtn do Canvas.TextRect(R,R.Left+5,R.Top,'-'); finally ReleaseDC(Self.Handle,Canvas.Handle); Canvas.Handle:=0; end;end;procedure TForm1.WMNCActivate(var Msg: TWMNCActivate);begininherited; DrawCaptButton;end;procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);begininherited; with Msg do if PtInRect(CaptionBtn,Point(xPos-Left,yPos-Top)) then Result:=htCaptionBtn;end;procedure TForm1.WMNCLButtonDown(var Msg: TWMNCLButtonDown);begininherited; if(Msg.HitTest=htCaptionBtn)then Sendmessage(handle,WM_SYSCOMMAND,SC_MINIMIZE ,0);end;procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);begininherited; DrawCaptButton;end;procedure TForm1.WMSetText(var Msg: TWMSetText);begininherited; DrawCaptButton;end;procedure TForm1.FormResize(Sender: TObject);begin Perform(WM_NCACTIVATE,Word(Active),0);end;end. 你还是菜鸟啊,属性里就可以设啊! beyondtkl(大龙驹<逝追.弗瑞德>) form->BorderIcons -> only bMinimizi is True other all are false,就ok! 对我同意 fangerhua 的说法即简单又快捷 楼上的你自己试过没有,不要乱说人家。其实你也是菜鸟,把很多事情都想当然了,你自己试试看吧。agree 我的回复 确实是不对的 刚才去试了一下 没有选biSystemMenu 再选 biMinimizi为true也是不对的我当时确实是有点想当然了 汗 对不起了 楼主向 linzhengqun(风。全面提高回贴质量) 学习.....唉 偶还是太菜了.. unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; bool: boolean;implementation{$R *.dfm}procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin if bool then action := canone;end;procedure TForm1.FormCreate(Sender: TObject);begin bool := true;end;procedure TForm1.Button1Click(Sender: TObject);begin bool := false; form1.Close;end;end. 设置窗体属性:BorderIcons := [biMinimize];这样就行,还有象上面的用API那种方法也可以。反正方法很多,看你喜欢哪个了。 CloseQuery 在这个事件中写:canclose := false; 即可 向 linzhengqun(风。全面提高回贴质量) 学习 BorderIcons := [biMinimize]; 去查查windows api ,好像是deletemenu或deletesystemmenu之类的东东。 但我似乎理解错楼主的意思了,楼主是说标题上只有一个最小化按钮。还是说其他按钮也有,只是其他按钮不可用呢。如果是第一种,就是我的回复中如果是第二种,就是 gaodu2002(旖旎) 的回复 如何把drawgrid做成excel的样子(仅外观) 请问如何post数据,数据包已经截下来,麻烦高手写个代码,谢谢了 很久没来,听说有人要请我吃饭? 如何实现如下格式数据 小弟问个简单问题 比较弱的问题,请不吝赐教 第一个月做程序员的疑问 delphi设置ini文件动态读取数据库配置,为什么跳不出Fdataset delphi中怎么在table中加入可修改的临时字段 急、急、急,汉字转动如何实现? findwindows函数怎么能找的label里的内容呢? 如何在DBGRID的某一列添加COMBOX控件?急啊,会的兄弟姐妹帮忙!
当然你真的想要关闭的时候,就要多做一点事情了。
Windows, Buttons, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
procedure FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
CaptionBtn:TRect;
procedure DrawCaptButton;
procedure WMNCPaint(var Msg:TWMNCPaint);message WM_NCPaint;
procedure WMNCActivate(var Msg:TWMNCActivate);message WM_NCActivate;
procedure WMSetText(var Msg:TWMSetText);message WM_SetText;
procedure WMNCHitTest(var Msg:TWMNCHitTest);message WM_NCHittest;
procedure WMNCLButtonDown(var Msg:TWMNCLButtonDown);message WM_NCLButtonDown;
end;var
Form1: TForm1;implementationconst
htCaptionBtn=htSizeLast+1;
{$R *.dfm}procedure TForm1.DrawCaptButton;
var
xFrame,yFrame,xSize,ySize:Integer;
R:TRect;
begin
xFrame:=GetSystemMetrics(SM_CXFRAME);
yFrame:=GetSystemMetrics(SM_CYFRAME);
xSize:=GetSystemMetrics(SM_CXSIZE);
ySize:=GetSystemMetrics(SM_CYSIZE);
// caption:=inttostr(ysize);
//按钮属性调整->>
CaptionBtn:=Bounds(Width-xFrame-5*xSize+2,yFrame+2,xSize+13,ySize-4);
Canvas.Handle:=GetWindowDC(Self.Handle);
Canvas.Font.Name:='宋体';
//Canvas.Font.Color:=clblack;
//Canvas.Pen.Color:=clYellow;
Canvas.Brush.Color:=clBtnFace;
try
DrawButtonFace(Canvas,CaptionBtn,1,bsAutoDetect,False,False,False);
R:=Bounds(Width-xFrame-5*xSize+3,yFrame+3,xSize+10,ySize-7);
with CaptionBtn do
Canvas.TextRect(R,R.Left+5,R.Top,'-');
finally
ReleaseDC(Self.Handle,Canvas.Handle);
Canvas.Handle:=0;
end;
end;procedure TForm1.WMNCActivate(var Msg: TWMNCActivate);
begin
inherited;
DrawCaptButton;
end;procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
inherited;
with Msg do
if PtInRect(CaptionBtn,Point(xPos-Left,yPos-Top)) then
Result:=htCaptionBtn;
end;procedure TForm1.WMNCLButtonDown(var Msg: TWMNCLButtonDown);
begin
inherited;
if(Msg.HitTest=htCaptionBtn)then
Sendmessage(handle,WM_SYSCOMMAND,SC_MINIMIZE ,0);
end;procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);
begin
inherited;
DrawCaptButton;
end;procedure TForm1.WMSetText(var Msg: TWMSetText);
begin
inherited;
DrawCaptButton;
end;procedure TForm1.FormResize(Sender: TObject);
begin
Perform(WM_NCACTIVATE,Word(Active),0);
end;end.
即简单又快捷
其实你也是菜鸟,把很多事情都想当然了,你自己试试看吧。agree
我当时确实是有点想当然了 汗 对不起了 楼主
向 linzhengqun(风。全面提高回贴质量) 学习.....唉 偶还是太菜了..
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
bool: boolean;implementation{$R *.dfm}procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if bool then
action := canone;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
bool := true;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
bool := false;
form1.Close;
end;end.
BorderIcons := [biMinimize];
这样就行,还有象上面的用API那种方法也可以。反正方法很多,看你喜欢哪个了。
楼主是说标题上只有一个最小化按钮。
还是说其他按钮也有,只是其他按钮不可用呢。
如果是第一种,就是我的回复中
如果是第二种,就是 gaodu2002(旖旎) 的回复