473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 14564
A) Don't create any forms
B) If for some reason you have to, then use form.Hide();

"christopher green" <us************@yahoo.com> wrote in message
news:eB**************@TK2MSFTNGP10.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
"christopher green" <us************@yahoo.com> wrote in message
news:eB**************@TK2MSFTNGP10.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("user32.dll",EntryPoint="SetForegroundWi ndow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool MessageBeep(int type);
[DllImport("user32.dll")]
public static extern int SetWindowLong( IntPtr window, int index, int
value);
[DllImport("user32.dll")]
public static extern int GetWindowLong( IntPtr window, int index);
[DllImport("winmm.dll")]
public static extern int sndPlaySound(string lpszSoundName , int uFlags)
;
const int GWL_EXSTYLE = -20;
const int WS_EX_TOOLWINDOW = 0x00000080;
const int WS_EX_APPWINDOW = 0x00040000;

//This is the icon when there are no orders in the system
Icon normalIcon;
public Form1()
{
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

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

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

// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon1.Text = "the text";
notifyIcon1.Visible = true;
//Remove from the taskbar and also from alt+tab
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;

int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);
}
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("user32.dll",EntryPoint="SetForegroundWi ndow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool MessageBeep(int type);
[DllImport("user32.dll")]
public static extern int SetWindowLong( IntPtr window, int index,
int
value);
public static extern int GetWindowLong( IntPtr window, int index);
[DllImport("winmm.dll")]
public static extern int sndPlaySound(string lpszSoundName , int
uFlags)

I suggest also to the the "System.Security.SupressUnmanagedCodeSecurity"
for better performance.

So change the attributes to:
[DllImport("xxx.dll"), System.Security.SupressUnmanagedCodeSecurity]
--
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
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...
3
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
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...
2
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...
2
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...
3
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...
7
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...
1
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...
11
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? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.