473,880 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to run application from system tray

1 New Member
Hey
I'm pretty new to C# (started few hours ago) but i learn extremly fast, i have previous knowledge of php, javascript and flash.

I have made my first simple application the way i want it, however i'm having trouble with the system tray icon, i can show/hide the main window using the icon with a context menu etc.

However what i would like to do it to make the icon go to the system tray when i press the red cross in the top right corner rather than completly closing the application, and if someone wishes to close the application they right click the system tray icon and press exit (which i have already setup)

I asked a friend/coworker for some advice but he was busy, he did however say it had something to do with do with catching the SW_QUERYCLOSE event somewhere, but i've had no luck searching for that.

Any help is apreciated and thanks in advance for your time,
Marc
Mar 24 '08 #1
3 1736
gpraghuram
1,275 Recognized Expert Top Contributor
I think this should be part of .NET forum

Raghuram
Mar 24 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
I ma moving this to the .NET forum.
Mar 24 '08 #3
Plater
7,872 Recognized Expert Expert
Well there'a couple of different ways to do this.

Approach One:
You make an empty form and add the sys icon (NotifyIcon) to THAT form. Then set THAT form as the main start up form.
The only job of this form is to be invisible (visible=false) and to launch (keep a reference to) the form you actually want to show/hide. The functionality of the systray icon is changed to show/hide the form you just launched (instead of like this.visible=fa lse, it would be myActualForm.Vi sible=false, etc)


Approach Two:
On the form you show/hide, you would attach an event handler to the Closing event for the form. There you would take action depending on what the type is (you would want to make sure the OS can close the program, only want to deal with the user tries to close).
You would also want to implent some logic (a simple boolean value perhaps?) to make sure your menu-click item is allowed to close the application as well.
Mar 24 '08 #4

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

Similar topics

1
3718
by: Greg Merideth | last post by:
Is there a way via c# to hook a system tray application into the windows keyboard que globally so that when the application is running and you press, say, control-alt-shift-f11 the system tray app could respond to that keypress (much in the way my pgp app encrypts on ctrl-alt-e) even though its minimized and your in a different app? I've got an app thats a system tray and while its easy to access the data I'm just trying to add an extra...
0
1454
by: Vinay Agarwal | last post by:
Hello, I am writing an application that wants to monitor another application's state (on the same computer). This other application is a commercial application and I do not have access to its source. The state of this other application is clearly visible through its Notify icon in the system tray which changes with the state change. I have following two questions with two different approaches to this monitoring: 1. Is it possible to...
3
2066
by: dencdr | last post by:
Hi, I have an application VB.NET (using Form Win32) with no icon in TaskBar. When a FORM of this application is visible I see this application in the list of "Alt+Tab" choice. How do for this application does not appear in this list when a FORM is visible ?
4
3961
by: Curious Coder | last post by:
I have been tasked with a project that I do not think can be accomplished. Our company has an application that runs as an unmanaged ActiveX control on user desktops. It is designed to work with our phone system. When a phone call comes in, users can click a button on the ActiveX control and begin recording. My task is to fire off this recording, behind the scenes, without user interaction, using the existing instance of the ActiveX...
1
3300
by: Geraldine Hobley | last post by:
Hello, I have an icon in my system tray and I wish to call various functions from withing the tray which involve the application been maximized. The following event is on the system tray icon Dim mouse As Cursor Dim Myprojectdet As New frmProjectDetails If SetupContextMenu(cmnuSysTray, "SystemTray", Myprojectdet.ImgJobDetails) Then cmnuSysTray.TrackPopup(New
10
3154
by: Crouchie1998 | last post by:
Hello To All You Real Programmers Out There!! There is an application called: "Tray It" Webpage: ---------- http://www.teamcti.com/trayit/trayit.htm Direct Download:
11
1992
by: Jay | last post by:
Hey There, I have a system tray application that is running, and it needs to communicate with a Windows Service that I wrote. My problem is that if a user switches to another desktop, I need the service to have communication be able to distinguish that data needs to be sent to app A instead of app B. I was going to try to use a desktop handle to distinguish between the two, but I can't create the service as an interactive service (nor...
4
6137
by: Octavius Khan | last post by:
I have an application that runs in the system tray and I use global hotkeys to perform functions. When certain hotkeys are pressed, my system tray application may display a message box and sometimes a balloontip, but then focus is taken away from the application the user is using when this happens. How can I return focus to the original application? For example, let's say the user is using Notepad and then presses Ctrl-F9. This causes...
1
5649
by: =?Utf-8?B?RW5naW5lZXJpaw==?= | last post by:
I have an application which uses a notification icon in the system tray. When the application is closed the notification icon remains in the system tray until I hover over it with the mouse. How can I refresh the system tray to remove the notify icon when the app closes?
0
9926
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
9774
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
11093
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...
0
10715
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
9550
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...
0
5778
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4596
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
4192
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3220
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.