|
-
December 17th, 2004, 06:22 AM
#1
Hide Form
Hello,
I'd like to know how to hide the main form. I mean i don't want my application show any form, just run quitely on the background.
The main form doesn't have visible property, so i'm just stucked now.
i can only find the similiar answer on google at http://www.greatis.com/delphicb/tips...-showform.html
but it's in Delphi/ c++ and in c# we don't have Application.ShowMainForm=False;
Please help me.
Thanks for any helps.
-
December 17th, 2004, 06:23 AM
#2
Re: Hide Form
I think i might need to use an API to achieve this, but dont' know what function to look at
-
December 17th, 2004, 07:16 AM
#3
Re: Hide Form
What is the Form for if you can't see it?
Form has an Opacity property that you could set to zero to hide it.
OR
Create a console app instead of a windows app.
Useful? Then click on (Rate This Post) at the top of this post.
-
December 17th, 2004, 07:30 AM
#4
Re: Hide Form
i think u can run u'r program as background thread that;s what u might want
-
December 17th, 2004, 07:58 AM
#5
Re: Hide Form
U can convert windows application this way:
Code:
[STAThread]
static void Main()
{
//Application.Run(new Form1());
//Now do your job :-)
}
-
December 17th, 2004, 09:29 PM
#6
Re: Hide Form
show me the way, how?
only Application.Run(); ??? it won't work for sure.
Norfy What is the Form for if you can't see it?
Form has an Opacity property that you could set to zero to hide it.
OR
Create a console app instead of a windows app.
then it shows the black screen ??
talksandy i think u can run u'r program as background thread that;s what u might want
Yes, i;ve written a windows service to call up the application on an scheduled time, and this application uses a workerthread to read hundreds of files.
However i don't know how to get it to work as the background thread as you said. Do you know where i can find an example for that ??
Thanks.
-
December 17th, 2004, 10:27 PM
#7
Re: Hide Form
You can mimimize the form at startup. Add a NotifyIcon to the form and add the following code to the form's Load event handler.
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
-
December 17th, 2004, 10:38 PM
#8
Re: Hide Form
You need to close the form when you have finished or you can allow the user to double click the notify icon in the system tray to restore the form to normal state.
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
notifyIcon1.Visible = false;
-
December 18th, 2004, 09:21 AM
#9
Re: Hide Form
show me the way, how?
only Application.Run(); ??? it won't work for sure.
Ive already showed it to U.
"There is no spoon"
When U create windows application in c# it looks like this:
Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
///<summary>
/// Summary description for Form1.
///</summary>
publicclass Form1 : System.Windows.Forms.Form
{
///<summary>
/// Required designer variable.
///</summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.Hide();
}
///<summary>
/// Clean up any resources being used.
///</summary>
protectedoverridevoid Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///<summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///</summary>
privatevoid InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
///<summary>
/// The main entry point for the application.
///</summary>
[STAThread]
staticvoid Main()
{
Application.Run(new Form1());
}
}
}
Code begins execution from static function Main()
call to "Application.Run(new Form1());" creates new object of type "Form1" and starts message loop.
So if U modify Main() that way:
Code:
[STAThread]
static void Main()
{
//Application.Run(new Form1());
//Now do your job :-)
}
No window is shown (and no class is created).
Info: // - starts a comment line NO ACTION WAS TAKEN!
But u can do your background task in your Main() function.
Its the same as "Application.ShowMainForm=False;" in delphi
So for example:
Code:
[STAThread]
static void Main()
{
System.Windows.Forms.MessageBox.Show("bbbb");
}
Only the message box is shown.
No black screen no main form ...!
I need to use an API to achieve this
No You dont!
If U desperately need to create windows form (and not show it ) U can do it standard way:
Code:
[STAThread]
static void Main()
{
Form1 frm=new Form1();
}
Than U can do your job in constructor, or U can add public function "public void DoBackgroundJob()" and execute it "frm.DoBackgroundJob()" in main function.
Hope it helps.
-
December 18th, 2004, 01:27 PM
#10
Re: Hide Form
Thanks for your commited help. The problem is no class is created by doing so whereas other classes need to call Delegate functions from the main class.
Anyway, it seems to work ok now by starting a process.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|