|
From: Tanzen on 4 Jul 2008 15:44 Here's what I'm trying to do in vb.net 2005. I have a public declared method that sets the value of a control on a form, but that form could change, so I don't want to code its actual name. I want it to be a parameter in the module method so that you pass the form name of whatever form called the method. So let's say we call the method from form 1: UpdateText(frmName) Then in the module we have the actual method Public Sub UpdateText(ByVal frmName as Form) frmName.textbox1.text = "Hi, I'm Me." end Sub Now, the problem that arises is that frmName gets underlined by visual studio and says: TextBox1 is not a member of 'System.Window.Forms.Form'. So apparently my parameter in the method is wrong. But I can't find out what type the form should be. Can anyone help me? Thanks
From: breitak67 on 4 Jul 2008 22:30 TextBox1 is not a member of System.Windows.Forms.Form - it is a member of the Form1 class, which is a subclass of System.Windows.Forms.Form. Try this: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Utilities.SetControl(Me, \"ExampleText\") End Sub End Class Public Class Utilities Public Shared Sub SetControl(ByRef MyForm As Form1, ByVal MyTextVal As String) MyForm.TextBox1.Text = MyTextVal End Sub End Class If you need the flexibility to set the text of forms that are of class Form1, then pass a reference to the control instead of the form, like this: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Utilities.SetControl(Me.TextBox1, \\"ExampleText\\") End Sub End Class Public Class Utilities Public Shared Sub SetControl(ByRef MyTextBox As TextBox, ByVal MyTextVal As String) MyTextBox.Text = MyTextVal End Sub End Class -- breitak67
From: Tanzen on 24 Jul 2008 00:13 On Jul 4, 8:30 pm, breitak67 <gu...(a)unknown-email.com> wrote: > TextBox1 is not a member of System.Windows.Forms.Form - it is a member > of the Form1 class, which is a subclass of System.Windows.Forms.Form. > Try this: > > Public Class Form1 > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e > As System.EventArgs) Handles Button1.Click > Utilities.SetControl(Me, \"ExampleText\") > End Sub > End Class > > Public Class Utilities > Public Shared Sub SetControl(ByRef MyForm As Form1, ByVal > MyTextVal As String) > MyForm.TextBox1.Text = MyTextVal > End Sub > End Class > > If you need the flexibility to set the text of forms that are of class > Form1, then pass a reference to the control instead of the form, like > this: > > Public Class Form1 > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e > As System.EventArgs) Handles Button1.Click > Utilities.SetControl(Me.TextBox1, \\"ExampleText\\") > End Sub > End Class > > Public Class Utilities > Public Shared Sub SetControl(ByRef MyTextBox As TextBox, ByVal > MyTextVal As String) > MyTextBox.Text = MyTextVal > End Sub > End Class > > -- > breitak67 Thank you very much for the help. Most appreciated!
|
Pages: 1 Prev: Folder Icons in Vista Next: GPS intermediate driver getting NMEA strings. |