winform Panel设定 按钮显示位置

  private void MovePanelSid(Control btn)
        {
            panelside.Top = btn.Top;
            panelside.Height = btn.Height;
        }

   private void button1_Click(object sender, EventArgs e)
        {
            MovePanelSid(btnHome);
        }

 private void button2_Click(object sender, EventArgs e)
        {
            MovePanelSid(btnBOOK);
        }

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BookManager
{
    public partial class Form2 : Form
    {
        int PanelWidth;
        bool isCollapsed;

        public Form2()
        {
            InitializeComponent();
            PanelWidth = panelLeft.Width;
        }

        private Point mpoint;       //移动窗体位置,创建新的点

        private void MovePanelSid(Control btn)
        {
            panelside.Top = btn.Top;
            panelside.Height = btn.Height;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MovePanelSid(btnHome);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MovePanelSid(btnBOOK);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void timer1_Tick(object sender, EventArgs e)    //定时器控制Button显示图标
        {
            if (isCollapsed)
            {
                panelLeft.Width = panelLeft.Width + 20;
                if (panelLeft.Width >= PanelWidth)
                {
                    timer1.Stop();
                    isCollapsed = false;
                    this.Refresh();
                }
            }
            else
            {
                panelLeft.Width = panelLeft.Width - 20;
                if (panelLeft.Width <= 59)
                {
                    timer1.Stop();
                    isCollapsed = true;
                    this.Refresh();
                }
            }
        }

        private void btnList_Click(object sender, EventArgs e)  //启动定时器只显示按钮图标
        {
            timer1.Start();         
        }

        private void panel2_MouseDown(object sender, MouseEventArgs e)  //移动窗体位置
        {
            mpoint = new Point(e.X, e.Y);
        }

        private void panel2_MouseMove(object sender, MouseEventArgs e)    //移动窗体位置
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X + e.X - mpoint.X, this.Location.Y + e.Y - mpoint.Y);
            }
        }

    }
}

猜你喜欢

转载自www.cnblogs.com/yunchen/p/12552785.html