Controlling a form from within another class

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
 
O

One Handed Man \( OHM - Terry Burns \)

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))
 
J

John Dann

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
 
K

Ken Tucker [MVP]

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
 
O

One Handed Man \( OHM - Terry Burns \)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top