首页 新闻 搜索 专区 学院

自定义控件的一个问题 ?WINFORM。

0
悬赏园豆:20 [已解决问题] 解决于 2008-09-05 23:38
&nbsp;public ComboxSex() <BR>&nbsp; &nbsp; &nbsp; &nbsp; { <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.FormattingEnabled = true; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.Items.AddRange(new object[] { "男", "女" }); <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //label = new System.Windows.Forms.Label(); <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //label.Text = "性别"; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //this.Controls.Add (label); <BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.TextChanged += new EventHandler(ComboxSex_TextChanged); <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (Exception ex) <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw ex; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } <BR>&nbsp; &nbsp; &nbsp; &nbsp; } <BR><BR><BR>当在窗体 画此控件的时候。 <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.comboxSex1 = new WindowsControlLibrary2.ComboxSex(); <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.SuspendLayout(); <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // comboxSex1 <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <SPAN style="COLOR: #ff0000">this.comboxSex1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.comboxSex1.FormattingEnabled = true; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.comboxSex1.Items.AddRange(new object[] { <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "男", <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "女"});</SPAN> <BR>new 的时候执行了一次。 <BR>为什么会出红色的代码。如何取消。
秋色的主页 秋色 | 初学一级 | 园豆:47
提问于:2008-08-04 17:42
< >
分享
最佳答案
0
把那些代码放到Loaded事件里,别放到构造函数里.
deerchao | 大侠五级 |园豆:8167 | 2008-08-05 00:06
其他回答(1)
0
你可以给Items属性上添加: [DesignerSerializationVisibility(DesignerSerializationVisibility.Never)] 禁止Items属性生成代码。
Colin Han | 园豆:3041 (老鸟四级) | 2008-08-05 13:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册