473,795 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

88 New Member
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 toolstripbutton s 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 1072

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

Similar topics

0
1762
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 up deactivated because the event does not fire. Ed,
2
1131
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 or utilizing an ArrayList to hold references to the forms, adding a form item to the array each time a new form is loaded, and then looping thru the class of forms to find the reference? 'clsForm is a class similar to an ArrayList
3
3521
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 that I avoided it. I now have a project with MDI child forms and non-MDI child forms coming and going as the user selects different options. I need to know which form is the active one and thought that I could use the Activate and Deactivate...
0
1982
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 using the following method... Private Sub ShowForm(ByVal form)
3
8631
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 sure my question can be extrapolated to the more general case, so here goes! I have a box standard windows forms project. (File, New Project, Windows Application, OK)
1
1608
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. What i am trying to do now is have a previous/next button on the form i just opened and have it go through the list of items depending on whats previous or next to that item. I pretty much have the logic for that, the only issue i cant seem to...
1
5148
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 as intended (It picks up files to be proccessed out of watch directories) however there seems to be an issue when the Windows App is called. I use the below to call the application: ProcessStartInfo theProcess; theProcess = new...
2
2214
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
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.