473,666 Members | 2,474 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 2536
Plater
7,872 Recognized Expert Expert
I usually just use menu.Visible=!m enu.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
4037
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 on it... (Kinda like a menu, you make your choice from) But since this table can get very long, I've put something of a 'search-form' on top, which enables the user to make a
0
1098
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 ????? Thanks DD
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 only 3/4" tall and the size of the form is correct, but there is nothing on it. If, in design view, I move some fields around that stretch the form, the big empty box I have changes accordingly, but still nothing but the header appearing. Any...
1
1378
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 left(dock=left). How can I do it? (I tried to add them first without docking in the order 1),2),3) but after doing the dock it wasn't ok)
0
1076
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 notifyicon, and hidden when the user minimizes the form) The problem I've run into is that Process class is unable to close the application using either the CloseMainWindow() or Close() method, when the form is hidden. It seems that the form's...
2
3704
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 form with a login dialog (initiated in onOpen). When I open the application the form maximizes (as it should). But when the code reopens the form, the form is not maximized. I have DoCmd.Maximize in onOpen,onLoad,onActivate. What else can I try...
3
3335
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 having to be minimized. I have tried putting this.Hide(); in the Load method, but that doesn't work (the form still comes up and needs
1
1359
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 append these fields to form using appendChild - they are moved from their places in page and placed diectly after <form> tag. And sure they vanish from the browser and can't be edited. How shall I append these fields to form to not to lose them and...
1
1100
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 respective page without authentication and authroization process. I have given my hyper link in my page to go another application. When tried this one, It is going login page , because tried application has form authentication. Here I have to...
8
2569
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 together making a form. But somthing strange goes on: the form will only pass it's fields forward under method GET, but not on POST. Here's a snippet of code, just the basics: print "<form name=\"postcomment\" action=\"".HTTP_ROOT."/pages/
0
8352
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
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7378
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
6189
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
5661
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
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
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.