2014-02-19 60 views
1

我有一些標籤打開並且每個標籤頁都處於監禁狀態。 我想通過點擊表格中的按鈕在當前標籤頁中打開另一個標籤頁,並且當前標籤的文本將會更改。 我用下面的代碼,這樣,如果按下按鈕,當前標籤頁變化的名稱:C#文本不會在tabcontrol的tabpage中更改

private void buttonNewForm_Click(object sender, EventArgs e) 
     { 
      newForm childForm = new newForm(tbc1); 
      //TopLevel for form is set to false 
      childForm.TopLevel = false; 
      //select current TabPage 
      int curr = tbc1.SelectedIndex; 
      TabPage tbp = tbc1.TabPages[curr]; 
      tbc1.TabPages[curr].Text = "name of new form"; 
      tbp.Controls.Add(childForm); 
      //Added form to tabpage 
      childForm.WindowState = FormWindowState.Maximized; 
      childForm.Show(); 
      Refresh(); 

     } 

它運作良好,直到我把代碼中的主要形式,將阻止我閃爍標籤的一段話:

protected override CreateParams CreateParams 
     { 
      get 
      { 
       CreateParams cp = base.CreateParams; 
       cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED 
       return cp; 
      } 
     } 

如何在不刪除防止閃爍的代碼的情況下再次工作?

+0

。你是否想在標籤頁中打開另一個表單,或者想要使用表格形式構建一個與google chrome瀏覽器類似的應用程序? – Shell

+0

這裏需要適當的歸屬。也是讓這個人關注你的帖子的好方法。 –

回答

0

最後我解決了這個問題。 相反刷新()我不得不使用tbc1.refresh()

TBC1是我使用的TabControl的名稱。

我沒有,以後我更換所有形式從主窗體usecontrols分開,我需要做一些改變上面的代碼:

private void buttonNewForm_Click(object sender, EventArgs e) 
     { 
      newForm childForm = new newForm(tbc1); 
      //select current TabPage 
      int curr = tbc1.SelectedIndex; 
      TabPage tbp = tbc1.TabPages[curr]; 
      tbc1.TabPages[curr].Text = "name of new form"; 
      tbp.Focus(); 
      tbp.Controls.Clear(); 
      tbp.Controls.Add(childForm); 
      tbc1.Refresh(); 

     } 
你想要什麼
0

爲了防止閃爍試試這個

SuspendLayout(); 
// Add control and make size changes 
childForm.Show(); 
Refresh(); 
ResumeLayout(); 

您應該考慮使用一個用戶控件,而不是一種形式,一個標籤頁面中嵌入。

相關問題