zoukankan      html  css  js  c++  java
  • 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);
                }
            }
    
        }
    }

    本文来自博客园,作者:云辰,转载请注明原文链接:https://www.cnblogs.com/yunchen/p/12552785.html

  • 相关阅读:
    HANDLE CreateThread()
    偷懒的一天-jQuery之事件与应用
    web进阶之jQuery操作DOM元素&&MySQL记录操作&&PHP面向对象学习笔记
    无聊的周五晚上
    闲里偷闲
    被蚊子和自己搞毁的一天
    数据库有点意思
    周一周一周。。一
    无聊到周六的教研室
    1.Nginx相关概念
  • 原文地址:https://www.cnblogs.com/yunchen/p/12552785.html
Copyright © 2011-2022 走看看