Load form count
-
Hello, How could I trace which form was previously loaded within my application? Sorry but I'm a bit lost on how to explain this let alone put this into code. Here's the story, I have an application which loads to form1. From form1 I can load to form2. Then from form2 I can load back to form1 taking a couple of variables to display in my datagrid in form1. So I was looking at a broken code like this
If previous form = form1 then
execute cmd1
else if previous form = form3 then
execute cmd3
etc....Any help would be greatly appreciated. Thanks in advance :-D
Aim small, miss small
-
Hello, How could I trace which form was previously loaded within my application? Sorry but I'm a bit lost on how to explain this let alone put this into code. Here's the story, I have an application which loads to form1. From form1 I can load to form2. Then from form2 I can load back to form1 taking a couple of variables to display in my datagrid in form1. So I was looking at a broken code like this
If previous form = form1 then
execute cmd1
else if previous form = form3 then
execute cmd3
etc....Any help would be greatly appreciated. Thanks in advance :-D
Aim small, miss small
Implement a shared variable on the form and increase it in the constructor and decrement when destroying the form. Something like,
class whatever
Implements IDisposable
Private mblnDisposed As Boolean = FalsePublic Shared iCount As Integer = 0 Sub New() iCount += 1 End Sub
'Dispose, etc down here
end classAny suggestions, ideas, or 'constructive criticism' are always welcome.
-
Hello, How could I trace which form was previously loaded within my application? Sorry but I'm a bit lost on how to explain this let alone put this into code. Here's the story, I have an application which loads to form1. From form1 I can load to form2. Then from form2 I can load back to form1 taking a couple of variables to display in my datagrid in form1. So I was looking at a broken code like this
If previous form = form1 then
execute cmd1
else if previous form = form3 then
execute cmd3
etc....Any help would be greatly appreciated. Thanks in advance :-D
Aim small, miss small
You're treating forms like a trail of breadcumbs. This is not the case. Forms create instances of other forms in a hierarchical fashion. If, say, Form1 creates an instance of Form2 to get some data, Form1 should call Form2's
.ShowDialog
method, notShow
. This way, Form1 will know exactly when Form2 is closed and is free to grab any data it needs from it. Form2 should not care at all which form created it, nor should it care about what data it needs to pass back to the form that called it. It's not Form2's job to do any of this. Form2's job is just to get data from the user or whever, not to pass it around. Form1 should know which methods it needs to call on Form2, not the other way around.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
You're treating forms like a trail of breadcumbs. This is not the case. Forms create instances of other forms in a hierarchical fashion. If, say, Form1 creates an instance of Form2 to get some data, Form1 should call Form2's
.ShowDialog
method, notShow
. This way, Form1 will know exactly when Form2 is closed and is free to grab any data it needs from it. Form2 should not care at all which form created it, nor should it care about what data it needs to pass back to the form that called it. It's not Form2's job to do any of this. Form2's job is just to get data from the user or whever, not to pass it around. Form1 should know which methods it needs to call on Form2, not the other way around.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Dave Kreskowiak wrote:
You're treating forms like a trail of breadcumbs.
:laugh: yeah I guess you're right.
Dave Kreskowiak wrote:
Form1 should call Form2's .ShowDialog method, not Show
got it! Form1 calls upon data that form2 generates not form2 passes the data back to form1. Many thanks again for the tip! :-D
Aim small, miss small