2014-01-19 39 views
0

我有一個基本形式與標籤& 2個按鈕,當我在孩子的形式繼承它,它只是變得標籤,但不是按鈕C#形式的繼承問題

我不知道爲什麼它繼承一個控制而不是其他,你呢?

什麼我試圖做這件事:

1-改變了基本表單控件修飾符來保護,那麼公衆,仍然只有標籤被繼承

2-裝箱一個新的空測試項目有從一個文本框和一個按鈕&子窗體繼承它,它工作正常,即這兩個控件出現在子窗體

3-回到我的項目,我刪除的形式(父&子)重建的基本形式帶有標籤和2個默認設置按鈕(無需定製l ike字體,文本或大小)然後創建子窗體繼承它,直到這裏它工作正常所有控件出現在子窗體上..一旦我定製父控件的構造函數上的按鈕消失從孩子只有標籤仍然

代碼示例:

通過VS2012

private System.Windows.Forms.Label editheader_lbl; 
private System.Windows.Forms.Button cancel_btn; 
private System.Windows.Forms.Button save_btn 
private void InitializeComponent() 
    { 
     this.editheader_lbl = new System.Windows.Forms.Label(); 
     this.cancel_btn = new System.Windows.Forms.Button(); 
     this.save_btn = new System.Windows.Forms.Button(); 
     this.SuspendLayout(); 
     // 
     // editheader_lbl 
     // 
     this.editheader_lbl.Anchor = System.Windows.Forms.AnchorStyles.Top; 
     this.editheader_lbl.AutoSize = true; 
     this.editheader_lbl.Location = new System.Drawing.Point(164, 11); 
     this.editheader_lbl.Name = "editheader_lbl"; 
     this.editheader_lbl.Size = new System.Drawing.Size(44, 13); 
     this.editheader_lbl.TabIndex = 7; 
     this.editheader_lbl.Text = "edit info"; 
     this.editheader_lbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
     // 
     // cancel_btn 
     // 
     this.cancel_btn.Location = new System.Drawing.Point(321, 278); 
     this.cancel_btn.Name = "cancel_btn"; 
     this.cancel_btn.Size = new System.Drawing.Size(75, 23); 
     this.cancel_btn.TabIndex = 9; 
     this.cancel_btn.Text = "cancel"; 
     this.cancel_btn.UseVisualStyleBackColor = true; 
     // 
     // save_btn 
     // 
     this.save_btn.Location = new System.Drawing.Point(143, 278); 
     this.save_btn.Name = "save_btn"; 
     this.save_btn.Size = new System.Drawing.Size(75, 23); 
     this.save_btn.TabIndex = 8; 
     this.save_btn.Text = "save"; 
     this.save_btn.UseVisualStyleBackColor = true; 
     // 
     // MainEdit 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(533, 331); 
     this.ControlBox = false; 
     this.Controls.Add(this.cancel_btn); 
     this.Controls.Add(this.save_btn); 
     this.Controls.Add(this.editheader_lbl); 
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 
     this.Name = "MainEdit"; 
     this.RightToLeft = System.Windows.Forms.RightToLeft.Yes; 
     this.RightToLeftLayout = true; 
     this.ShowIcon = false; 
     this.ShowInTaskbar = false; 
     this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 
     this.TopMost = true; 
     this.ResumeLayout(false); 
     this.PerformLayout(); 

    } 

MainEdit.cs產生MainEdit表單設計文件自動

public MainEdit() 
    { 
     InitializeComponent(); 
     this.Text = string.Empty; 
     this.editheader_lbl.Font = Program.font_l; 
     this.save_btn.Font = Program.font_btn; 
     this.save_btn.Size = Program.btnSize; 
     this.save_btn.Text = Constants.SAVE; 
     this.cancel_btn.Font = Program.font_btn; 
     this.cancel_btn.Size = Program.btnSize; 
     this.cancel_btn.Text = Constants.CANCEL; 
    } 

Edit_Employee.cs ..子窗體

public partial class Edit_Employee : MainEdit 
{ 
    public Edit_Employee() 
    { 
     InitializeComponent(); 
    } 
} 

更新

意外,當我移動按下鼠標按鍵,這讓子窗體上的選擇區域。有2個鎖定符號,按鈕應該是,我想這意味着按鈕在那裏,但我只是看不到它們! 我會去嘗試我收到的建議到現在,讓你更新,感謝大家誰迄今幫助

更新-2

試圖通過一個添加定製一個,看看是什麼導致這問題,這是尺寸線。儘管它在運行時需要正確的大小,但在設計時它就像在孩子中被設置爲0,0一樣!我在按鈕上得到大小相同的點,我在父級應用大小,而另一個按鈕正常顯示。

仍然沒有看到那裏的大小編輯造成麻煩,但我想這個問題是由@ Chiel92解決希望你發佈你的建議的答案,所以我可以再次接受它,並關閉該線程

感謝

+1

它是如何不繼承?你的意思是這些按鈕在子窗體上不可見? –

+0

@ Chiel92是的,標籤貼在兒童窗體上,但沒有按鈕。當我將默認私人更改爲受保護的時,我可以通過代碼訪問按鈕,但它們仍未顯示在表單上 – Katia

+0

您確定按鈕的位置在子窗體大小內嗎? –

回答

0

我認爲你的問題來自你的主窗體的自動生成部分,因爲拖放Visual Studio將生成主窗體的各個部分作爲私人嘗試定義應該在你的主類中繼承的所有控件而不是由設計師生成的部分內容如下

MainEdit。cs(不是由視覺工作室生成的部分視頻)

public partial class MainEdit 
{ 
protected System.Windows.Forms.Label editheader_lbl; 
protected System.Windows.Forms.Button cancel_btn; 
protected System.Windows.Forms.Button save_btn 
public MainEdit() 
    { 
     InitializeComponent(); 
     this.Text = string.Empty; 
     this.editheader_lbl.Font = Program.font_l; 
     this.save_btn.Font = Program.font_btn; 
     this.save_btn.Size = Program.btnSize; 
     this.save_btn.Text = Constants.SAVE; 
     this.cancel_btn.Font = Program.font_btn; 
     this.cancel_btn.Size = Program.btnSize; 
     this.cancel_btn.Text = Constants.CANCEL; 
    } 
} 
+0

我嘗試將修改器更改爲受保護的,我可以通過代碼訪問控件,但它們仍未在窗體上顯示。或者你的意思是我不應該使用自動生成的表單,只是寫我自己的? – Katia

+0

你的意思是我不應該使用自動生成的表單,只是寫我自己的?是的,我的意思是 –