• 完全自定义窗体风格的实现


    完全自定义窗体风格的实现

     

    最小化到任务栏
    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 RzPageCotrol1.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;

  • 相关阅读:
    机器学习-分类简单介绍
    状态压缩动态规划 -- 旅行商问题
    30 天学习 30 种新技术系列
    Sublime Text3 高亮显示Jade语法 (Windows 环境)
    程序启动缓慢-原来是hbm.xml doctype的原因
    Spring4 Hibernate4 Struts2在WebLogic 10.3.3上面部署
    Spring的 classpath 通配符加载配置文件
    nmp install 异常
    cvc-complex-type.2.4.c: The matching wildcard...
    LazyInitializationException--由于session关闭引发的异常
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/7741829.html
Copyright © 2020-2023  润新知