窗口的最小尺寸(50分)

  • 主题发起人 主题发起人 Zythum
  • 开始时间 开始时间
Z

Zythum

Unregistered / Unconfirmed
GUEST, unregistred user!
如何设定窗口的最小尺寸?<br>当用鼠标改变窗口的大小时,窗口尺寸不能小于最小尺寸。<br>(象Windows中的打开窗口)<br>
 
&nbsp;TForm1 = class(TForm)<br>&nbsp; private<br>&nbsp; &nbsp; procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;<br>&nbsp; end;<br>...<br>procedure TForm1.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);<br>begin<br>&nbsp; Msg.MinMaxInfo.ptMinTrackSize := Point(200, 300);<br>end;<br><br>
 
将窗体的Constraints属性的MinHeight, MinWidth的值设为你的要求.
 
嘿嘿,<br>1)如果不显示窗口,没尺寸。<br>2)如果窗口内有其它组件,应以他们的边界为准。<br>3)其它,上面网友已经论及
 
在TForm.Constraints.MinHeight 和MinWidth设置你想要的最小值就可以了。
 
to Zythum:<br><br>Croco已经说出了思路,这是我总结的(C++Builder程序,我注释得这么清楚,<br>你应该能看懂),已经很完善了.<br><br>Form1源文件: Unit1.cpp<br><br>//---------------------------------------------------------------------------<br>#include &lt;vcl.h&gt;<br>#pragma hdrstop<br><br>#include "Unit1.h"<br>//---------------------------------------------------------------------------<br>#pragma package(smart_init)<br>#pragma resource "*.dfm"<br>TForm1 *Form1;<br>//---------------------------------------------------------------------------<br>__fastcall TForm1::TForm1(TComponent* Owner)<br>&nbsp; &nbsp; &nbsp; &nbsp; : TForm(Owner)<br>{<br>}<br>//---------------------------------------------------------------------------<br><br>void __fastcall TForm1::FormResize(TObject *Sender)<br>{<br>&nbsp; Label1-&gt;Caption = "宽度 = " &nbsp; &nbsp;+ AnsiString(Width) &nbsp;+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp;高度 = " + AnsiString(Height);<br>}<br>//---------------------------------------------------------------------------<br>void __fastcall TForm1::WMGetMinMaxInfo(TWMGetMinMaxInfo &amp;Msg) &nbsp;//++<br>{<br>&nbsp; /*<br>&nbsp; &nbsp; &nbsp;一般是这样操作的:<br>&nbsp; &nbsp; &nbsp;将窗体的 Form1-&gt;Width , Form1-&gt;Height 设置为正常时的尺寸,一般来说<br>&nbsp; &nbsp; &nbsp;Form1-&gt;Width = ptMinTrackSize.x;<br>&nbsp; &nbsp; &nbsp;Form1-&gt;Height = ptMinTrackSize.y;<br>&nbsp; */<br>&nbsp; /*<br>&nbsp; &nbsp; 规则:<br>&nbsp; &nbsp; Form1-&gt;Width &nbsp;与 ptMaxSize.x , ptMaxTrackSize.x , ptMinTrackSize.x 是同步的<br>&nbsp; &nbsp; Form1-&gt;Height 与 ptMaxSize.y , ptMaxTrackSize.y , ptMinTrackSize.y 是同步的<br>&nbsp; &nbsp; ptMaxTrackSize.x &gt;= ptMinTrackSize.x<br>&nbsp; &nbsp; ptMaxTrackSize.y &gt;= ptMinTrackSize.y<br>&nbsp; &nbsp; ptMaxSize.x == ptMaxTrackSize.x<br>&nbsp; &nbsp; ptMaxSize.y == ptMaxTrackSize.y<br>&nbsp; &nbsp; 窗体刚生成时:<br>&nbsp; &nbsp; 若 Form1-&gt;Height &lt; ptMinTrackSize.y , 则以 ptMinTrackSize.y 为准<br>&nbsp; &nbsp; 若 Form1-&gt;Height &gt; ptMinTrackSize.y , 则以 Form1-&gt;Height 为准<br>&nbsp; &nbsp; 若 Form1-&gt;Width &gt; ptMinTrackSize.x , 则以 Form1-&gt;Width 为准<br>&nbsp; &nbsp; 若 Form1-&gt;Width &lt; ptMinTrackSize.x , 则以 ptMinTrackSize.x 为准<br>&nbsp; */<br><br>&nbsp; /*当窗体最大化时,窗体的宽度和高度*/<br>&nbsp; Msg.MinMaxInfo-&gt;ptMaxSize.x=500;<br>&nbsp; Msg.MinMaxInfo-&gt;ptMaxSize.y=130;<br><br>&nbsp; /*当窗体最大化时,窗体左上角的横,纵坐标*/<br>&nbsp; Msg.MinMaxInfo-&gt;ptMaxPosition.x=GetSystemMetrics(SM_CXSCREEN)-600;<br>&nbsp; Msg.MinMaxInfo-&gt;ptMaxPosition.y=0;<br><br>&nbsp; /*当用鼠标拖拽时,窗体允许的最大宽度和高度*/<br>&nbsp; Msg.MinMaxInfo-&gt;ptMaxTrackSize.x=500;<br>&nbsp; Msg.MinMaxInfo-&gt;ptMaxTrackSize.y=130;<br><br>&nbsp; /*当用鼠标拖拽时,窗体允许的最小宽度和高度*/<br>&nbsp; Msg.MinMaxInfo-&gt;ptMinTrackSize.x=275;<br>&nbsp; Msg.MinMaxInfo-&gt;ptMinTrackSize.y=120;<br>}<br><br>Form1头文件: Unit1.h<br><br>//---------------------------------------------------------------------------<br>#ifndef Unit1H<br>#define Unit1H<br>//---------------------------------------------------------------------------<br>#include &lt;Classes.hpp&gt;<br>#include &lt;Controls.hpp&gt;<br>#include &lt;StdCtrls.hpp&gt;<br>#include &lt;Forms.hpp&gt;<br>//---------------------------------------------------------------------------<br>class TForm1 : public TForm<br>{<br>__published: // IDE-managed Components<br>&nbsp; &nbsp; &nbsp; &nbsp; TLabel *Label1;<br>&nbsp; &nbsp; &nbsp; &nbsp; void __fastcall FormResize(TObject *Sender);<br>private: // User declarations<br>&nbsp; &nbsp; &nbsp; &nbsp; void __fastcall WMGetMinMaxInfo(TWMGetMinMaxInfo &amp;Msg); &nbsp;//++<br>public: // User declarations<br>&nbsp; &nbsp; &nbsp; &nbsp; __fastcall TForm1(TComponent* Owner);<br>BEGIN_MESSAGE_MAP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//++<br>&nbsp; MESSAGE_HANDLER(WM_GETMINMAXINFO,TWMGetMinMaxInfo,WMGetMinMaxInfo) //++<br>END_MESSAGE_MAP(TForm) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //++<br>};<br>//---------------------------------------------------------------------------<br>extern PACKAGE TForm1 *Form1;<br>//---------------------------------------------------------------------------<br>#endif<br>
 
就是 constraints
 
To FuDei:<br>&nbsp; &nbsp; 又学一招,设置constraints更方便。
 
除了设置constraints的MinHeight 和MinWidth值,有没有其他的方法呢???<br>我只是问问、、、
 
多人接受答案了。
 
后退
顶部