用户定义的标签页和锚点
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;
这给出了您期望的结果。
我在使用用户定义的 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;
这给出了您期望的结果。