|
-
Jul 15th, 2006, 07:20 PM
#1
Thread Starter
Addicted Member
Interaction Between FORM
Interaction between form
Hi, i have two form, One is MDI Child (FORM1) and another is "normal form"
(FORM2) that i show from FORM1 with "vbModelless". When
some control on FORM2 get clicked "text" property of
"textBox" control on FORM1 change. I was able to do
that, but Event "textbox.change" on textbox control
FORM1 didn't executed. On this change event i change
value almost every control on FORM1 and execute some
function on FORM1.
My question is
1. How is the proper way to achieve my goal above?
2. How to passed variables between FORM1 to FORM2? so
FORM2 will act properly according to what variables been
pass to it or if i change variables that been pass to
FORM2, how FORM1 wil recognize it's new Value?
3. How FORM1 know that FORM2 has gone?
4. How to position FORM2 relative on some control on
FORM1 (FORM1 can be move)? FORM2 will be launch wen
"COMMANDBUTTON" on FORM1 get clicked, i want FORM2 popup
exactly under this "COMMANDBUTTON".
All you VB Guru please help me....
Thanks.
PS: i will away for a while so i'm sorry if i'm not able
to response to you follow up question.
-
Jul 15th, 2006, 07:46 PM
#2
Re: Interaction Between FORM
Read up on using custom properties to manage the movement of data between forms.
-
Jul 15th, 2006, 07:47 PM
#3
Re: Interaction Between FORM
1. If you change Text1 then the Change event must be firing.
2. To refer to something on another form you need to include the name of the other form like Form.Text1.Text = "blah"
3. Set some Public variable in a code module or check the Forms collection.
4. ???
-
Jul 15th, 2006, 08:03 PM
#4
Thread Starter
Addicted Member
Re: Interaction Between FORM
Hi, thanks
Martin
1. Yes, textbox is change but still change event doesn't firing.
2. I set FORM1 to become object on FORM2, something like
on FORM1:
Dim frm1 As FORM1
Set frm1 = New FORM1
Set frm1.fMain = Me
frm1.Show
on FORM2
Public fMain As FORM1
is that not the correct way.
when on FORM2 i'm using FORM1.textBox.text="BLAH BLAH", it will show up FORM1
ones again, although it already open.
3. I'm going to try that, thank
4. i want FORM2 to show up exactly under control on FORM1 (while FORM1 can be move)
Thanks
-
Jul 16th, 2006, 08:13 PM
#5
Thread Starter
Addicted Member
Re: Interaction Between FORM
-
Jul 16th, 2006, 08:22 PM
#6
Re: Interaction Between FORM
umm, regarding your event problem. The textbox change event is firing - just not on the form you want it to. If you create a new instance of a form using:
VB Code:
Dim frm1 As FORM1
Set frm1 = New FORM1
Set frm1.fMain = Me
frm1.Show
then you must continue to refer to that using an object reference - in the manner that the frm1 object is being used to show the instance of form1 (however since the varaible is local to the sub, you won't be able to use that particular object to refer to that form outside of that procedure - you'd need a modular level or public object).
By refering to that object as Form1:
VB Code:
FORM1.textBox.text = "BLAH BLAH"
you are creating (and setting the textbox text) of a new instance of Form1 - different from the one that you are showing.
Are you using multiple instance of Form1 in your program? If not, then there is no need to create a new insatnce of the form using Set frm1 = New FORM1. Just refer to the form using it's design-time name.
-
Jul 16th, 2006, 09:22 PM
#7
Re: Interaction Between FORM
In Form2 you should use: fMain.Text1.Text = "blah" since fMain contains a reference to the form you have loaded.
-
Jul 16th, 2006, 11:24 PM
#8
Thread Starter
Addicted Member
Re: Interaction Between FORM
Yes Joacim i'm using - fMain.Text1.Text = "blah" -
bushmobile,
No i Don't create multiple instance of FORM1 in my program, but if i'm refer it using design time name (FORM1) it will open FORM1 ones again although it already open, btw FORM1 is MDI Child. So waht is best approach for my purpose?
About, textbox event change don't firing, it's resolved. It was my mistake, since i create usercontrol from textbox and forget to add Raisevent Change on that usercontrol event change.
Set position of FORM2 to show up on exact location of control FORM1 (as my question #4) also resolved. I got it from vbaccelerator.com
But now if try to moving variables between FORM. Declared it as Public on module is last option.
I was interrest wit custom properties, and learning it right now. My question is what about if FORM2 should return variable more than one? better using array on Custom Properties or create custom properties .value1 , value2, so on...?
And i still don;t get it how FORM1 know that FORM2 has gone? or how to tell FORM1 when FORM2 has gone?
In my application when some button on FORM1 get clicked FORM2 popup exactly under this button. When some control from FORM2 get clicked TEXTBOX on FORM1 value get changed. When user clicked outside FORM2 FORM2 get unload. So where is correct time to tell FORM1 that FORM2 has gone?
Thanks guy
Last edited by barianto; Jul 16th, 2006 at 11:32 PM.
-
Jul 17th, 2006, 07:40 AM
#9
Re: Interaction Between FORM
 Originally Posted by barianto
bushmobile,
No i Don't create multiple instance of FORM1 in my program, but if i'm refer it using design time name (FORM1) it will open FORM1 ones again although it already open, btw FORM1 is MDI Child. So waht is best approach for my purpose?
Then you are creating multiple instances of Form1. VB automatically creates an object of a Form with the same name as the class. This object is however doesn't have any instance until you start to use it, which you do when you use the name Form1. That's another instance of the Form apart from the one you've created with the New keyword.
-
Jul 17th, 2006, 08:22 PM
#10
Thread Starter
Addicted Member
Re: Interaction Between FORM
Well i don't need create multiple instance in my program, So what should i do?
-
Jul 17th, 2006, 08:24 PM
#11
Re: Interaction Between FORM
-
Jul 17th, 2006, 09:23 PM
#12
Re: Interaction Between FORM
Since Form2 has a reference to the form that showed it (fMain) simply create a public sub in Form1 which you call from Form2 when it's time to unload itself. You can pass any values back to this sub in Form1, just remember that in Form2 this form is called fMain and nothing else.
VB Code:
'In Form1
Public Sub Form2Closes(ByVal someValue As Long, ByVal anotherValue As String)
'do whatever
End Sub
'in Form2, for example in the Unload event
Private Sub Form_Unload(Cancel As Integer)
'Let Form1 know that it is closing time :)
Call fMain.Form2Closes(25, "Hello world")
End Sub
Of course the values 25 and "Hello world" above should be replaced with whatever values you want to pass back to Form1.
-
Jul 17th, 2006, 10:54 PM
#13
Thread Starter
Addicted Member
Re: Interaction Between FORM
Okay, just frm1.show
Guys thanks all for your kindly response, that give me much new idea how thing can be done in vb.
All my problem had been answered now:
1. It's my own fault, when textbox change, it's definitely should firing event textbox.change. I managed to found where the problem is.
2. I'm using CUSTOM PROPERTIES
3. Also using CUSTOM PROPERTIES
4. I'm using this
VB Code:
Dim tR As RECT
GetWindowRect picCommandbar.hwnd, tR
FORM2.Move tR.Left * Screen.TwipsPerPixelX, (tR.Bottom + 1) * Screen.TwipsPerPixelY
picCommandbar is reside on FORM1
Cheer
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
|