473,414 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Problem in Form Activated and Deactivate events (Windows app, .Net 4.0).

88 64KB
Scenario
This is a non-MDI windows application.
I have a home form containing a panel named Panel1 and two buttons btnForm1 and btnForm2. Clicking btnForm1 and btnForm2 opens up Form1 and Form2 respectively in Panel1. Before a form is opened in Panel1, all opened forms in Panel1 are cleared. The code follows:
Expand|Select|Wrap|Line Numbers
  1. Private objForm1 As Form1
  2. Private Sub btnForm1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm1.Click
  3.     objForm1 = New Form1
  4.     objForm1.FormBorderStyle = Windows.Forms.FormBorderStyle.None
  5.        objForm1.TopLevel = False
  6.        objForm1.Dock = DockStyle.Fill
  7.     Panel1.Controls.Clear
  8.     Panel1.Controls.Add(objForm1)
  9.     objForm1.Show()
  10. End Sub
  11.  
  12. Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm2.Click
  13.     Dim objForm2 As New Form1
  14.     objForm2.FormBorderStyle = Windows.Forms.FormBorderStyle.None
  15.        objForm2.TopLevel = False
  16.        objForm2.Dock = DockStyle.Fill
  17.     Panel1.Controls.Clear
  18.     Panel1.Controls.Add(objForm2)
  19.     objForm2.Show()
  20. End Sub
  21.  
In Form1 there's a button btnForm3 that opens up Form3 in frmHome.Panel1 just above Form2 without clearing any existing forms in Panel1. This is not done by
btnForm3_Click event directly, rather a friend event declared in this form is raised in btnForm3_Click which is handled in frmHome. The code in frmHome to handle it follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub objForm1_LoadForm3InHome() Handles objForm1.LoadSubForm3InHome
  2.     Dim objForm3 As New Form3
  3.     objForm3.FormBorderStyle = Windows.Forms.FormBorderStyle.None
  4.        objForm3.TopLevel = False
  5.        objForm3.Dock = DockStyle.Fill
  6.        Panel1.Controls.Add(objForm3)
  7.        objForm3.Show()
  8.        objForm3.BringToFront()
  9. End Sub
  10.  
All the four forms have Add, Edit and Delete buttons among their toolstripbuttons that are common to all of them. They also have File menu among their menuitems that are common to them.

Objective
To merge the menu and toolstrip of the currently active form in frmHome.Panel1 to the menu and toolstrip of frmHome. To unmerge the menu and toolstrip of the currently active form in frmHome.Panel1 from the menu and toolstrip of frmHome when the active form of
the panel is deactivated. This can be handled by including the undermentioned lines in the form that will open in frmHome.Panel1:
To merge
Expand|Select|Wrap|Line Numbers
  1. ToolStripManager.Merge(Me.MenuStrip1, frmHome.MenuStrip1)
  2. ToolStripManager.Merge(Me.ToolStrip1, frmHome.ToolStrip1)
  3.  
To unmerge
Expand|Select|Wrap|Line Numbers
  1. ToolStripManager.RevertMerge(frmHome.MenuStrip1)
  2. ToolStripManager.RevertMerge(frmHome.ToolStrip1)
  3.  
Problem
In which events should the above lines be written?
In MDI apps this could have been accomplished by including them in Form_Activated and Form_Deactivate events respectively. But here neither Activated nor
Deactivate events fire when you open forms in frmHome.Panel1. Instead of Activated and Deactivate you can use Form_Load and Form_FormClosed events but they will only merge/unmerge menus if existing forms are closed before opening a new form in the panel. But as I sometimes need forms to be opened and closed keeping existing forms opened, using these events won't fulfill the task. Even the GotFocus and LostFocus events won't work. So I want Activated and Deactivate events to be fired or some other means by which the menus and toolstrips can be merged/unmerged when the form gains/
looses focus respectively. This is driving me crazy. I can't at all find a way out. Please help. Regards.
Apr 3 '11 #1
0 1059

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: gencode | last post by:
I need to know if my form(main app) is activated or not at any given time. There are the Activated and Deactivated events and I can toggle a local flag but that does not help if the form starts...
2
by: Dean Slindee | last post by:
I have two different independent forms that need to talk to one another to syncronize their displays. Is there a shorter way of referring to another form's controls/events than creating a class...
3
by: active | last post by:
I remember when I checked NewGroups for comments about the VB6 Activate event and found that many thought it was not a reliable way to keep track of which form has focus. There was enough bad press...
0
by: A_PK | last post by:
Hi I got the following environment.......Form1 and inside Form1, got Panel1.... I also got another new Form ...named Form2... Form1, Panel1 Form2 Inside Form1, I click a button to show Form2...
3
by: garyusenet | last post by:
Dear Professionals, I have recently been using the wonderful krypton toolkit and am trying to use them in my small hobby application. I include this bit of info as an aside really because i'm...
1
by: Pumpkin Carver | last post by:
I have a form that has a listview on it and a serious of strings in the listiew. When i doubel click on the listview item it opens a new form and displays the text that i pass to the constructor....
1
by: trinityofsouls | last post by:
I am trying to run a windows application from a service. Both the Windows Form App and the Windows Service were created using the .NET 2005 "New Project" Templates. There service is working...
2
by: noorcsharp | last post by:
hello friends, there is no ( Form_Activated Event ) in C#.Net. but vb,vb.net have this event. is there any alternate for form Activated event.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.