|
-
Jul 27th, 2007, 03:41 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [02/03] Manipulate a form from a different class
Hello,
I have three classes, Common, A, and B. A and B reference Common so that they have access to variables inside it (I know this may be bad design, but I didn't do it, and I can't change it). From A, I can make a new B.Main form. No problem. However, we only want one copy of B.Main open at a time. So, we store a variable in Common called (basically) BMainOpen (boolean). In A, if they try to open a new instance of form B, and one is already open, I would like to give them the ability to jump to the point they wish, not just close it and open a new one. However, I need to know the...?... handle?... memory address?... of the open B.Main form, so I can manipulate it (load the correct data, set the selectedTabPage of the tab control, etc.). I thought I would just add another variable of type B.Main to Common, but I can't reference B from Common because B already references Common, which would cause circular dependency (the VB IDE won't let me).
In Form A
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f as B.Main
If Not BMainOpen Then
f = new B.Main
Else
f.? = MyStoredVariable
End If
f.DoStuff()
f.Show()
End Sub
I just need to know what f.? and MyStoredVariable would be.
Confused? I tried to make it as simple as I could. Anyone know the solution?
Thanks
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jul 27th, 2007, 03:47 PM
#2
Re: [02/03] Manipulate a form from a different class
Use.ShowDialog() instead of .Show. That will stop the processing on form A so they cant go back until they close form B.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 27th, 2007, 03:52 PM
#3
Thread Starter
Fanatic Member
Re: [02/03] Manipulate a form from a different class
I regularly use ShowShowDialog, but, in this case, they want to be able to have Form B open and Form A still be responsive.
See, Form B is used to attach things (pics, pdfs, whatever) to different objects. So, it interacts heavily with things outside of our main program (not Form A, but the MDIParent of Form A).
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jul 27th, 2007, 04:00 PM
#4
Re: [02/03] Manipulate a form from a different class
Ok, then create a public object variable of form B in a Module. Then when you create the instance from A you can test for B being opened or created yet. If it is then just reuse it or messagebox to the user that they need to close the other form B first.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 27th, 2007, 04:09 PM
#5
Thread Starter
Fanatic Member
Re: [02/03] Manipulate a form from a different class
Well, that is what I tried to do. I tried to create a public object variable of class B form Main in my Common Class (we call them modules). But, B references Common, so Common can't reference B to get that Main form type.
So, I was thinking, maybe I could store the memory address of my open form B and then just DirectCast it something over in form A.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jul 27th, 2007, 04:18 PM
#6
Re: [02/03] Manipulate a form from a different class
Im not sure of your form designs but if you created the form B object variable in a Module or in the general declarations section of your Main form then it should work.
"Common Class" is not a valid term. A Module is a Module and shouldnt be called anything else. It creates confusion as it just did for me.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 27th, 2007, 04:46 PM
#7
Thread Starter
Fanatic Member
Re: [02/03] Manipulate a form from a different class
I was trying to say, in the Common Module,
Dim frmOpenFormBMain as B.frmMain
But I couldn't reference it, because B referenced Common already. So, I just changed it to
Dim frmOPenFormBMain as Form
And, then, when I need to use it, I just DirectCast(frmOpenFormBMain, B.frmMain).
Problem solved.
Thanks for the help. Looking at this from different angles made me realize I could just use a generic form. Also, I tried it using and Object instead of a Form, and it worked like that, too.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jul 27th, 2007, 04:52 PM
#8
Re: [RESOLVED] [02/03] Manipulate a form from a different class
You can also Inherit a form a different way, probably better too. In the forms designer code where it says "Inherits System.Windows.Forms.Form" you can change that to say "Inherits frmOpenFormBMain". Then it wont be dependant upon form b but it will only be "created" off of form b as a template.
This is called Visual Inheritance.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
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
|