我有一類,其中我從Control鑄造System.Windows.Forms.Label到一個自定義類型
導出[Serializable]
public class CommonControl : System.Windows.Forms.Control,IXmlSerializable
{
基本上這類增加了一些更多的屬性到默認控件類。 我的問題是我不能將Control對象轉換到我的自定義控件對象中。由於自定義控件類派生自控件,我認爲它可能工作。
我正在做這樣的鑄造。
CommonControl ctrlTemp = new CommonControl();
ctrlTemp = (CommonControl)((Control)ctrl);
這裏CTRL是一個標籤對象。當我調試第一個鑄造工作正常。 (Control)ctrl
部分。但是當(CommonControl)((Control)ctrl)
被調試時,它會顯示以下消息。
(CommonControl)(CTRL)無法投 'CTRL'(其具有實際類型 'System.Windows.Forms.Label')至 'SharpFormEditorDemo.CommonControl' SharpFormEditorDemo.CommonControl
Thnx很多。我應該考慮班級的層次結構。 – JCTLK 2010-12-13 06:10:40