2016-03-20 5 views
0

タブページとアンカーを定義したユーザーに問題があります。私のソリューションでは、私はタブページのテンプレートを使用し、それをユーザーの選択に基づいて複数回追加したいと思う。ユーザー定義のタブページとアンカー

これが私のテンプレートです:

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 
} 

、私はこれで私のtabpagesを作成:コンストラクタの「ディレクトリ」の部分が使用されていない今のとおり

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

。 「

enter image description here

そして、私はウィンドウモードに戻ってきたときにコントロールがドン:私はこのような何かを得る私は私のTabPageを作成した後:私はフルスクリーンボタンをクリックした後 enter image description here

は、それは私にこのことを示していtは縮小し、私はこれを残しています:

enter image description here

誰もが、私はコード内で間違って何をしたかの手掛かりを持っていますか?

+1

私は 'AutoSize'と' Anchor'を混在させることが問題になると思います。 'AutoSize = false'を設定して、' TabPage'の現在の 'Size'にしたがって初期の' Size'と 'Location'を設定し、' Anchors'を設定しようとします。別の可能性(図示の場合)は、「Dock = DockStyle.Top」または「DockStyle.Fill」を使用することができる。 –

+0

私はDockを使用することができます。DataGridViewには記入してくださいが、GroupBoxには記入しないでください。 GroupBox.AutoSizeをfalseに設定しても何も変更されていません。グループボックスの最初の幅を設定するだけで助けになりました。 –

答えて

0

私はすでにコメントしてみましたし、これらの変更でsucceded:

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; 

これは、あなたが期待する結果が得られます。

関連する問題