繁体   English   中英

用户定义的标签页和锚点

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM