Winform中实现仿XP系统的任务栏菜单效果(附代码下载)

场景

效果

Winform中实现仿XP系统的任务栏菜单效果(附代码下载)

注:

博客主页:
https://blog.csdn.net/badao_liumang_qizhi

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

新建一个Form窗体,设计页面布局如下

Winform中实现仿XP系统的任务栏菜单效果(附代码下载)

折叠效果的向上和向下按钮是PictureBox,从上往下依次的Tag标签为1,2,3

三个PictureBox都绑定同一个点击事件,在点击事件中根据传递的Tag标签的值在Switch-case中进行处理。

在Switch-case中分别将对应的一组PictureBox和Panel对象赋值给上面声明的静态的两个控件对象。

下面要隐藏的Panel对象的tag属性默认为0,在上面switch-case中获取一组对应的控件对象后进行判断,

如果Tag为0或者2则是将Panel隐藏,同时将Tag标签设置为1,表示隐藏。

如果是1,则表示已经处于隐藏状态,则会将其显示并将Tag设置为2。

关键代码

private static Panel Var_Panel = new Panel();
private static PictureBox Var_Pict = new PictureBox();
private static int Var_i = ;
private Font Var_Font = new Font("宋体", ); private void pictureBox_1_Click(object sender, EventArgs e)
{
Var_i = Convert.ToInt16(((PictureBox)sender).Tag.ToString());
switch (Var_i)
{
case :
{
Var_Panel = panel_Gut_1;
Var_Pict = pictureBox_1;
break;
}
case :
{
Var_Panel = panel_Gut_2;
Var_Pict = pictureBox_2;
break;
}
case :
{
Var_Panel = panel_Gut_3;
Var_Pict = pictureBox_3;
break;
} }
if (Convert.ToInt16(Var_Panel.Tag.ToString()) == || Convert.ToInt16(Var_Panel.Tag.ToString()) == )
{
Var_Panel.Tag = ;//隐藏标识
Var_Pict.Image = null;
Var_Pict.Image = Properties.Resources.朝下按钮;
Var_Panel.Visible = false;
}
else
{
if (Convert.ToInt16(Var_Panel.Tag.ToString()) == )
{
Var_Panel.Tag = ;//显示标识
Var_Pict.Image = null;
Var_Pict.Image = Properties.Resources.朝上按钮;
Var_Panel.Visible = true;
}
}
} private void Form1_Load(object sender, EventArgs e)
{
pictureBox_1.Image = null;
pictureBox_1.Image = Properties.Resources.朝上按钮;
pictureBox_2.Image = null;
pictureBox_2.Image = Properties.Resources.朝上按钮;
pictureBox_3.Image = null;
pictureBox_3.Image = Properties.Resources.朝上按钮;
Var_Font = label_1.Font;
} private void label_1_MouseEnter(object sender, EventArgs e)
{
((Label)sender).ForeColor = Color.Gray;
((Label)sender).Font = new Font(Var_Font, Var_Font.Style | FontStyle.Underline);
} private void label_1_MouseLeave(object sender, EventArgs e)
{
((Label)sender).ForeColor = Color.Black;
((Label)sender).Font = new Font(Var_Font, Var_Font.Style);
}

代码下载

https://download.csdn.net/download/BADAO_LIUMANG_QIZHI/12025648

上一篇:后端程序员之路 31、Protocol Buffer


下一篇:Corba、protocol buffer、SOA的区别 (转)