Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - declare a form so that you can reference it's controls

Reply
 
Old 07-04-2008   #1 (permalink)
Tanzen


 
 

declare a form so that you can reference it's controls

On Jul 4, 8:30*pm, breitak67 <gu...@xxxxxx-email.com> wrote:
Quote:

> 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!

My System SpecsSystem Spec
Old 07-04-2008   #2 (permalink)


Vista Business x64
 
 

Re: declare a form so that you can reference it's controls

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:

PublicClass Form1
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Utilities.SetControl(
Me, "ExampleText")
EndSub
End
Class

Public
Class Utilities
PublicSharedSub SetControl(ByRef MyForm As Form1, ByVal MyTextVal AsString)
MyForm.TextBox1.Text = MyTextVal
EndSub
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:

PublicClass Form1
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Utilities.SetControl(
Me.TextBox1, "ExampleText")
EndSub
End
Class

Public
Class Utilities
PublicSharedSub SetControl(ByRef MyTextBox As TextBox, ByVal MyTextVal AsString)
MyTextBox.Text = MyTextVal
EndSub
End
Class

My System SpecsSystem Spec
Old 07-24-2008   #3 (permalink)
Tanzen


 
 

Re: declare a form so that you can reference it's controls

On Jul 4, 8:30*pm, breitak67 <gu...@xxxxxx-email.com> wrote:
Quote:

> 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!
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Declare type for hashtables? PowerShell
Declare in vb script? VB Script
Winforms User Controls - How do I bind those to a dataset on the host form .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46