accesing Form1:controls from other class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I need to control the text of a label on a form, from a VB class
I'm using VB .NET and can't figure out how to accomplish this
I saw a similar question/answer using C#, but I can't translate it to VB .NET
Can someone show a simple example of using a public property in the form, that sets/gets the label text, and how to call the property from a VB class to update the labels text

Thanks
Gre
 
* "=?Utf-8?B?R3JlZw==?= said:
I need to control the text of a label on a form, from a VB class.
I'm using VB .NET and can't figure out how to accomplish this.
I saw a similar question/answer using C#, but I can't translate it to VB .NET.
Can someone show a simple example of using a public property in the form, that sets/gets the label text, and how to call the property from a VB class to update the labels text?

You will have to pass a reference to the form to the class/method which
updates the form, for example, in a property or in a parameter of the
method.

Some basics:

<URL:http://dotnet.mvps.org/dotnet/faqs/downloads/accessmainform.txt>
 
Thanks for the reply
I actually have a AddHandler that calls a class sub procedure when a mouse down event is fired
So I'd like the class sub() to update the labels text, since it's called on the mouse down event.
Shouldn't the "myMouseEventClass", seen below, be able to update the label on form1?
It seems that .NET should have this functionality?

Here's some of the code:

This is part of the form1 #Region section
#Region " Windows Form Designer generated code

Public Sub New(
MyBase.New(

'This call is required by the Windows Form Designer
InitializeComponent(

'Add any initialization after the InitializeComponent() cal
'--- Gregs addition to track right click of label2
AddHandler Label1.MouseDown, AddressOf myEvents.myMouseDow
End Su

This is in the Form1 declarations section
Public myEvents As New myMouseEventClass(

This is my class:
Public Class myMouseEventClas
Inherits System.Windows.Forms.Labe

'--- Function signatures must match the signature of the MouseEventHandler class.
Public Sub myMouseDown(ByVal sender As Object, ByVal ex As MouseEventArgs

If ex.Button = MouseButtons.Right The
'Executes when a mouse down event is received, and the right button is clicked.
Dim Reply As Int32 = MsgBox("Search by Server name?", MsgBoxStyle.YesNoCancel, "?"
Select Case Repl
Case 6 'Ye
label1.Text = "Server Name:"
Case 7 'N
'labelx.Text = "Path Name:"
Case Els
End Selec
End I
End Sub 'myMouseDown

End Class 'myMouseEventClass

Thanks

Gre
 
Back
Top