473,508 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Form appearing from MouseClick on NotifyIcon

Tyler Wiebe
66 New Member
The following code makes the Form(menu) appear, and disappear, but if I select a opened window or anything besides the Form(menu) or NotifyIcon, the Form(menu) disappears and will not come back from clicking the NotifyIcon. I would much appreciate if someone could give me a solution to this problem, otherwise there isn't really a point to continue building my program.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.         public static bool menuOpen = false;
  4.         public static int mouseUpXPosition;
  5.         public static Menu menu;
  6.  
  7.         public StartUp()
  8.         {
  9.             InitializeComponent();
  10.             SystemTrayIcon = new NotifyIcon();
  11.             SystemTrayIcon.Icon = Properties.Resources.Icon;
  12.             twSystemTrayIcon.MouseUp += new MouseEventHandler(this.ShowHideIcon_MouseUp);
  13.             SystemTrayIcon.Visible = true;
  14.             menu = new Menu();
  15.         }
  16.  
  17.         private void ShowHideIcon_MouseUp(object sender, MouseEventArgs e)
  18.         {
  19.             switch(e.Button)
  20.             {
  21.                 case MouseButtons.Left:
  22.  
  23.                 if (menuOpen == false)
  24.                 {
  25.                     if (MousePosition.X < Screen.PrimaryScreen.WorkingArea.Width - (menu.Width / 2))
  26.                     {
  27.                         mouseUpXPosition = MousePosition.X;
  28.                         menu.Location = new Point(mouseUpXPosition - menu.Width / 2, Screen.PrimaryScreen.WorkingArea.Height - menu.Height);
  29.                         menu.Show();
  30.                         menuOpen = true;
  31.                     }
  32.                     else
  33.                     {
  34.                         menu.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - menu.Width, Screen.PrimaryScreen.WorkingArea.Height - menu.Height);
  35.                         menu.Show();
  36.                         menuOpen = true;
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     menu.Hide();
  42.                     menuOpen = false;
  43.                 }
  44.  
  45.                 break;
  46.             }
  47.         }
  48.  
  49.  
The Form, that is called StartUp, is invisible to everyone, and this code that is placed in the StartUp Form, is only to show and hide the Form called Menu.

I'm pretty sure nothing from my Form called Menu is causing the problem, but if you think seeing that code would help, let me know.
Mar 9 '11 #1
6 2526
Plater
7,872 Recognized Expert Expert
I usually just use menu.Visible=!menu.Visible to toggle the window. I'm not sure what all the other stuff yo uare doing is all about
Mar 9 '11 #2
Tyler Wiebe
66 New Member
If your reply of menu.Visible was meant to replace the if(menuOpen == false), I appreciate it, I feel rather stupid not thinking of it. And actually, well thinking of other ways of describing my problem, I found my solution, which is

TopMost = true;
TopMost = false;

Simple, effective, and it gets the job done. Thank you though for your advice.
Mar 9 '11 #3
Plater
7,872 Recognized Expert Expert
I wasn't really clear on what you problem was.

An example of what i do would be like this:
Expand|Select|Wrap|Line Numbers
  1. private void ShowHideIcon_MouseUp(object sender, MouseEventArgs e) 
  2.    if(e.Button==MouseButtons.Left)menu.Visible=!menu.Visible;
  3. }
  4.  
I don't mess around with window position though.
Mar 9 '11 #4
Tyler Wiebe
66 New Member
Okay, I see what you mean. But I have actually found out my fix, didn't fix everything.

When my program starts, my Menu Form stays in the same spot of all programs, so lets say I open two other programs, those will be in front of my Menu Form, if I click the NotifyIcon, it shows and hides, but it doesn't come in front of the other programs. With the

TopMost = true;
TopMost = false;

It comes to the front like I want, but if it was open, it needs to be double clicked, so that it will close, and then open on top.

Is there any event that will activate when my application is not the top window?
Mar 10 '11 #5
Plater
7,872 Recognized Expert Expert
Why not leave topmost always true and then just show/hide the window?
Mar 16 '11 #6
Tyler Wiebe
66 New Member
All I want is it to hide when it's not in use. Like when you click the volume icon, the menu appears, but when you select anything else, it hides.
Mar 19 '11 #7

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

Similar topics

6
4021
by: Joop | last post by:
Hi all, I'm kinda new to JavaScript, but hey... I'm trying anyway! ;-) So, here's my problem : I've created a table in my document, presenting a list of items, one can 'select' by clicking...
0
1093
by: DD | last post by:
Hi when i open a form, then walk away from the computer and my screensaver comes on. When i clear the screensaver infront of me is the code window Is this a problem that can be fixed or ????? ...
1
453
by: Andrew | last post by:
I recently copied an old form and modified it with new fields and such, and now when I try to simply open the form (view it to enter data) there is nothing but the header showing! The header is...
1
1370
by: juli jul | last post by:
Hello, I need to place those controls in the form in the order that I am writing: 1)ListView (aligned dock to "Fill") 2)Spliter aligned to left(dock=left). 3)TreeView aligned to...
0
1073
by: tim | last post by:
I have an vb application that is started/stopped using the System.Diagnostics.Process class. The application has both a form, and a notifyicon. (The form is displayed when the user clicks the...
2
3698
by: insomniux | last post by:
Hi, I have an Access 2000 database with one main form in which all subforms are embedded. In this form I have a timer which closes the form, detaches the linked (ODBC) tables and reopens the same...
3
3325
by: Raj Wall | last post by:
Hi, I have an application which, when running, is to be seen only in the system tray as a right-clickable icon. However I want the main Form window itself to immediately disappear without...
1
1354
by: udivitelno | last post by:
Here is the problem: part of the form elements is replaced using Ajax. After this new input elements getting lost from the form so nothing can be POSTed through these input fields. But if I try to...
1
1095
by: th12345 | last post by:
I have implemented the form authentication in my application. whenever i tried to go particular page . It is automaticaly is going to login page of another application. Because I am trying to go...
8
2562
by: bruno_guedesav | last post by:
This has ocurred before, but if the person had find a way to solve it or not, I've got no clue. So, here I am to ask for help. I've created a form via pure PHP, basically a bunch of prints...
0
7224
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
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
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...
1
7038
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...
1
5049
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...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
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.