简体   繁体   中英

User defined tabpage and anchors

I'm having a problem with a user defined TabPage and anchors. In my solution i want to used a template for a tabpage and add it multiple times based on users choice.

This is my template:

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
}

And i create my tabpages with this:

        ATMTemplate atm = new ATMTemplate("", tc_ATMs);

As for now the "directory" part of the constructor isn't used. After i create my TabPage i get something like this: 在此处输入图片说明

After I click the fullscreen button it shows me this:

在此处输入图片说明

And when I come back to the windowed mode the controls don't shrink and I'm left with this:

在此处输入图片说明

Does anybody have a clue what I did wrong in the code ?

I tried as I already commented and succeded with these changes:

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;

This gives the result you expect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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