控件出了什么问题 [英] What's wrong with the control

查看:73
本文介绍了控件出了什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在学习如何用c#编写控件,我从MSDN复制了一个演示(解决方案

没有错:放置控件的窗体正在设置您看到的文本:

  firstControl1 
//  
 .firstControl1.BackColor = System.Drawing.SystemColors.ControlDark;
 .firstControl1.Location =  System.Drawing.Point( 96  104 );
 .firstControl1.Name = " ;
 .firstControl1.Size =  System.Drawing.Size( 75  16 );
 .firstControl1.TabIndex =  0 ;
  .firstControl1.Text = " ; 
 .firstControl1.TextAlignment =
System.Drawing.ContentAlignment.MiddleCenter;

在您的项目中打开Designer.cs文件,然后进行检查.

注意:链接到的示例代码是针对VS 2005的,尽管有用户回溯到2008年的消息(请在MSDN页面的底部向下查看),但该代码是不完整的,但仍省略了Form设计器代码. ,并且错误地重复了Control定义代码.

如果您看到该示例的VS 2010版本> [
^ ],您将看到表单代码.


Hi all, I''m learning how to write a control by c#, and I copy a demo from MSDN(http://msdn.microsoft.com/en-us/library/649xahhe%28VS.80%29.aspx[^]), but when I try to use it, I found something strange.

I drag the control to a form and set the control''s dock is fill, then when I double click the form to make it largest, there is tow "Hello World" string in the control, what''s wrong?

解决方案

There''s nothing wrong: the Form in which the Control is placed is setting the text you see:

// firstControl1
//
this.firstControl1.BackColor = System.Drawing.SystemColors.ControlDark;
this.firstControl1.Location = new System.Drawing.Point(96, 104);
this.firstControl1.Name = "firstControl1";
this.firstControl1.Size = new System.Drawing.Size(75, 16);
this.firstControl1.TabIndex = 0;
this.firstControl1.Text = "Hello World";
this.firstControl1.TextAlignment =
System.Drawing.ContentAlignment.MiddleCenter;

Open the Designer.cs file in your project, and examine it.

Note: the example code you linked to is for VS 2005, and, in spite of messages from users going back to 2008 (look down at the bottom of the MSDN page), that the code is incomplete, it still omits the Form designer code, and, mistakenly, repeats the Control definition code.

If you see the VS 2010 version of that example>[^], you will see the Form code.


这篇关于控件出了什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆