CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Hide Form

  1. #1
    Join Date
    Dec 2004
    Posts
    16

    Unhappy 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.

  2. #2
    Join Date
    Dec 2004
    Posts
    16

    Re: Hide Form

    I think i might need to use an API to achieve this, but dont' know what function to look at

  3. #3
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    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.

  4. #4
    Join Date
    Nov 2004
    Location
    India
    Posts
    63

    Re: Hide Form

    i think u can run u'r program as background thread that;s what u might want

  5. #5
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: Hide Form

    U can convert windows application this way:
    Code:
     [STAThread] 
    static void Main() 
    
    {
    
    //Application.Run(new Form1());
    //Now do your job :-)
    }

  6. #6
    Join Date
    Dec 2004
    Posts
    16

    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.

  7. #7
    Join Date
    Aug 2002
    Location
    Kerala
    Posts
    1,183

    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;

  8. #8
    Join Date
    Aug 2002
    Location
    Kerala
    Posts
    1,183

    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;

  9. #9
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    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.

  10. #10
    Join Date
    Dec 2004
    Posts
    16

    Arrow 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
  •  





Click Here to Expand Forum to Full Width

Featured