⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 panellayoutbuttons.cs

📁 这是用VC编写的一个关于计算器的代码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace ProgramCalculator
{
    /// <summary>
    /// 继承于Panel,用于放置函数按钮的面板
    /// </summary>
    class PanelLayoutButtons:Panel
    {
        private readonly int dxButtonLoc = 6;
        private readonly int dyButtonLoc = 6;
        private readonly int xButtonCount = 4;


        public PanelLayoutButtons()
        {
            this.AutoScroll = true;
        }

        /// <summary>
        /// 添加函数按钮到面板
        /// </summary>
        /// <param name="btn">按钮对象</param>
        public void AddButton(ref Button btn)
        {
            //计算按钮高度与宽度
            btn.Width = (this.Width - (xButtonCount - 1) * dxButtonLoc) / xButtonCount;
            btn.Height = (int)(btn.Width / 2.5);


            //计算按钮位置
            int index = this.Controls.Count;
            int rowLoc = (index) / xButtonCount;
            int columnLoc = index % xButtonCount;
            btn.Location = new System.Drawing.Point(
                columnLoc * (btn.Width + dxButtonLoc), rowLoc * (btn.Height + dyButtonLoc));
         
            if ( !this.Contains(btn) )
            {
                this.Controls.Add(btn);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -