[英]User defined tabpage and anchors
用戶定義的TabPage和錨點出現問題。 在我的解決方案中,我想使用一個標簽頁模板,並根據用戶的選擇多次添加它。
這是我的模板:
public class ATMTemplate : TabPage
{
#region Fields
#endregion
#region Properties
public List<LogFile> LogFiles { get; set; }
public GroupBox GroupFiles { get; set; }
public DataGridView DGV_LogFiles { get; set; }
#endregion
#region Constructors
public ATMTemplate(string directory, TabControl parent)
{
this.Text = "ATM TEST 2";
this.Parent = parent;
this.LogFiles = new List<LogFile>();
this.GroupFiles = new GroupBox();
this.DGV_LogFiles = new DataGridView();
this.Controls.Add(this.GroupFiles);
this.GroupFiles.Location = new Point(6, 6);
this.GroupFiles.Text = "Log files:";
this.GroupFiles.AutoSize = true;
this.GroupFiles.Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top);
this.GroupFiles.Controls.Add(this.DGV_LogFiles);
this.DGV_LogFiles.Location = new Point(9, 18);
this.DGV_LogFiles.AutoSize = true;
this.DGV_LogFiles.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top);
this.Invalidate();
}
#endregion
#region Methods
#endregion
}
我用這個創建我的標簽頁:
ATMTemplate atm = new ATMTemplate("", tc_ATMs);
到目前為止,不使用構造函數的“目錄”部分。 創建我的TabPage后,我得到如下信息:
單擊全屏按鈕后,它顯示以下內容:
當我回到窗口模式時,控件不會縮小,剩下的是:
有人知道我在代碼中做錯了什么嗎?
我已經評論並成功完成以下更改,因此嘗試了以下操作:
this.GroupFiles.Location = new Point(6, 6);
this.GroupFiles.Size = this.Size - new Size(12, 12); // set initial size
this.GroupFiles.AutoSize = false; // and autosize to false
this.GroupFiles.Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top);
// ...
// same thing for the grid view
this.DGV_LogFiles.Location = new Point(9, 18);
this.DGV_LogFiles.Size = this.GroupFiles.Size - new Size(18, 36);
this.DGV_LogFiles.AutoSize = false;
這給出了您期望的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.