对于想了解Delphi中让窗口关闭按钮无效的6种方法的读者,本文将是一篇不可错过的文章,我们将详细介绍delphi中让窗口关闭按钮无效的6种方法是,并且为您提供关于C#winform中窗口关闭按钮的隐
对于想了解Delphi中让窗口关闭按钮无效的6种方法的读者,本文将是一篇不可错过的文章,我们将详细介绍delphi中让窗口关闭按钮无效的6种方法是,并且为您提供关于C# winform中窗口关闭按钮的隐藏与禁用详解、Delphi TTabControl 在 TabItem 添加关闭按钮、Delphi TTabControl在TabItem添加关闭按钮、delphi – 不支持vcl样式的标签页的关闭按钮的有价值信息。
本文目录一览:- Delphi中让窗口关闭按钮无效的6种方法(delphi中让窗口关闭按钮无效的6种方法是)
- C# winform中窗口关闭按钮的隐藏与禁用详解
- Delphi TTabControl 在 TabItem 添加关闭按钮
- Delphi TTabControl在TabItem添加关闭按钮
- delphi – 不支持vcl样式的标签页的关闭按钮
Delphi中让窗口关闭按钮无效的6种方法(delphi中让窗口关闭按钮无效的6种方法是)
总结
以上是小编为你收集整理的Delphi中让窗口关闭按钮无效的6种方法全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
C# winform中窗口关闭按钮的隐藏与禁用详解
首先说一句:
不存任何一种方式可以单独隐藏关闭按钮,隐藏的话会把所有最大化,最小化,帮助,关闭按钮都给隐藏掉。
第一种:禁用窗口上部的关闭按钮
方法一:在Form1的窗口程序中desigener设计器中重写如下方法:(将此部分粘贴到窗口程序中去就可以了)
protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE) { return; } base.WndProc(ref m); }
方法二:就是在窗口的FormClosing事件中加上这样一句话就可以了
e.Cancel=true
第二种:隐藏掉窗口上部的关闭按钮
方法一:在窗口的初始化事件中加上this.Control=false;这样一句话就可以了
public mainForm() { InitializeComponent(); this.ControlBox = false; }
方法二:将窗口的FormBoderstyle属性设置为None。这种方法是将整个标题栏去掉了。
补充知识:C#Winform去掉边框后,窗体最大化,任务栏被遮挡问题!
问题描述:
为了自定义设置界面的标题,边框样式,我们通常会把winform窗体的边
框属性设置为None,但去掉边框的窗体在最大化时会挡住电脑桌面的任务栏,
但任务栏的时间、输入法等我们仍然需要用到,因此任务栏必须显示出来。
解决方法:
在窗体初始化完后,加入
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
或
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
例:
public MainFrm() { InitializeComponent(); this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea; }
以上这篇C# winform中窗口关闭按钮的隐藏与禁用详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
- C# Winform实现圆角无锯齿按钮
- C# Winform按钮中图片实现左图右字的效果实例
- C#中Winform 实现Ajax效果自定义按钮
- C#中Winform窗体Form的关闭按钮变灰色的方法
- C# Winform实现捕获窗体最小化、最大化、关闭按钮事件的方法
- c# winform取消右上角关闭按钮的实现方法
- C# Winform实现圆角无锯齿按钮
Delphi TTabControl 在 TabItem 添加关闭按钮
unit uFMXTabItemWithCloseBtn;
interface
uses
FMX.TabControl;
type
TTabControlHelper = class helper for TTabControl
private
procedure CloseButtonClick(Sender: TObject);
procedure TimerOnTimer(Sender: TObject);
public
procedure CheckCloseBtn(const iBtnResourceName: String = ''closebutton'');
end;
implementation
uses
System.UITypes
, System.Classes
, FMX.Types
, FMX.StdCtrls
;
{ TTabControlHelper }
var
GRemoveTimer: TTimer;
GIndex: Integer;
GRemoveTab: TTabItem;
GTabControlHelperChecked: Boolean = False;
procedure TTabControlHelper.CheckCloseBtn;
var
B: TFmxObject;
TabItem: TTabItem;
i: Integer;
begin
if (GTabControlHelperChecked) then
Exit;
for i := 0 to TabCount - 1 do begin
TabItem := Tabs[i];
B := TabItem.FindStyleResource(iBtnResourceName);
if (B <> nil) and (B is TCustomButton) then begin
B.TagObject := TabItem;
TabItem.AutoSize := False;
TabItem.Width := TabItem.Width + TCustomButton(B).Width * 1.5;
TCustomButton(B).OnClick := CloseButtonClick;
GTabControlHelperChecked := True;
end;
end;
end;
procedure TTabControlHelper.CloseButtonClick(Sender: TObject);
var
TabItem: TTabItem;
i: Integer;
Len: Integer;
begin
if (Sender is TCustomButton) then begin
GRemoveTab := TTabItem(TCustomButton(Sender).TagObject);
GIndex := -1;
Len := TabCount - 1;
for i := 0 to Len do begin
TabItem := Tabs[i];
if (TabItem = GRemoveTab) then begin
if (i = Len) then begin
if (Len > 0) then
GIndex := i - 1;
Break;
end
else begin
GIndex := i;
Break;
end;
end;
end;
GRemoveTab.Release;
TabIndex := -1;
if (GIndex <> -1) then begin
GRemoveTimer := TTimer.Create(nil);
GRemoveTimer.OnTimer := TimerOnTimer;
GRemoveTimer.Interval := 20;
GRemoveTimer.Enabled := True;
end;
end;
end;
procedure TTabControlHelper.TimerOnTimer(Sender: TObject);
var
Ist: Boolean;
i: Integer;
begin
Ist := False;
for i := 0 to TabCount - 1 do
if (Tabs[i] = GRemoveTab) then begin
Ist := True;
Break;
end;
if (Ist) then
Exit;
GRemoveTimer.DisposeOf;
GRemoveTImer := nil;
GRemoveTab := nil;
TabIndex := GIndex;
end;
end.
然后在主程序上进行调用
unit Unit1;
interface
uses
System.SysUtils
, System.Types
, System.Classes
, System.Generics.Collections
, FMX.Types
, FMX.Controls
, FMX.Graphics
, FMX.Forms
, FMX.StdCtrls
, FMX.TabControl
;
type
TForm1 = class(TForm)
StyleBook1: TStyleBook;
TabControl1: TTabControl;
TabItem1: TTabItem;
TabItem2: TTabItem;
TabItem3: TTabItem;
procedure FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
private
public
end;
var
Form1: TForm1;
implementation
uses
uFMXTabItemWithCloseBtn;
{$R *.fmx}
procedure TForm1.FormPaint(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
begin
TabControl1.CheckCloseBtn;
end;
end.
Delphi TTabControl在TabItem添加关闭按钮
unit uFMXTabItemWithCloseBtn; interface uses FMX.TabControl; type TTabControlHelper = class helper for TTabControl private procedure CloseButtonClick(Sender: TObject); procedure TimerOnTimer(Sender: TObject); public procedure CheckCloseBtn(const iBtnResourceName: String = ‘closebutton‘); end; implementation uses System.UITypes,System.Classes,FMX.Types,FMX.StdCtrls ; { TTabControlHelper } var GRemoveTimer: TTimer; GIndex: Integer; GRemoveTab: TTabItem; GTabControlHelperChecked: Boolean = False; procedure TTabControlHelper.CheckCloseBtn; var B: TFmxObject; TabItem: TTabItem; i: Integer; begin if (GTabControlHelperChecked) then Exit; for i := 0 to TabCount - 1 do begin TabItem := Tabs[i]; B := TabItem.FindStyleResource(iBtnResourceName); if (B <> nil) and (B is TCustomButton) then begin B.TagObject := TabItem; TabItem.AutoSize := False; TabItem.Width := TabItem.Width + TCustomButton(B).Width * 1.5; TCustomButton(B).OnClick := CloseButtonClick; GTabControlHelperChecked := True; end; end; end; procedure TTabControlHelper.CloseButtonClick(Sender: TObject); var TabItem: TTabItem; i: Integer; Len: Integer; begin if (Sender is TCustomButton) then begin GRemoveTab := TTabItem(TCustomButton(Sender).TagObject); GIndex := -1; Len := TabCount - 1; for i := 0 to Len do begin TabItem := Tabs[i]; if (TabItem = GRemoveTab) then begin if (i = Len) then begin if (Len > 0) then GIndex := i - 1; Break; end else begin GIndex := i; Break; end; end; end; GRemoveTab.Release; TabIndex := -1; if (GIndex <> -1) then begin GRemoveTimer := TTimer.Create(nil); GRemoveTimer.OnTimer := TimerOnTimer; GRemoveTimer.Interval := 20; GRemoveTimer.Enabled := True; end; end; end; procedure TTabControlHelper.TimerOnTimer(Sender: TObject); var Ist: Boolean; i: Integer; begin Ist := False; for i := 0 to TabCount - 1 do if (Tabs[i] = GRemoveTab) then begin Ist := True; Break; end; if (Ist) then Exit; GRemoveTimer.dispoSEOf; GRemoveTImer := nil; GRemoveTab := nil; TabIndex := GIndex; end; end. 复制代码 然后在主程序上进行调用 unit Unit1; interface uses System.SysUtils,System.Types,System.Generics.Collections,FMX.Controls,FMX.Graphics,FMX.Forms,FMX.StdCtrls,FMX.TabControl ; type TForm1 = class(TForm) StyleBook1: TStyleBook; TabControl1: TTabControl; TabItem1: TTabItem; TabItem2: TTabItem; TabItem3: TTabItem; procedure FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); private public end; var Form1: TForm1; implementation uses uFMXTabItemWithCloseBtn; {$R *.fmx} procedure TForm1.FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); begin TabControl1.CheckCloseBtn; end; end.
delphi – 不支持vcl样式的标签页的关闭按钮
procedure TFormMain.PageControlCloseButtonDrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean); var CloseBtnSize: Integer; PageControl: TPageControl; TabCaption: TPoint; CloseBtnRect: TRect; CloseBtnDrawState: Cardinal; CloseBtnDrawDetails: TThemedElementDetails; begin PageControl := Control as TPageControl; if InRange(TabIndex,Length(FCloseButtonsRect) - 1) then begin CloseBtnSize := 14; TabCaption.Y := Rect.Top + 3; if Active then begin CloseBtnRect.Top := Rect.Top + 4; CloseBtnRect.Right := Rect.Right - 5; TabCaption.X := Rect.Left + 6; end else begin CloseBtnRect.Top := Rect.Top + 3; CloseBtnRect.Right := Rect.Right - 5; TabCaption.X := Rect.Left + 3; end; CloseBtnRect.Bottom := CloseBtnRect.Top + CloseBtnSize; CloseBtnRect.Left := CloseBtnRect.Right - CloseBtnSize; FCloseButtonsRect[TabIndex] := CloseBtnRect; PageControl.Canvas.FillRect(Rect); PageControl.Canvas.textout(TabCaption.X,TabCaption.Y,PageControl.Pages[TabIndex].Caption); if not UseThemes then begin if (FCloseButtonMouseDownIndex = TabIndex) and FCloseButtonShowPushed then CloseBtnDrawState := DFCS_CAPTIONCLOSE + DFCS_PUSHED else CloseBtnDrawState := DFCS_CAPTIONCLOSE; Winapi.Windows.DrawFrameControl(PageControl.Canvas.Handle,FCloseButtonsRect[TabIndex],DFC_CAPTION,CloseBtnDrawState); end else begin Dec(FCloseButtonsRect[TabIndex].Left); if (FCloseButtonMouseDownIndex = TabIndex) and FCloseButtonShowPushed then CloseBtnDrawDetails := StyleServices.GetElementDetails(twCloseButtonPushed) else CloseBtnDrawDetails := StyleServices.GetElementDetails(twCloseButtonnormal); StyleServices.DrawElement(PageControl.Canvas.Handle,CloseBtnDrawDetails,FCloseButtonsRect[TabIndex]); end; end; end;
解决方法
如果你在实现样式钩子时遇到问题,请告诉我在这里发布一个完整的解决方案.
UPDATE
我刚刚写了这个简单的样式钩子来为标签页中的关闭按钮添加suport.
uses Vcl.Styles,Vcl.Themes; type TTabControlStyleHookBtnClose = class(TTabControlStyleHook) private FHotIndex : Integer; FWidthModified : Boolean; procedure WMMouseMove(var Message: TMessage); message WM_MOUSEMOVE; procedure WMLButtonUp(var Message: TWMMouse); message WM_LBUTTONUP; function GetButtonCloseRect(Index: Integer):TRect; strict protected procedure DrawTab(Canvas: TCanvas; Index: Integer); override; procedure MouseEnter; override; procedure MouseLeave; override; public constructor Create(AControl: TWinControl); override; end; constructor TTabControlStyleHookBtnClose.Create(AControl: TWinControl); begin inherited; FHotIndex:=-1; FWidthModified:=False; end; procedure TTabControlStyleHookBtnClose.DrawTab(Canvas: TCanvas; Index: Integer); var Details : TThemedElementDetails; ButtonR : TRect; FButtonState: TThemedWindow; begin inherited; if (FHotIndex>=0) and (Index=FHotIndex) then FButtonState := twSmallCloseButtonHot else if Index = TabIndex then FButtonState := twSmallCloseButtonnormal else FButtonState := twSmallCloseButtondisabled; Details := StyleServices.GetElementDetails(FButtonState); ButtonR:= GetButtonCloseRect(Index); if ButtonR.Bottom - ButtonR.Top > 0 then StyleServices.DrawElement(Canvas.Handle,Details,ButtonR); end; procedure TTabControlStyleHookBtnClose.WMLButtonUp(var Message: TWMMouse); Var LPoint : TPoint; LIndex : Integer; begin LPoint:=Message.Pos; for LIndex := 0 to TabCount-1 do if PtInRect(GetButtonCloseRect(LIndex),LPoint) then begin if Control is TPageControl then begin TPageControl(Control).Pages[LIndex].Parent:=nil; TPageControl(Control).Pages[LIndex].Free; end; break; end; end; procedure TTabControlStyleHookBtnClose.WMMouseMove(var Message: TMessage); Var LPoint : TPoint; LIndex : Integer; LHotIndex : Integer; begin inherited; LHotIndex:=-1; LPoint:=TWMMouseMove(Message).Pos; for LIndex := 0 to TabCount-1 do if PtInRect(GetButtonCloseRect(LIndex),LPoint) then begin LHotIndex:=LIndex; break; end; if (FHotIndex<>LHotIndex) then begin FHotIndex:=LHotIndex; Invalidate; end; end; function TTabControlStyleHookBtnClose.GetButtonCloseRect(Index: Integer): TRect; var FButtonState: TThemedWindow; Details : TThemedElementDetails; R,ButtonR : TRect; begin R := TabRect[Index]; if R.Left < 0 then Exit; if TabPosition in [tpTop,tpBottom] then begin if Index = TabIndex then InflateRect(R,2); end else if Index = TabIndex then Dec(R.Left,2) else Dec(R.Right,2); Result := R; FButtonState := twSmallCloseButtonnormal; Details := StyleServices.GetElementDetails(FButtonState); if not StyleServices.GetElementContentRect(0,Result,ButtonR) then ButtonR := Rect(0,0); Result.Left :=Result.Right - (ButtonR.Width) - 5; Result.Width:=ButtonR.Width; end; procedure TTabControlStyleHookBtnClose.MouseEnter; begin inherited; FHotIndex := -1; end; procedure TTabControlStyleHookBtnClose.MouseLeave; begin inherited; if FHotIndex >= 0 then begin FHotIndex := -1; Invalidate; end; end;
以这种方式注册
TStyleManager.Engine.RegisterStyleHook(TCustomTabControl,TTabControlStyleHookBtnClose); TStyleManager.Engine.RegisterStyleHook(TTabControl,TTabControlStyleHookBtnClose);
这是一个演示
今天关于Delphi中让窗口关闭按钮无效的6种方法和delphi中让窗口关闭按钮无效的6种方法是的讲解已经结束,谢谢您的阅读,如果想了解更多关于C# winform中窗口关闭按钮的隐藏与禁用详解、Delphi TTabControl 在 TabItem 添加关闭按钮、Delphi TTabControl在TabItem添加关闭按钮、delphi – 不支持vcl样式的标签页的关闭按钮的相关知识,请在本站搜索。
本文标签: