开发者

c# - difference between Button and System.Windows.Forms.Button?

开发者 https://www.devze.com 2023-04-11 13:11 出处:网络
In my form1 class I have a number of buttons added using the designer. ie button1, button2.etc In my controller class I\'ve created an array of buttons like:

In my form1 class I have a number of buttons added using the designer. ie button1, button2.etc

In my controller class I've created an array of buttons like:

Btns[k,m] = new Button();

then go:

Btns[1,1].Name = "button1";
Btns[1,1].Visi开发者_Python百科ble = False;

But this does not actually change the visibility of the button on my form class. Does anyone know why?

Basically create an array of button names in the controller that actually link to the form buttons in my form1 class.


There is no difference between Button and System.Windows.Forms.Button assuming you are using System.Windows.Forms and there is no ambiguity.

Don't overwrite Btns[k, m] with a new button. That is, remove this line:

Btns[k, m] = new Button();

If Btns is not set from the designer and would have its elements be null, set them to the buttons created from the designer:

Btns[1, 1] = button1;


The Button class in .Net framework comes under the System.Windows.Forms package. By default this is already referenced in Windows Form Applications. In C# you will see

using System.Windows.Forms;

at the top of the code behind of any form. If it is VB.Net you may not see

Imports System.Windows.Forms

as in C# but if you go to the references in solution explorer you will see that the reference is already there.

Since you have the references already there is no difference of just typing Button or System.Windows.Forms.Button. If you use the System.Windows.Forms we can say that it's like the full qualified path.

For example think of one particular class room, (Let's say Grade 11 class A) in a school and take one student who's name is David and imagine you also in the same class room. So if you want to refer him you will simply call his name David.Now think you are in a different class and you want to refer him. So in this case just calling David won't enough to identify him. You have to say something like this."David from Grade 11 Class A". Now again think if you both in the same class and when you want to refer him and it's look bit dumb if you call him "David from Grade 11 Class A" instead of just using David.

So if you are in the same class(=> you have the using System.Windows.Forms already defined) and want to refer David(=> Button) just saying Button is enough else you can use System.Windows.Forms.Button.

Hope you'll get some idea.

Thanks


I believe the main difference would be one required to process a form and the other could be used as initiator / hyperlink mask

0

精彩评论

暂无评论...
验证码 换一张
取 消