1 Replies - 3161 Views - Last Post: 14 March 2009 - 03:59 PM Rate Topic: -----

#1 lowrent2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-February 09

Control as Variable.

Posted 14 March 2009 - 10:38 AM

Hello most excellant ones. In vb.net 2005 how would one referance a a control as variable and change it"s properties. Such as in control X visible = True. Tryed string manipulations that did't work. Hope someone can give me a quick answer. Thsnks., Marty
Is This A Good Question/Topic? 0
  • +

Replies To: Control as Variable.

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4361
  • View blog
  • Posts: 12,179
  • Joined: 18-April 07

Re: Control as Variable.

Posted 14 March 2009 - 03:59 PM

Well first for all controls on your forms they have their names so you can call them directly. For those controls you create dynamically, you will set them up as variables and control them through the variable.

So for instance if I have a form and one button on the form called "Button1" as its name I can control it directly by saying Button1.Text = "Hello".

Now lets say I want to add a but dynamically to the form. I will first create the button as a variable, then manipulate that variable. Then lastly add it to the form.

' Create a button and set it up as a variable called buttonTest
Dim buttonTest As New Button

' Lets give this button the text "Hello2"
buttonTest.Text = "Hello2"

' Lastly, add it to the form using "Me" which refers to itself. 
' We add the button to the forms list of controls. Pass it to the add method.
Me.Controls.Add(buttonTest)



This will add the button to the form. Try putting these lines of code in a button click event and run your project. When you click the button it will then add this second button to the form in the upper left corner. You can control the position by manipulating buttonTest's "left" and "top" properties.

Hope this is what you were wanting to do. Keep in mind that we also have a VB.NET forum and this forum is reserved for VB6 only questions. I have moved the post to the appropriate forum.

Thanks and enjoy!

"At DIC we be dynamic button creating code ninjas.. we dynamically created the seahorse also. Poseidon gets all the credit, but we were the ones behind his code." :snap:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1