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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Minimize to tray bar [modified]

Minimize to tray bar [modified]

Scheduled Pinned Locked Moved C#
windows-adminhelpquestion
4 Posts 2 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.
  • R Offline
    R Offline
    Ronni Marker
    wrote on last edited by
    #1

    Hi all, writing a small app that reads a registry setting and based on the content on that, should either show the form or hide it in the tray bar.

            RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\\\Policies\\\\OTM");
            if (masterKey != null)
            {
                if (masterKey.GetValue("Serial").ToString().Length == 36)
                {
                    textBox1.Text = masterKey.GetValue("Serial").ToString();
                    textBox1.Enabled = false;
                    this.Hide();
                }
                else
                {
                    textBox1.Enabled = true;
                    this.StartPosition = FormStartPosition.CenterScreen;
                    this.WindowState = FormWindowState.Normal;
                    this.Show();
                }
            }
    

    unfortunately the window always stays open. Anyone who have a quick tip to what Im missing? I tried to include this.WindowState = FormWindowState.Minimized;, but that just minimized to app, but didnt hide it in the tray bar. - sorry writing error here. Meant didnt hide the form at all. At best it gets to be minimized in the lower left corner.

    modified on Friday, November 6, 2009 4:27 AM

    L 1 Reply Last reply
    0
    • R Ronni Marker

      Hi all, writing a small app that reads a registry setting and based on the content on that, should either show the form or hide it in the tray bar.

              RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\\\Policies\\\\OTM");
              if (masterKey != null)
              {
                  if (masterKey.GetValue("Serial").ToString().Length == 36)
                  {
                      textBox1.Text = masterKey.GetValue("Serial").ToString();
                      textBox1.Enabled = false;
                      this.Hide();
                  }
                  else
                  {
                      textBox1.Enabled = true;
                      this.StartPosition = FormStartPosition.CenterScreen;
                      this.WindowState = FormWindowState.Normal;
                      this.Show();
                  }
              }
      

      unfortunately the window always stays open. Anyone who have a quick tip to what Im missing? I tried to include this.WindowState = FormWindowState.Minimized;, but that just minimized to app, but didnt hide it in the tray bar. - sorry writing error here. Meant didnt hide the form at all. At best it gets to be minimized in the lower left corner.

      modified on Friday, November 6, 2009 4:27 AM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      How about set ShowInTaskbar = false ?

      R 1 Reply Last reply
      0
      • L Lost User

        How about set ShowInTaskbar = false ?

        R Offline
        R Offline
        Ronni Marker
        wrote on last edited by
        #3

        sorry i didnt mean the tray bay, but it is shown minimized in the left corner just above the traybar ifi i force the app to start minimized. ShowInTaskbar is already set to false.

        R 1 Reply Last reply
        0
        • R Ronni Marker

          sorry i didnt mean the tray bay, but it is shown minimized in the left corner just above the traybar ifi i force the app to start minimized. ShowInTaskbar is already set to false.

          R Offline
          R Offline
          Ronni Marker
          wrote on last edited by
          #4

          Did a small change

                  RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\\\Policies\\\\OTM");
                  if (masterKey != null)
                  {
                      if (masterKey.GetValue("Serial").ToString().Length == 36)
                      {
                          textBox1.Text = masterKey.GetValue("Serial").ToString();
                          textBox1.Enabled = false;
                          **this.WindowState = FormWindowState.Minimized;**
                          this.Hide();
                      }
                      else
                      {
                          textBox1.Enabled = true;
                          this.StartPosition = FormStartPosition.CenterScreen;
                          this.WindowState = FormWindowState.Normal;
                          this.Show();
                      }
                  }
          

          plus included this:

              private void Form1\_Resize(object sender, EventArgs e)
              {
                  if (WindowState == FormWindowState.Minimized)
                  {
                      Hide();
                  }
              }
          

          It is far from beautiful but it works for now...

          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