您好,登錄后才能下訂單哦!
最大化縮放
//界面初始化
private void frmTemp_Load(object sender, EventArgs e)
{
//全屏顯示
Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(this);
//設(shè)置水平伸縮比例
dbScaleX = ScreenArea.Width /Convert.ToDouble(this.Width);
//設(shè)置垂直伸縮比例
dbScaleY = ScreenArea.Height /Convert.ToDouble(this.Height);
this.Width = ScreenArea.Width;
this.Height = ScreenArea.Height;
//窗體的位置由 Location 屬性確定。
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(0, 0);
this.MaximizeBox = false;
this.MinimizeBox = false;
controlsDfsToResize(frmMain.Instance.Controls,dbScaleX,dbScaleY);
}
/// <summary>
/// 對(duì)form中的控件進(jìn)行深度優(yōu)先遍歷,
/// 隨著Form的大小調(diào)整子控件的大小及位置
/// </summary>
/// <param name="controls"></param>
private static void controlsDfsToResize(Control.ControlCollection controls, double dbScaleX,double dbScaleY)
{
foreach (Control ctrl in controls)
{
ctrl.Left = (int)(Convert.ToDouble(ctrl.Left) * dbScaleX);
ctrl.Top = (int)(Convert.ToDouble(ctrl.Top) * dbScaleY);
ctrl.Width = (int)(Convert.ToDouble(ctrl.Width) * dbScaleX);
ctrl.Height = (int)(Convert.ToDouble(ctrl.Height) * dbScaleY);
//如果控件是Datagridview,則縮放列的行寬
if (ctrl.GetType().Equals(typeof(DataGridView)))
{
DataGridView dgv = (DataGridView)ctrl;
foreach (DataGridViewColumn col in dgv.Columns)
{
col.Width = Convert.ToInt32(col.Width * dbScaleX);
}
}
if (ctrl.Controls.Count > 0)
{
controlsDfsToResize(ctrl.Controls, dbScaleX, dbScaleY);
}
}
}
2.不可移動(dòng)
/// <summary>
/// 欺騙窗體,讓窗體認(rèn)為點(diǎn)擊的為非窗體區(qū)域,從而實(shí)現(xiàn)不可移動(dòng)(有BUG,所以需要下面的函數(shù))
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
if(m.Msg == 0x00A1 && m.WParam.ToInt32() == 2)
{
m.Msg = 0x0201;
m.LParam = IntPtr.Zero;
}
base.WndProc(ref m);
}
/// <summary>
/// 不讓窗體移動(dòng)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmMain_Move(object sender, EventArgs e)
{
this.Location = new Point(0,0);
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。