473,770 Members | 3,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

invisible c# windows application

I am writing a C# windows application but I don't want to display any
forms, effectively I want it to be invisible on the desktop apart from
an icon in the system tray. How can I do this? I know I can start an
application minimised but I don't want to display any forms.

Thanks for your assistance.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
5 14595
A) Don't create any forms
B) If for some reason you have to, then use form.Hide();

"christophe r green" <us************ @yahoo.com> wrote in message
news:eB******** ******@TK2MSFTN GP10.phx.gbl...
I am writing a C# windows application but I don't want to display any
forms, effectively I want it to be invisible on the desktop apart from
an icon in the system tray. How can I do this? I know I can start an
application minimised but I don't want to display any forms.

Thanks for your assistance.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
christopher green <us************ @yahoo.com> wrote:
I am writing a C# windows application but I don't want to display any
forms, effectively I want it to be invisible on the desktop apart from
an icon in the system tray. How can I do this? I know I can start an
application minimised but I don't want to display any forms.


Just don't create any forms then. There's nothing forcing you to.

I don't know offhand how you put an icon in the system tray, but I'm
sure there's code around the net to help you with that part.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
"christophe r green" <us************ @yahoo.com> wrote in message
news:eB******** ******@TK2MSFTN GP10.phx.gbl...
I am writing a C# windows application but I don't want to display any
forms, effectively I want it to be invisible on the desktop apart from
an icon in the system tray. How can I do this? I know I can start an
application minimised but I don't want to display any forms.


A WinForms app doesn't *have* to have any forms in it - it's not
compulsory.. :-)
Nov 16 '05 #4
Hi

This is the code I'm using to do that, I saw a post today that do not
require P/invoke but I havent test it yet

using System.Runtime. InteropServices ;

[DllImport("user 32.dll",EntryPo int="SetForegro undWindow")]
public static extern bool SetForegroundWi ndow(IntPtr hWnd);
[DllImport("user 32.dll")]
private static extern bool MessageBeep(int type);
[DllImport("user 32.dll")]
public static extern int SetWindowLong( IntPtr window, int index, int
value);
[DllImport("user 32.dll")]
public static extern int GetWindowLong( IntPtr window, int index);
[DllImport("winm m.dll")]
public static extern int sndPlaySound(st ring lpszSoundName , int uFlags)
;
const int GWL_EXSTYLE = -20;
const int WS_EX_TOOLWINDO W = 0x00000080;
const int WS_EX_APPWINDOW = 0x00040000;

//This is the icon when there are no orders in the system
Icon normalIcon;
public Form1()
{
this.notifyIcon 1 = new System.Windows. Forms.NotifyIco n(this.componen ts);

// The Icon property sets the icon that will appear
// in the systray for this application.
notifyIcon1.Ico n = normalIcon;

// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon1.Con textMenu = this.contextMen u1;

// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon1.Tex t = "the text";
notifyIcon1.Vis ible = true;
//Remove from the taskbar and also from alt+tab
this.WindowStat e = System.Windows. Forms.FormWindo wState.Minimize d;
this.Visible = false;
this.ShowInTask bar = false;

int windowStyle = GetWindowLong(H andle, GWL_EXSTYLE);
SetWindowLong(H andle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDO W);
}
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nov 16 '05 #5
Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi

This is the code I'm using to do that, I saw a post today that do not
require P/invoke but I havent test it yet

using System.Runtime. InteropServices ;

[DllImport("user 32.dll",EntryPo int="SetForegro undWindow")]
public static extern bool SetForegroundWi ndow(IntPtr hWnd);
[DllImport("user 32.dll")]
private static extern bool MessageBeep(int type);
[DllImport("user 32.dll")]
public static extern int SetWindowLong( IntPtr window, int index,
int
value);
public static extern int GetWindowLong( IntPtr window, int index);
[DllImport("winm m.dll")]
public static extern int sndPlaySound(st ring lpszSoundName , int
uFlags)

I suggest also to the the "System.Securit y.SupressUnmana gedCodeSecurity "
for better performance.

So change the attributes to:
[DllImport("xxx. dll"), System.Security .SupressUnmanag edCodeSecurity]
--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4888
by: Jose_Csharp | last post by:
Hi guys, I´m trying to make a startup invisible form. I don´t want a form with Opacity property 0. First I did the property Visible of the form to false. It wasn´t a good idea, was too easy. Then I follow the tips of MSDN making a new class with an instance of the form that has the logical of the application. But it not run since I call the ShowDialog() method. Please, can anyone gime me a tip or any web with an example? I´m a newbie.
3
3818
by: Dakkar | last post by:
I made a program like i showed below and i used this.Visible = false; line to make it invisible but it doesnt work where did i make mistake ? here is my code
0
1111
by: Emmanouel | last post by:
Hello everybody, I have a program that i would like to run as a system tray application. This means that i do not need the main form to appear. I found in net help that : “To make the main form of a Windows application invisible when the application starts, you have to move the application's startup logic into a separate class. You cannot simply set its Visible property to false.” In the net help it says that I should add something...
2
1243
by: Johnny Ruin | last post by:
I ran the wizard to generate default Windows Forms Application. I wanted to make it invisible, so I added the line "this->Visible = false;" to the InitializeComponent function. I rebuilt it and dang ... it wasn't invisible. What else should I try? void InitializeComponent(void) { this->components = new System::ComponentModel::Container(); this->Size = System::Drawing::Size(300,300); this->Text = S"Form1";
2
1580
by: graeme34 via AccessMonster.com | last post by:
Hi I was wondering if there was any way of making the windows for the currently opened objects in access invisible on the bottom toolbar. Iam using Access 2003 also is it possible to turn of the right click facility on the mouse to prevent the user from getting into the 'background' of Access?? Thank you. -- Message posted via http://www.accessmonster.com
3
9833
by: Nicol | last post by:
Hi, I have created a console application in c#.net. I also scheduled it in the windows scheduler. In the scheduled task i will specify the command line arguments. When I say "Run", I am getting the command window, which I dont want. I need to run my application in silent mode. My system is windows 2003 server. Please help me in this. Thanks
7
7025
by: Nader | last post by:
It's easy to make the last row in a datagrid (filled with a table) invisible: datagridObject.Rows.Visible = false BUT if 'i' is not the last row then things go wrong. I even tried: for (int i = datagridObject.Rows.Count - 1; i >= 0; i-- ) {
1
1517
by: | last post by:
Hi! I'm running a Python program on M$ Windows 2000 as a test monitor. The program should close various processes, mostly "Application error"-windows, as they are created. This works fine until the screensaver gets active or until I press Ctrl-Alt-Del and choose "Lock my computer". At that point, my Python program cannot see any change when a "Application error" pops up. Without locked computer, it can identify these windows and close...
11
2962
by: Simon van Beek | last post by:
Dear reader, By opening an application I get always the main Access window with the closing cross in the above right corner. Is there a possibility to make this closing cross invisible? All the settings in the Start-up form under Tools are disabled but the closing cross in the above right corner is still visible.
0
9595
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
9432
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
10232
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
10008
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
9873
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
8891
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
3974
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
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
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.