winform Panel display position setting button

  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;        // move the position of the form, create a new point 

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

        Private  void the button1_Click ( Object SENDER, EventArgs E) 
        { 
            MovePanelSid (btnHome); 
        } 

        Private  void the 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 (); 
                } 
            } 
            the else 
            { 
                panelLeft.Width = panelLeft.Width - 20 is ;
                 IF (panelLeft.Width <= 59 ) 
                { 
                    timer1.Stop (); 
                    isCollapsed = to true ;
                     the this .Refresh (); 
                } 
            } 
        } 

        Private  void btnList_Click ( Object SENDER, EventArgs E)   // start the timer display only the button icons 
        { 
            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); 
            }
        } 

    } 
}

 

Guess you like

Origin www.cnblogs.com/yunchen/p/12552785.html