我在已經有 2 個現有按鈕的表單中添加一個新按鈕。當btnCancel
' 的內容更改為更長的字串時會出現問題,這會使按鈕自動調整大小 - 因此,與我添加的按鈕重疊。
這Proxy Settings
是我添加的按鈕。如果我換成Don't sign in
更長的字串,那么中間的按鈕會與我的重疊。
按鈕的代碼如下:
//
// btnLogin
//
this.btnLogin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnLogin.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.btnLogin.Location = new System.Drawing.Point(340, 50);
this.btnLogin.Margin = new System.Windows.Forms.Padding(2);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(82, 24);
this.btnLogin.TabIndex = 0;
this.btnLogin.Text = "Sign in...";
this.btnLogin.UseVisualStyleBackColor = true;
this.btnLogin.Click = new System.EventHandler(this.btnLogin_Click);
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(239, 50);
this.btnCancel.Margin = new System.Windows.Forms.Padding(2);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(94, 24);
this.btnCancel.TabIndex = 1;
this.btnCancel.Text = "Don\'t sign in";
this.btnCancel.UseVisualStyleBackColor = true;
//
// btnProxySettings
//
this.btnProxySettings.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnProxySettings.Location = new System.Drawing.Point(138, 50);
this.btnProxySettings.Margin = new System.Windows.Forms.Padding(2);
this.btnProxySettings.Name = "btnProxySettings";
this.btnProxySettings.Size = new System.Drawing.Size(92, 24);
this.btnProxySettings.TabIndex = 2;
this.btnProxySettings.Text = "Proxy Settings";
this.btnProxySettings.UseVisualStyleBackColor = true;
this.btnProxySettings.Click = new System.EventHandler(this.btnProxySettings_Click);
如何動態地使后一個按鈕距離本身?
編輯,因為我注意到我的帖子被否決了。我已經使用位置、大小、寬度等資料嘗試了幾次“計算” btnCancel
,但我無法找出一個可以這么說的“規則”。或者也許甚至有一種我找不到的方法可以“神奇地”完成所有事情?所以我不是要求你做我的功課什么的,但我發現在目前的情況下展示我的糟糕嘗試是沒有用的。
uj5u.com熱心網友回復:
將按鈕放在具有 RightToLeft FlowDirection的flowLayoutPanel中。這應該保證適當的分離,而無需手動計算任何位置。每當您使用自動縮放控制元件時,使用某種具有自動布局的面板通常是個好主意。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/498206.html
上一篇:除非選中框,否則禁用“提交”按鈕
下一篇:帶有apache的API平臺