Tag: winforms构建

将新的System.Windows.Forms.Control对象转换为System.Windows.Forms.Textbox

我将Control转换为System.Windows.Forms.Textbox时出现InvalidArgumentException: 无法将类型为“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; 我这样做,因为我有不同的控件(Textbox,MaskedTextbox,Datetimepicker …),它将动态添加到面板并具有相同的基本属性(大小,位置… – >控制) 为什么演员不可能?