Wednesday 15 June 2011

c# - .NET controls and scope -


How to work around the boundaries of a programmer when writing an event handling function related to controls not announced through GOI Can, but main source file?

Is it "acceptable" to declare such controls in the global realm rather than form 1_load () to solve this problem?

  Private Zero form1_load (object sender, event events e) {combo box t = new combo box (); Button b = new button (); B.Onclic + = B_OnClick; } Private Zero b_OnClick (Object Sender, OnClickEventArgs E) {S. Ed ​​("Hello S!"); // Objects is a combo box control that designer GUI t. Aad ("Hello T!") Is generated in; } // line 10 is valid. // Line 11 has been invented because T is not present in the current scope. How can anybody work about this issue?    

I think this is acceptable, if you see the form.designer file It will see that all controls created using the designer are at the world level. So I think you can do this in your code too.

However, I think there are situations in which you do not need these controls, otherwise the argument decides that you make them directly with the designer and avoid that code.

Of course, there is a lack of some essential information in your code such as the position, size, name and the most important form of all. Form.Controls.Add (control) statement, but I do not know that this is due to the simplification of your question.

No comments:

Post a Comment