ron nash

Hi,

I have created a class which will become a dll. I have coded a dynamic form and controls within this class.

The issue I have is obtaining the text from the textbox when the button is clicked. The yellow highlights the problem, error reference to a non-shared member requires an object reference. Because the textbox does not exsit untill run time, how do I overcome this problem please

'\\SET TEXTBOX

With textbox

.Name = "productkeytext"

.Location = New System.Drawing.Size(5, 40)

.Size = New System.Drawing.Size(360, 100)

End With

AddHandler button1.Click, AddressOf buttonclickedhandler

 

Private Sub buttonclickedhandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim btnsender As Button = CType(sender, Button)

If btnsender.Name = "button1" Then

Dim original As String = productkettext.Text         '\\ Have also used textbox.text



Re: Visual Basic Express Edition dynamic form and controls

AtomZ .be

Have you declared the textbox as like:

friend withevents txtbox as new textbox

And as I can see you have declared textbox as a textbox..
textbox.. textbox.. -> you shouldn't use
the name of a control as identifier

Grtz, Tom.






Re: Visual Basic Express Edition dynamic form and controls

ron nash

Hi,

Thanks for the reply,

I would normally prefix my objects with obj eg: "objtextbox = new textbox". Can you please explain the reason why, if you wanted, why you should not use the same names, or is it just good practice not too. Back to my original question,how can I
overcome the issue of the textbox.text

I am currently looking at coding an event handler for the objtextbox .textchanged event

Private Sub objtextbox_eventhandler(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles objtextbox.TextChanged

End Sub

Many thanks

Friend WithEvents objtextbox As TextBox

'\\SET TEXTBOX

With objtextbox

.Name = "productkeytext"

.Location = New System.Drawing.Size(5, 40)

.Size = New System.Drawing.Size(360, 100)

End With

AddHandler button1.Click, AddressOf buttonclickedhandler

 

Private Sub buttonclickedhandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim btnsender As Button = CType(sender, Button)

If btnsender.Name = "button1" Then

Dim original As String = productkeytext.text





Re: Visual Basic Express Edition dynamic form and controls

ron nash

Sorted

Thanks Atom z .be for pointing me in the right direction .... withevents

Private Sub objtextbox_eventhandler(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles objtextbox.TextChanged

productkeyIn = sender.text

End Sub