Hi
I have a main form which contains a panel which contains a child form. So
the hierarchy is as follows; frmMain->MyPanel-> frmChild
I have a toolbar on the main form. When a user presses a button on the
toolbar, how can I pass on the event to the child form?
Taking it further, is it possible to make it generic so that event is passed
to any child form (frmchild1, frmchild2,... so on) that is currently open in
the panel?
Some code examples would be appreciated.
Thanks
Regards 11 2182
"John" <jo**@nospam.infovis.co.uk> schrieb I have a main form which contains a panel which contains a child form. So the hierarchy is as follows; frmMain->MyPanel-> frmChild
I have a toolbar on the main form. When a user presses a button on the toolbar, how can I pass on the event to the child form?
When you get the click event, call a method of the child form. The child
form doesn't need to listen to the toolbar's events.
Taking it further, is it possible to make it generic so that event is passed to any child form (frmchild1, frmchild2,... so on) that is currently open in the panel?
Add the child forms to an array/arraylist/coolection and call the method
mentioned above in a loop.
Some code examples would be appreciated.
--
Armin
"Armin Zingler" <az*******@freenet.de> wrote in message
news:uI**************@TK2MSFTNGP11.phx.gbl... When you get the click event, call a method of the child form. The child form doesn't need to listen to the toolbar's events.
Would it be like this; call frmMain.mypanel.frmchild.mymethod() ?
Add the child forms to an array/arraylist/coolection and call the method mentioned above in a loop.
There would be only one child form in the panel at any one time. Is there a
generic way to get whatever child form there is? Such as;
MyPanl.<childref?>.mymethod()?
Thanks
Regards
"John" <jo**@nospam.infovis.co.uk> schrieb When you get the click event, call a method of the child form. The child form doesn't need to listen to the toolbar's events.
Would it be like this; call frmMain.mypanel.frmchild.mymethod() ?
You wrote that the toolbar is on the main form. I guess the ButtonClick
event is also handled in the main form. If frmChild is a public property of
the panel, you can write
Me.mypanel.frmchild.mymethod
If you have a reference to the child form in the main form, and if it is
called frmChild, then you can write
Me.frmChild.mymethod Add the child forms to an array/arraylist/coolection and call the method mentioned above in a loop.
There would be only one child form in the panel at any one time. Is there a generic way to get whatever child form there is? Such as;
MyPanl.<childref?>.mymethod()?
You wrote frmChild1, frmChild2, ... You are now saying that these are
different Form types? Where do you hold the refrence to the child? How is it
declared?
Sorry, I first have to ask some questions before finding the right solution.
--
Armin
Hi
I think I am almost there. Thanks.
I am thinking that when a child form is made active in the panel, it leaves
its reference with the main form so the main form always knows which child
form's method it has to call.
Just one thing, how does a child form leaves its reference with the main
form? What variable type to declare and how to assign etc. Any code example?
Thanks
Regards
"Armin Zingler" <az*******@freenet.de> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl... "John" <jo**@nospam.infovis.co.uk> schrieb When you get the click event, call a method of the child form. The child form doesn't need to listen to the toolbar's events. Would it be like this; call frmMain.mypanel.frmchild.mymethod() ?
You wrote that the toolbar is on the main form. I guess the ButtonClick event is also handled in the main form. If frmChild is a public property
of the panel, you can write
Me.mypanel.frmchild.mymethod
If you have a reference to the child form in the main form, and if it is called frmChild, then you can write
Me.frmChild.mymethod
Add the child forms to an array/arraylist/coolection and call the method mentioned above in a loop.
There would be only one child form in the panel at any one time. Is there a generic way to get whatever child form there is? Such as;
MyPanl.<childref?>.mymethod()?
You wrote frmChild1, frmChild2, ... You are now saying that these are different Form types? Where do you hold the refrence to the child? How is
it declared?
Sorry, I first have to ask some questions before finding the right
solution.
-- Armin
"John" <jo**@nospam.infovis.co.uk> schrieb I think I am almost there. Thanks.
I am thinking that when a child form is made active in the panel, it leaves its reference with the main form so the main form always knows which child form's method it has to call.
Just one thing, how does a child form leaves its reference with the main form? What variable type to declare and how to assign etc. Any code example?
Have you already created the structure main->panel->child, or is it your
intention?
If you've already created it, please post the code that creates the panel
and the child and how and where the variables are declared.
As you ask how to declare the variables, I guess you have not created the
structure yet. This is _one_ example how to achieve it:
Private m_Panel As Panel
Private m_Child As ChildForm
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
m_Panel = New Panel
m_Panel.Size = New Size( _
Me.ClientRectangle.Width - 10, _
Me.ClientRectangle.Height - 10 _
)
m_Panel.BackColor = Color.Blue
Me.Controls.Add(m_Panel)
m_Child = New ChildForm
m_Child.TopLevel = False
m_Child.Visible = True
m_Panel.Controls.Add(m_Child)
End Sub
Private Sub ToolBar1_ButtonClick( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) _
Handles ToolBar1.ButtonClick
m_Child.MethodInChild()
End Sub
Of course, there can be many other approaches depending on the demands for
the application. For example, you could derive your own panel class from the
Windows.Forms.Panel class. Maybe it is not even necessary to put a _Form_
inside the panel.
--
Armin
Hi
This is all very clear. Thanks for that.
Taking it further, I have a number of child forms and I would like to allow
the user to select any to open. Since I would not know what child form user
chooses can I have a generic way to get a handle to the selected child form
in the main form, so that a method of the child form can be called?
Perhaps by having a variant variable child_ref on the master form and in
each child form's load event having something like
call frmMain.set_child_ref (me) ' me is the child form we are currently in.
Thanks
Regards
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... "John" <jo**@nospam.infovis.co.uk> schrieb I think I am almost there. Thanks.
I am thinking that when a child form is made active in the panel, it leaves its reference with the main form so the main form always knows which child form's method it has to call.
Just one thing, how does a child form leaves its reference with the main form? What variable type to declare and how to assign etc. Any code example?
Have you already created the structure main->panel->child, or is it your intention?
If you've already created it, please post the code that creates the panel and the child and how and where the variables are declared.
As you ask how to declare the variables, I guess you have not created the structure yet. This is _one_ example how to achieve it:
Private m_Panel As Panel Private m_Child As ChildForm
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e)
m_Panel = New Panel m_Panel.Size = New Size( _ Me.ClientRectangle.Width - 10, _ Me.ClientRectangle.Height - 10 _ ) m_Panel.BackColor = Color.Blue Me.Controls.Add(m_Panel)
m_Child = New ChildForm m_Child.TopLevel = False m_Child.Visible = True m_Panel.Controls.Add(m_Child)
End Sub
Private Sub ToolBar1_ButtonClick( _ ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) _ Handles ToolBar1.ButtonClick
m_Child.MethodInChild()
End Sub
Of course, there can be many other approaches depending on the demands for the application. For example, you could derive your own panel class from
the Windows.Forms.Panel class. Maybe it is not even necessary to put a _Form_ inside the panel.
-- Armin
In this scenario, is there a way for the child form to get a handle of the
main form so a method on the main from can be called from the child form?
Thanks
Regards
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... "John" <jo**@nospam.infovis.co.uk> schrieb I think I am almost there. Thanks.
I am thinking that when a child form is made active in the panel, it leaves its reference with the main form so the main form always knows which child form's method it has to call.
Just one thing, how does a child form leaves its reference with the main form? What variable type to declare and how to assign etc. Any code example?
Have you already created the structure main->panel->child, or is it your intention?
If you've already created it, please post the code that creates the panel and the child and how and where the variables are declared.
As you ask how to declare the variables, I guess you have not created the structure yet. This is _one_ example how to achieve it:
Private m_Panel As Panel Private m_Child As ChildForm
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e)
m_Panel = New Panel m_Panel.Size = New Size( _ Me.ClientRectangle.Width - 10, _ Me.ClientRectangle.Height - 10 _ ) m_Panel.BackColor = Color.Blue Me.Controls.Add(m_Panel)
m_Child = New ChildForm m_Child.TopLevel = False m_Child.Visible = True m_Panel.Controls.Add(m_Child)
End Sub
Private Sub ToolBar1_ButtonClick( _ ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) _ Handles ToolBar1.ButtonClick
m_Child.MethodInChild()
End Sub
Of course, there can be many other approaches depending on the demands for the application. For example, you could derive your own panel class from
the Windows.Forms.Panel class. Maybe it is not even necessary to put a _Form_ inside the panel.
-- Armin
"John" <jo**@nospam.infovis.co.uk> schrieb Taking it further, I have a number of child forms
You mean different types but not multiple instance at a time?
and I would like to allow the user to select any to open. Since I would not know what child form user chooses can I have a generic way to get a handle to the selected child form in the main form, so that a method of the child form can be called?
Perhaps by having a variant variable child_ref on the master form and in each child form's load event having something like
call frmMain.set_child_ref (me) ' me is the child form we are currently in.
The answer is not simple. It depends...
As there can only be one child form, I would probably declare the variable
"as Form". Does the method to be called have the same signature in different
child types? Does it do the same in all types of child forms?
Same signature, different implementation: Write an Interface and implement
it in all child types.
Same signature, same implementation: Derive your child forms from a base
form containing the common code.
Different signatures: Use
If TypeOf <ChildVariable> Is ChildType1 then
Directcast (<ChildVariable>, ChildType1).MethodInType1
ElseIf TypeOf <ChildVariable> Is ChildType2 Then
Directcast (<ChildVariable>, ChildType2).MethodInType2
elseif ....
end if
to distinguish between different child types.
--
Armin
"John" <jo**@nospam.infovis.co.uk> schrieb In this scenario, is there a way for the child form to get a handle of the main form so a method on the main from can be called from the child form?
It is possible, but why?
--
Armin
Some common methods can be defined on the main form which child forms can
call. This keeps the child forms simpler and it is easy to add more child
forms without adding too much code to them.
Regards
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... "John" <jo**@nospam.infovis.co.uk> schrieb In this scenario, is there a way for the child form to get a handle of the main form so a method on the main from can be called from the child form?
It is possible, but why?
-- Armin
"John" <jo**@nospam.infovis.co.uk> schrieb Some common methods can be defined on the main form which child forms can call. This keeps the child forms simpler and it is easy to add more child forms without adding too much code to them.
Why not derive the child forms from a base class containing the common code?
What kind of code is it?
--
Armin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andy Read |
last post by:
Hello all,
I have the requirement to produce source code that produces an object
hierarchy.
Example:
Root
|
Folder 1
|
by: Christopher W. Douglas |
last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a
method that handles several events, such as closing a form and changing the
visible status of a form. I have some code...
|
by: Mark |
last post by:
Hi,
I'm looking for some ideas on how to build a very simple Event processing
framework in my C++ app. Here is a quick background ...
I'm building a multithreaded app in C++ (on Linux) that...
|
by: Charles Law |
last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my
question about removing event handlers.
> http://www.vbinfozine.com/t_bindevt.shtml
Following on from that post, the...
|
by: Jack Russell |
last post by:
My unstanding of all VB up to and including vb6 is that an event could
not "interrupt" itself.
For instance if you had a timer event containing a msgbox then you would
only get one message.
...
|
by: JohnR |
last post by:
In it's simplest form, assume that I have created a usercontrol,
WSToolBarButton that contains a button. I would like to eventually create
copies of WSToolBarButton dynamically at run time based...
|
by: jeff |
last post by:
New VB user...developer...
Situation...simplified...
- I want to wrap a pre and post event around a system generated where the
pre-event will always execute before the system event and the...
|
by: Daniela Roman |
last post by:
Hello,
I try to fire an event under a button click event and maybe anybody can give
a clue please.
I have let's say a WEB grid with PageIndexChanged event:
private void...
|
by: jaysonnward |
last post by:
Hello All:
I've recently been recreating some 'dropdown menus' for a website I
manage. I'm writing all my event handlers into my .js file. I've got
the coding to work in Firefox, but the...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |