|
-
Apr 1st, 2013, 11:46 AM
#1
Thread Starter
Junior Member
Re: Communicating across threads from module to gui text box
frmMain is what is loaded on startup. Is there a method of setting a variable within the module to the existing instance of frmMain?
I tried declaring a variable in the module as Windows.Forms.Form , then when frmMain loads, i set that variable = ME
will that then allow me to reference the particular instance of the form?
CODE IN MODULE
=================
Code:
Public frmMainInst As Windows.Forms.Form 'DECLARED WITHIN MODULE, BEFORE SUBS
CODE IN frmMain
=================
Code:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmMainInst = Me
End Sub
-
Apr 1st, 2013, 12:01 PM
#2
Re: Communicating across threads from module to gui text box
 Originally Posted by dontstealmyfish
frmMain is what is loaded on startup. Is there a method of setting a variable within the module to the existing instance of frmMain?
I tried declaring a variable in the module as Windows.Forms.Form , then when frmMain loads, i set that variable = ME
will that then allow me to reference the particular instance of the form?
CODE IN MODULE
=================
Code:
Public frmMainInst As Windows.Forms.Form 'DECLARED WITHIN MODULE, BEFORE SUBS
CODE IN frmMain
=================
Code:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmMainInst = Me
End Sub
You've got the code already. Why ask us whether it will work when you could just try it for yourself? If it works then you don't need to ask the question. If it doesn't work then the question is not "will it work" but rather "why didn't it work".
-
Apr 1st, 2013, 12:14 PM
#3
Thread Starter
Junior Member
Re: Communicating across threads from module to gui text box
 Originally Posted by jmcilhinney
You've got the code already. Why ask us whether it will work when you could just try it for yourself? If it works then you don't need to ask the question. If it doesn't work then the question is not "will it work" but rather "why didn't it work".
Ah, you are right. Sorry, I guess I was just nervous and posted before testing. It looks like it won't work when i reference the instance of the form itself, but will if i reference the instance of the textbox.
When I tried to reference the proper frmMain, it would do so... but then i could not access the textbox inside that form instance.
-
Apr 1st, 2013, 12:21 PM
#4
Re: Communicating across threads from module to gui text box
 Originally Posted by dontstealmyfish
When I tried to reference the proper frmMain, it would do so... but then i could not access the textbox inside that form instance.
That's because you declared the field as type Form and that type has no fields that refer to TextBoxes. If you know that the type of the object you want to refer to is frmMain then declare the field as that type. There's no reason not to. You'd only use Form if you want to be able to refer to different types of forms.
-
Apr 1st, 2013, 12:28 PM
#5
Thread Starter
Junior Member
Re: Communicating across threads from module to gui text box
 Originally Posted by jmcilhinney
That's because you declared the field as type Form and that type has no fields that refer to TextBoxes. If you know that the type of the object you want to refer to is frmMain then declare the field as that type. There's no reason not to. You'd only use Form if you want to be able to refer to different types of forms.
Perfect, Thanks! Definitely learned a few things today that I will not forget! declaring the variable as a type of specific form is exactly what I needed to do.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|