用户定义的标签页和主播

时间:2016-03-20 16:02:04

标签: c# winforms .net-4.5

我遇到了用户定义的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);

至于现在的&#34;目录&#34;部分构造函数未被使用。在我创建我的TabPage后,我得到这样的东西: enter image description here

点击全屏按钮后,它会显示我:

enter image description here

当我回到窗口模式时,控制器不会缩小,我就离开了:

enter image description here

有没有人知道我在代码中做错了什么?

1 个答案:

答案 0 :(得分:0)

我尝试过,因为我已经评论并成功完成了这些更改:

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;

这会得到您期望的结果。