Windows Develop Bookmark and Share   
 index > Windows Forms General > Auto Hide function for Toolstrip control????
 

Auto Hide function for Toolstrip control????

Hi
Is it possible to implement a function like auto hide for toolstrip control like we have in XP???
abhi0410  Tuesday, April 21, 2009 6:13 AM
You can't reduce the height of the ToolStrip, it enforces a minimum height to keep the items visible. One thing you could do is add a Panel and a Timer to the form. Dock the panel to the top and make it a couple of pixel high with a distinctive BackColor. Set the toolstrip's Visible property to False. Set the timer's Interval to 3000 or so. Now you can detect mouse activity in the panel and make the tool strip visible, the timer can hide it again. For example:

private void panel1_MouseMove(object sender, MouseEventArgs e) {
panel1.Visible = false;
toolStrip1.Visible = true;
timer1.Enabled = true;
}

private void toolStrip1_MouseMove(object sender, MouseEventArgs e) {
timer1.Enabled = false;
timer1.Enabled = true;
}

private void timer1_Tick(object sender, EventArgs e) {
timer1.Enabled = false;
toolStrip1.Visible = false;
panel1.Visible = true;
}

Hans Passant.
  • Marked As Answer byabhi0410 Tuesday, April 21, 2009 12:50 PM
  •  
nobugz  Tuesday, April 21, 2009 11:46 AM
Use an user scoped application setting.
Hans Passant.
  • Marked As Answer byabhi0410 Tuesday, April 21, 2009 2:44 PM
  •  
nobugz  Tuesday, April 21, 2009 1:34 PM
Hi,

Well, would not it work by the adding the following code at the completion of your task?

toolStrip1.Visible = false;


Hope, I have understood your requirement correctly.
Regards, Lakra :)
  • Unproposed As Answer byabhi0410 Tuesday, April 21, 2009 11:14 AM
  • Proposed As Answer byAbhijeet Lakra Tuesday, April 21, 2009 6:33 AM
  • Edited byAbhijeet Lakra Tuesday, April 21, 2009 6:36 AMUpdated for readability.
  •  
Abhijeet Lakra  Tuesday, April 21, 2009 6:33 AM
Hi Aby

i mean to auto hide in a sense like how it happens in the XP taskbar....

right click on taskbar and go to property and check the Auto-hide the taskbar..

Then the taskbar automatically hides and when u bring the mouse to the taskbar then it automatically appears...

I hope i am clear now what i am trying to implement...

If possible do help me out.

abhi0410  Tuesday, April 21, 2009 11:14 AM
You can't reduce the height of the ToolStrip, it enforces a minimum height to keep the items visible. One thing you could do is add a Panel and a Timer to the form. Dock the panel to the top and make it a couple of pixel high with a distinctive BackColor. Set the toolstrip's Visible property to False. Set the timer's Interval to 3000 or so. Now you can detect mouse activity in the panel and make the tool strip visible, the timer can hide it again. For example:

private void panel1_MouseMove(object sender, MouseEventArgs e) {
panel1.Visible = false;
toolStrip1.Visible = true;
timer1.Enabled = true;
}

private void toolStrip1_MouseMove(object sender, MouseEventArgs e) {
timer1.Enabled = false;
timer1.Enabled = true;
}

private void timer1_Tick(object sender, EventArgs e) {
timer1.Enabled = false;
toolStrip1.Visible = false;
panel1.Visible = true;
}

Hans Passant.
  • Marked As Answer byabhi0410 Tuesday, April 21, 2009 12:50 PM
  •  
nobugz  Tuesday, April 21, 2009 11:46 AM
hi Nobugz
Thanks..it works great....jus i had to add little more for my requirement.
i am pasting my code here...i would like to know couple of more stuff as i have added context menu to toolstrip1.

private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (toolStripMenuItem1.Checked == true)
            {
                panel1.Visible = false;
                toolStrip1.Visible = true;
                toolStrip1.Dock = DockStyle.Top;
                timer1.Enabled = true;
            }

            else
            {
                panel1.Visible = true;
                toolStrip1.Dock = DockStyle.Top;

                toolStrip1.Visible = true;
            }
        }

        private void toolStrip1_MouseMove(object sender, MouseEventArgs e)
        {
            if (toolStripMenuItem1.Checked == true)
            {
                timer1.Enabled = true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (toolStripMenuItem1.Checked == true)
            {
                timer1.Enabled = false;
                toolStrip1.Visible = false;
                panel1.Visible = true;
            }
            else
            {
                panel1.Visible = true;
                toolStrip1.Dock = DockStyle.Top;

                toolStrip1.Visible = true;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
            panel1.Visible = true;
            toolStrip1.Dock = DockStyle.Top;

            toolStrip1.Visible = true;
        }
Now once user check the in context menu strip then it hides otherwise it is not hidden.

but how to store that checked status in some variable so that when the user closes the form and open again then i could get the checked status????

Is it possible????
abhi0410  Tuesday, April 21, 2009 1:20 PM
Use an user scoped application setting.
Hans Passant.
  • Marked As Answer byabhi0410 Tuesday, April 21, 2009 2:44 PM
  •  
nobugz  Tuesday, April 21, 2009 1:34 PM
Thanks...Its works great... :-)
abhi0410  Tuesday, April 21, 2009 2:44 PM
Try this..., itis the simplest way to make it...

Put a ToolStrip in your Form

Set Properties as follows:

Location = 0,0
LayoutStyle = VerticalStackWithOverflow
Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.ToolStrip1.Width = 5
End Sub
Private Sub ToolStrip1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStrip1.MouseEnter
        Me.ToolStrip1.Width = 32 'Put the original width of the toolstrip
End Sub

Private Sub ToolStrip1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStrip1.MouseLeave
        Me.ToolStrip1.Width = 5
End Sub
alexlt1  Wednesday, May 20, 2009 6:58 PM

You can use google to search for other answers

Custom Search

More Threads

• Window Forms Control Question
• ToolStripManager settings don't work when ToolStripContainer is on a panel
• Saving a form created at run time/Prototype pattern for forms
• App domains Vs Windows Processes....
• Running a webform app from batch command line and disabling form
• Button Control
• unzip & zip w/ SharpZipLib... plus ListBox Q?
• Bug in drawsubitemeventargs.subitem in listview.darwsubitem method when ownerdraw is true
• Combo Box Values
• Different connection string for different configuration