Question

Is New Control needed to create a control or can one use only Control? For example:

Dim Label1 As Label VS Dim Label1 As Label= New Label

Was it helpful?

Solution

Question 1:

Here you made a reference;

 Dim Label1 As Label 

You can't use this one jet, this won't work;

 label1.text = "yadda"

You get an error like; object is not an instance of declaring class

Here you made a reference plus an instance;

 Dim Label1 As Label= New Label

You can now use the instance;

 label1.text = "yadde"

In .net a 'control' is not a variable, it's a class; http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx

Question 2:

If you put a control on a form, and then change it, it will also change on the form! You don't have to add them again to the form!

Question 3:

Controls.remove is a method of a Form, for example;

 Form1.controls.remove(label1)

You need to refer to form1 inside it own class as 'me' ;

 me.controls.remove(label1)

It only detaches the control from the form, but it is stil there.

If you want to 'remove' it you should,

    Me.Controls.Remove(Label1)
    Label1.Dispose()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top