Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Why doesnt this work

Why doesnt this work

Scheduled Pinned Locked Moved C#
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Esmo2000
    wrote on last edited by
    #1

    I have a Windows application and I was doing something that I thought to be very simple. The ONLY change that I made was: /// The main entry point for the application. /// [STAThread] static void Main() { Form1 someForm = new Form1(); someForm.Visible = false; Application.Run(someForm); } This didnt work. I dont know what I am doing wrong; I would have thought that that was a pretty good way to make it invisble but Im wrong. Thx, Jim

    T M M 3 Replies Last reply
    0
    • E Esmo2000

      I have a Windows application and I was doing something that I thought to be very simple. The ONLY change that I made was: /// The main entry point for the application. /// [STAThread] static void Main() { Form1 someForm = new Form1(); someForm.Visible = false; Application.Run(someForm); } This didnt work. I dont know what I am doing wrong; I would have thought that that was a pretty good way to make it invisble but Im wrong. Thx, Jim

      T Offline
      T Offline
      tdciDoug
      wrote on last edited by
      #2

      You need to make changes to your form in your onload or constructor...not in the Main. Have a wonderful evening Doug Wright Developer, TDCI

      E 1 Reply Last reply
      0
      • T tdciDoug

        You need to make changes to your form in your onload or constructor...not in the Main. Have a wonderful evening Doug Wright Developer, TDCI

        E Offline
        E Offline
        Esmo2000
        wrote on last edited by
        #3

        Thanks a lot, but sadly I tried that too with no result :( More exactly, this was the code that I used: public Form1() { this.Visible = false; InitializeComponent(); } I also tried public Form1() { InitializeComponent(); this.Visible = false; }

        C 1 Reply Last reply
        0
        • E Esmo2000

          I have a Windows application and I was doing something that I thought to be very simple. The ONLY change that I made was: /// The main entry point for the application. /// [STAThread] static void Main() { Form1 someForm = new Form1(); someForm.Visible = false; Application.Run(someForm); } This didnt work. I dont know what I am doing wrong; I would have thought that that was a pretty good way to make it invisble but Im wrong. Thx, Jim

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          Application.Run(Form f) sets the form's Visible attribute to True internally when it's starting the message loop for the form, so your form gets displayed regardless of what you set Visible to. To hide the form from the user you can either set its size to (0,0) or move the form off-screen (or both). Regards, mav

          E 1 Reply Last reply
          0
          • M mav northwind

            Application.Run(Form f) sets the form's Visible attribute to True internally when it's starting the message loop for the form, so your form gets displayed regardless of what you set Visible to. To hide the form from the user you can either set its size to (0,0) or move the form off-screen (or both). Regards, mav

            E Offline
            E Offline
            Esmo2000
            wrote on last edited by
            #5

            Thanks, I didnt know about that side effect! This program is going to be run as a scheduled task, how do I go about stopping it from stealing focus? Thanks a lot, Jim

            M 1 Reply Last reply
            0
            • E Esmo2000

              Thanks a lot, but sadly I tried that too with no result :( More exactly, this was the code that I used: public Form1() { this.Visible = false; InitializeComponent(); } I also tried public Form1() { InitializeComponent(); this.Visible = false; }

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              What about the Form's Load method? That was the other suggestion, did you try that?


              My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

              1 Reply Last reply
              0
              • E Esmo2000

                Thanks, I didnt know about that side effect! This program is going to be run as a scheduled task, how do I go about stopping it from stealing focus? Thanks a lot, Jim

                M Offline
                M Offline
                mav northwind
                wrote on last edited by
                #7

                You don't have to show a form for your program to run and perform its tasks. Take a look at the other Application.Run() overloads, that could be the cleaner solution. Otherwise you'd have to p/invoke ShowWindow(), there you can specify to show a window without giving it focus. Regards, mav

                T 1 Reply Last reply
                0
                • M mav northwind

                  You don't have to show a form for your program to run and perform its tasks. Take a look at the other Application.Run() overloads, that could be the cleaner solution. Otherwise you'd have to p/invoke ShowWindow(), there you can specify to show a window without giving it focus. Regards, mav

                  T Offline
                  T Offline
                  tdciDoug
                  wrote on last edited by
                  #8

                  Good post, I tested this out after posting to him earlier and saw that my suggestion wouldn't help. I was curious as to why it wouldn't hide as well. Have a wonderful evening Doug Wright Developer, TDCI

                  1 Reply Last reply
                  0
                  • E Esmo2000

                    I have a Windows application and I was doing something that I thought to be very simple. The ONLY change that I made was: /// The main entry point for the application. /// [STAThread] static void Main() { Form1 someForm = new Form1(); someForm.Visible = false; Application.Run(someForm); } This didnt work. I dont know what I am doing wrong; I would have thought that that was a pretty good way to make it invisble but Im wrong. Thx, Jim

                    M Offline
                    M Offline
                    MoustafaS
                    wrote on last edited by
                    #9

                    why don't u try the this.Hide() in the load constructor ByMindOnlyYouCanDoIt

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups