Controlling a form from within another class

  • Thread starter Thread starter John Dann
  • Start date Start date
J

John Dann

I seem to be transitioning from VB6 to VB.Net very unevenly - got some
fancier things working OK but then trip over something that ought to
be simple in .Net:

It's the change in WinForm instantiation that I've clearly got a block
understanding. What I want to do is something very straightforward:

I have one main form (Form1) that is allowed to instantiate itself as
per the default mechanism. I'm then writing classes for some heavy
processing that will be instantiated in Form 1. What I need to do is
very simply to change Form1.text programmatically to reflect the state
of processing inside of the child classes, but can't get a reference
to Form1

I thought that something like

Public Class Processor

Dim F1 as New Form1

... etc

End Class

might do the trick, but just gives a StackOverflow exception on
compilation. I know this is something pretty basic but anyone able to
point out the errors of my ways please?

JGD
 
Me.Text="My State"


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
Me.Text="My State"

'Text is not a member of Processor'

(using Processor as the name of my example class. In other words Me
refers to the immediate containing class (ie Processor) and not to its
ultimate containing form.)

JGD
 
Hi,

Need to see more code to figure out whyyou are getting stack
overflow. Try this to get a reference to the form.

Public Class Processor

Dim F1 as Form1

Public Sub New(frm as Form1)

f1=frm

end sub


End Class


Ken
----------------------

I seem to be transitioning from VB6 to VB.Net very unevenly - got some
fancier things working OK but then trip over something that ought to
be simple in .Net:

It's the change in WinForm instantiation that I've clearly got a block
understanding. What I want to do is something very straightforward:

I have one main form (Form1) that is allowed to instantiate itself as
per the default mechanism. I'm then writing classes for some heavy
processing that will be instantiated in Form 1. What I need to do is
very simply to change Form1.text programmatically to reflect the state
of processing inside of the child classes, but can't get a reference
to Form1

I thought that something like

Public Class Processor

Dim F1 as New Form1

.... etc

End Class

might do the trick, but just gives a StackOverflow exception on
compilation. I know this is something pretty basic but anyone able to
point out the errors of my ways please?

JGD
 
Sorry, I mi-read ur post. Kens example will work

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
Back
Top