我得到一個InvalidArgumentException同時播送控制到System.Windows.Forms.Textbox:鑄造新System.Windows.Forms.Control的對象System.Windows.Forms.Textbox
無法投類型的對象「 System.Windows.Forms.Control'來鍵入'System.Windows.Forms.TextBox'。
System.Windows.Forms.Control control = new System.Windows.Forms.Control();
control.Width = currentField.Width;
//here comes the error
((System.Windows.Forms.TextBox)control).Text = currentField.Name;
我這樣做,因爲我有不同的控件(文本框,MaskedTextBox中,dateTimePicker的...),這將動態地添加到面板,並具有相同的基本屬性(大小,位置.. 。 - > Control)
爲什麼不能投射?