DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Changing the text of Main Form title at runtime

  1. #1
    Join Date
    Sep 2005

    Changing the text of Main Form title at runtime

    Hi All,

    I would like to change the text appearing in the title (main bar at the top of the window) of the main form in a C# windows app at runtime.

    However, to change any property of a form at runtime, it appears the form needs to be an instance of the form, rather than the form itself. For all forms other than the main, this will usually be the case, however it appears that the main form cannot be instantiated at startup.

    Is there any way around this?

    Many thanks,
    Steve Krenek

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    In .NET, all forms are instances. Somewhere in your project, you have a Main method that looks like this:
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main() 
        Application.Run(new Form1());
    That code creates an instance of Form1 and passes it to the Application.Run method. If you want to change the form's title before passing it to Application.Run, you can do this instead:
    static void Main() 
        Form1 frmMain = new Form1;
        frmMain.Text = "Title bar text";
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Nov 2003
    Alameda, CA
    Inside the form itself you can change its title using the this keyword:

    this.Text = "This is my new title"

    From another class, you have to pass its instance like Phil suggested. If the class is created within the form itself, again you can pass the this keyword

    "There are two ways to write error-free programs. Only the third one works."

  4. #4
    Join Date
    Sep 2005
    Thanks, Phil, this has been very helpful in getting my mental picture of instances of forms etc clearer.

    However, my requirement was to change the title text *after* the program had started (ie in response to something happening during execution).

    I now find that I can do this using

    this.Text = "new title text";

    at any point in the code.


  5. #5
    Join Date
    Dec 2009

    related question - title in form during runtime

    hey Steve,

    interested in the same issue - used the "this.Text" command but doesn't do anything for me - in fact it, the program essentially stops processing anything after that command and just sits waiting on input from the form, which works.

    did you have any other problems? or was it just that easy?

    running VS 2008 and C#/C++


  6. #6
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Post the code that you are using that isn't working for you.

Similar Threads

  1. Replies: 3
    Last Post: 08-09-2005, 12:59 PM
  2. Replies: 0
    Last Post: 03-17-2005, 12:47 PM
  3. Move Form without title bar
    By Jonas in forum .NET
    Replies: 2
    Last Post: 11-12-2001, 10:46 AM
  4. Top fixed screen
    By Cheng in forum Web
    Replies: 1
    Last Post: 11-06-2001, 10:43 AM
  5. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center