完全自定义窗体风格的实现
最小化到任务栏
postmessage(Self.Handle,WM_SYSCOMMAND,SC_MINIMIZE,0);
最大化或还原
procedure Tf_MainForm.RzToolButton1Click(Sender: TObject);
var
abd: TAppBarData;
begin
inherited;
if WindowState=wsnormal then begin
WindowState := wsMaximized; // BorderStyleÎ为 bsNone
abd.cbSize := sizeof(abd);
SHAppBarMessage(ABM_GETTASKBARPOS, abd); //读取任务栏的区域
Self.Height := Self.Height - (abd.rc.Bottom - abd.rc.Top); //预留出任务栏的位置
(Sender as TRzToolButton).Hint :=‘还原‘;
(Sender as TRzToolButton).ImageIndex :=8;
end else if WindowState =wsmaximized then begin
WindowState :=wsNormal;
(Sender as TRzToolButton).Hint :=‘最大化‘;
(Sender as TRzToolButton).ImageIndex :=2;
end;
end;
移动无标题的窗体
procedure Tf_MainForm.RzPanel2MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
if Button=Mbleft then
begin
ReleaseCapture;
Perform(WM_NCLBUTTONDOWN,HTCAPTION,0);
end;
end;
无边框的窗体托动鼠标也能改变窗体的大小
protected
Procedure CreateParams(var Params: TCreateParams); override;
procedure Tf_MainForm.CreateParams(var Params: TCreateParams);
begin
BorderStyle := bsNone; // Îޱ߿ò´°ÌåÒ²Äܸı䴰ÌåµÄ´óС
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_STATICEDGE;
Params.Style := Params.Style or WS_SIZEBOX;
end;
鼠标点击BUTTON弹出菜单
procedure Tf_MainForm.CreateParams(var Params: TCreateParams);
begin
BorderStyle := bsNone;
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_STATICEDGE;
Params.Style := Params.Style or WS_SIZEBOX;
end;
窗体圆角处理
procedure Tf_MainForm.FormResize(Sender: TObject);
var hr:THandle;
begin
inherited;
hr:=createroundrectrgn(0,0,width,height,20,20);
setwindowrgn(handle,hr,true);
end;
窗体嵌入TABSHEET的一些方法
procedure Tf_MainForm.RzPageControl1Close(Sender: TObject;
var AllowClose: Boolean);
var
p: TRzPageControl;
t: TRzTabSheet;
begin
inherited;
p := sender as TRzPageControl;
t :=p.ActivePage;
if t.Caption <>‘ϵͳµ¼º½‘ then begin
AllowClose := True;
TForm(t.Controls[0]).Close;
t.Free;
end else AllowClose :=False;
end;
function Tf_MainForm.CreateTab(const aCaption: string): TRzTabSheet;
begin
Result := TrzTabSheet.Create(RzPageControl1);
Result.PageControl := RzPageControl1;
Result.Caption := Acaption;
RzPageControl1.ActivePage := Result;
end;
function Tf_MainForm.ExistTab(const aCaption: string): boolean;
var
i: Integer;
begin
result := false;
for i := 0 to RzPageControl1.PageCount - 1 do
begin
if RzPageControl1.Pages[i].Caption = Acaption then
begin
result := true;
RzPageControl1.activepage := RzPageControl1.pages[i];
Break;
end;
end;
end;
procedure Tf_MainForm.openForm(aFormClass: TFormClass;
aOwner: TWinControl);
var i: Integer;
f: TForm;
begin
f := aFormClass.Create(aOwner);
f.Color :=c_color;
for i:=0 to f.ComponentCount-1 do begin
if f.Components[i] is TRzDBGrid then begin
TRzDBGrid(f.Components[i]).FixedColor := c_color;
end else if f.Components[i] is TRzDBNavigator then begin
TRzDBNavigator(f.Components[i]).Color :=c_color;
end;
end;
f.ManualDock(aOwner);
f.WindowState := wsMaximized;
f.Align := alClient;
f.Show;
end;
http://www.cnblogs.com/hnxxcxg/archive/2012/05/10/2493680.html