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

📄 qbutton.cs

📁 基于C/S的医疗卫生管理系统
💻 CS
📖 第 1 页 / 共 4 页
字号:
                }
                _radius = _rtemp;
                #endregion

                #region SplitFill
                if (_splitbutton == splitbutton.Yes & mouse)
                {
                    FillSplit(gr);
                }
                #endregion

                #region Shadow
                if (i_mode == 2)
                {
                    rect = new Rectangle(1, 1, this.Width-2, this.Height);
                    pa = new GraphicsPath();
                    DrawShadow(rect, pa);
                    gr.DrawPath(new Pen(Color.FromArgb(50, 20, 20, 20),2.0F), pa);

                }
                else
                {
                    rect = new Rectangle(1, 1, this.Width - 2, this.Height-1);
                    pa = new GraphicsPath();
                    DrawShadow(rect, pa);
                    if (A0 > 80)
                    {
                        gr.DrawPath(new Pen(Color.FromArgb(100, 250, 250, 250), 3.0F), pa);
                    }
                }
                #endregion

                #region SplitLine

                if (_splitbutton == splitbutton.Yes)
                {
                    if (_imagelocation == imagelocation.Top)
                    {
                        switch (i_mode)
                        {
                            case 1:
                                gr.DrawLine(new Pen(_onStroke), new Point(1, this.Height - _splitdistance), new Point(this.Width-1, this.Height - _splitdistance));
                                break;
                            case 2:
                                gr.DrawLine(new Pen(_pressStroke), new Point(1, this.Height - _splitdistance), new Point(this.Width - 1, this.Height -_splitdistance));
                                break;
                            default:
                                break;
                        }
                    }
                    else if (_imagelocation == imagelocation.Left)
                    {
                        switch (i_mode)
                        {
                            case 1:
                                gr.DrawLine(new Pen(_onStroke), new Point(this.Width - _splitdistance, 0), new Point(this.Width - _splitdistance, this.Height));
                                break;
                            case 2:
                                gr.DrawLine(new Pen(_pressStroke), new Point(this.Width - _splitdistance, 0), new Point(this.Width - _splitdistance, this.Height));
                                break;
                            default:
                                break;
                        }     
                    }

                }
                #endregion

                rect = new Rectangle(new Point(0, 0), new Size(this.Width - 1, this.Height - 1));
                pa = new GraphicsPath();
                DrawArc(rect, pa);
                gr.DrawPath(new Pen(_colorStroke, 0.9F), pa);

                pa.Dispose(); lgbrush.Dispose(); 


            }
        }

        int offsetx=0, offsety=0, imageheight=0, imagewidth=0;
        public void DrawImage(Graphics gr)
        {
            if (this.Image != null)
            {
                offsety = _imageoffset; offsetx = _imageoffset;
                if (_imagelocation == imagelocation.Left | _imagelocation == imagelocation.Right)
                {
                    imageheight = this.Height - offsety * 2;
                    if (imageheight > maximagesize.Y & maximagesize.Y!=0)
                    { imageheight = maximagesize.Y; }
                    imagewidth = (int)((Convert.ToDouble(imageheight) / this.Image.Height) * this.Image.Width);
                }
                else if (_imagelocation == imagelocation.Top | _imagelocation == imagelocation.Bottom)
                {
                    imagewidth = this.Width - offsetx * 2;
                    if (imagewidth > maximagesize.X & maximagesize.X != 0)
                    { imagewidth = maximagesize.X; }
                    imageheight = (int)((Convert.ToDouble(imagewidth) / this.Image.Width) * this.Image.Height);
                    
                }
                switch (_imagelocation)
                {
                    case imagelocation.Left:
                        offsety = (this.Height - imageheight) / 2;
                        gr.DrawImage(this.Image, new Rectangle(offsetx, offsety, imagewidth, imageheight));
                        break;
                    case imagelocation.Right:
                        gr.DrawImage(this.Image, new Rectangle(this.Width - imagewidth - offsetx, offsety, imagewidth, imageheight));
                        break;
                    case imagelocation.Top:
                        offsetx = this.Width / 2 - imagewidth / 2;
                        gr.DrawImage(this.Image, new Rectangle(offsetx, offsety, imagewidth, imageheight));
                        break;
                    case imagelocation.Bottom:
                        gr.DrawImage(this.Image, new Rectangle(offsetx, this.Height - imageheight - offsety, imagewidth, imageheight));
                        break;
                    default:
                        break;
                }
            }
        }

        public void DrawString(Graphics gr)
        {
            if (this.Text != "")
            {
                int textwidth = (int) gr.MeasureString(this.Text,this.Font).Width;
                int textheight = (int) gr.MeasureString(this.Text,this.Font).Height;

                int extraoffset = 0;
                Font fontb = new Font(this.Font,FontStyle.Bold);
                if (_title != "")
                {
                    extraoffset = textheight/2;
                }

                string s1= this.Text; string s2="";
                int jump = this.Text.IndexOf("\\n");
                
                if (jump != -1)
                {
                    s2 = s1.Substring(jump+3); s1 = s1.Substring(0, jump);
                }

                #region Calc Color Brightness
                RibbonColor __color = new RibbonColor(Color.FromArgb(R0, G0, B0));
                RibbonColor forecolor = new RibbonColor(this.ForeColor);
                Color _forecolor;

                if (__color.GetBrightness() > 50)
                {
                    forecolor.BC = 1;
                    forecolor.SC = 80;
                }
                else
                {
                    forecolor.BC = 99;
                    forecolor.SC = 20;
                }
                _forecolor = forecolor.GetColor();
                #endregion
                if (!this.Enabled)
                {
                    _forecolor = Color.Silver;
                }

                int arrowWidthSpace = 0;
                if (_arrow != arrow.None)
                {
                    arrowWidthSpace = 1;
                }

                switch (_imagelocation)
                {
                    case imagelocation.Left:
                        if (this.Title != "")
                        {
                            gr.DrawString(this.Title, fontb, new SolidBrush(_forecolor), new PointF(offsetx + imagewidth + 4, this.Font.Size / 2));
                            gr.DrawString(s1, this.Font, new SolidBrush(_forecolor), new PointF(offsetx + imagewidth + 4, 2 * this.Font.Size + 1));
                            gr.DrawString(s2, this.Font, new SolidBrush(_forecolor), new PointF(offsetx + imagewidth + 4, 3 * this.Font.Size + 4));
                        }
                        else
                        {
                            gr.DrawString(s1, this.Font, new SolidBrush(_forecolor), new PointF(offsetx + imagewidth + 4, this.Height / 2 - this.Font.Size + 1));
                        }

                        break;
                    case imagelocation.Right:
                        gr.DrawString(this.Title, fontb, new SolidBrush(_forecolor), new PointF(offsetx, this.Height / 2 - this.Font.Size + 1 - extraoffset));
                        gr.DrawString(this.Text, this.Font, new SolidBrush(_forecolor), new PointF(offsetx, extraoffset + this.Height / 2 - this.Font.Size + 1));
                        break;
                    case imagelocation.Top:
                        gr.DrawString(this.Text, this.Font, new SolidBrush(_forecolor), new PointF(this.Width / 2 - textwidth / 2 - arrowWidthSpace, offsety + imageheight));
                        break;
                    case imagelocation.Bottom:
                        gr.DrawString(this.Text, this.Font, new SolidBrush(_forecolor), new PointF(this.Width / 2 - textwidth / 2 - arrowWidthSpace, this.Height - imageheight - textheight - arrowWidthSpace));
                        break;
                    default:
                        gr.DrawString(this.Text, this.Font, new SolidBrush(_forecolor), new PointF(this.Width / 2 - textwidth / 2 - arrowWidthSpace, this.Height / 2 - textheight / 2 + 2));
                        break;
                }

                fontb.Dispose();
                
            }
        }

        public void DrawArc(Rectangle re,GraphicsPath pa)
        {
            int _radiusX0Y0 = _radius, _radiusXFY0 = _radius, _radiusX0YF = _radius, _radiusXFYF = _radius;
            switch (_grouppos)
            {
                case groupPos.Left:
                    _radiusXFY0 = 1; _radiusXFYF = 1;
                break;
                case groupPos.Center:
                _radiusX0Y0 = 1; _radiusX0YF = 1; _radiusXFY0 = 1; _radiusXFYF = 1;
                break;
                case groupPos.Right:
                _radiusX0Y0 = 1; _radiusX0YF = 1;
                break;
                case groupPos.Top:
                _radiusX0YF = 1; _radiusXFYF = 1;
                break;
                case groupPos.Bottom:
                _radiusX0Y0 = 1; _radiusXFY0 = 1;
                break;
            }
            pa.AddArc(re.X, re.Y, _radiusX0Y0, _radiusX0Y0, 180, 90);
            pa.AddArc(re.Width - _radiusXFY0, re.Y, _radiusXFY0, _radiusXFY0, 270, 90);
            pa.AddArc(re.Width - _radiusXFYF, re.Height - _radiusXFYF, _radiusXFYF, _radiusXFYF, 0, 90);
            pa.AddArc(re.X, re.Height - _radiusX0YF, _radiusX0YF, _radiusX0YF, 90, 90);
            pa.CloseFigure();

        }

        public void DrawShadow(Rectangle re, GraphicsPath pa)
        {
            int _radiusX0Y0 = _radius, _radiusXFY0 = _radius, _radiusX0YF = _radius, _radiusXFYF = _radius;
            switch (_grouppos)
            {
                case groupPos.Left:
                    _radiusXFY0 = 1; _radiusXFYF = 1;
                    break;
                case groupPos.Center:
                    _radiusX0Y0 = 1; _radiusX0YF = 1; _radiusXFY0 = 1; _radiusXFYF = 1;
                    break;
                case groupPos.Right:
                    _radiusX0Y0 = 1; _radiusX0YF = 1;
                    break;
                case groupPos.Top:
                    _radiusX0YF = 1; _radiusXFYF = 1;
                    break;
                case groupPos.Bottom:
                    _radiusX0Y0 = 1; _radiusXFY0 = 1;
                    break;
            }
            pa.AddArc(re.X, re.Y, _radiusX0Y0, _radiusX0Y0, 180, 90);
            pa.AddArc(re.Width - _radiusXFY0, re.Y, _radiusXFY0, _radiusXFY0, 270, 90);
            pa.AddArc(re.Width - _radiusXFYF, re.Height - _radiusXFYF, _radiusXFYF, _radiusXFYF, 0, 90);
            pa.AddArc(re.X, re.Height - _radiusX0YF, _radiusX0YF, _radiusX0YF, 90, 90);
            pa.CloseFigure();

        }

        public void DrawArrow(Graphics gr)
        {
            int _size = 1;

            RibbonColor __color = new RibbonColor(Color.FromArgb(R0, G0, B0));
            RibbonColor forecolor = new RibbonColor(this.ForeColor);
            Color _forecolor;

            if (__color.GetBrightness() > 50)
            {
                forecolor.BC = 1;
                forecolor.SC = 80;
            }
            else
            {
                forecolor.BC = 99;
                forecolor.SC = 20;
            }
            _forecolor = forecolor.GetColor();
            
            switch (_arrow)
            {
                case arrow.ToDown:
                    if (_imagelocation == imagelocation.Left || _imagelocation == imagelocation.None)
                    {
                        Point[] points = new Point[3];
                        points[0] = new Point(this.Width - 8 * _size - _imageoffset, this.Height / 2 - _size / 2);
                        points[1] = new Point(this.Width - 2 * _size - _imageoffset, this.Height / 2 - _size / 2);
                        points[2] = new Point(this.Width - 5 * _size - _imageoffset, this.Height / 2 + _size * 2);
                        gr.FillPolygon(new SolidBrush(_forecolor), points);
                    }
                    else if (_imagelocation == imagelocation.Top)
                    {
                        Point[] points = new Point[3];
                        points[0] = new Point(this.Width/2 + 8 * _size - _imageoffset, this.Height - _imageoffset - 5*_size );
                        points[1] = new Point(this.Width/2 + 2 * _size - _imageoffset, this.Height - _imageoffset - 5* _size );
                        points[2] = new Point(this.Width/2 + 5 * _size - _imageoffset, this.Height - _imageoffset - 2*_size);
                        gr.FillPolygon(new SolidBrush(_forecolor), points);
                    }
                    break;
                case arrow.ToRight:
                    if (_imagelocation == imagelocation.Left)
                    {
                        int arrowxpos = this.Width - _splitdistance + 2*_imageoffset;
                        Point[] points = new Point[3];
                        points[0] = new Point(arrowxpos + 4, this.Height / 2 - 4 * _size);
                        points[1] = new Point(arrowxpos + 8, this.Height / 2);
                        points[2] = new Point(arrowxpos + 4, this.Height / 2 + 4 * _size);
                        gr.FillPolygon(new SolidBrush(_forecolor), points);
                    }
                    break;
                default:
                    break;
            }
            
        }

        public void FillSplit(Graphics gr)
        {
            Color _tranp = Color.FromArgb(200, 255, 255, 255);
            int x1 = this.Width - _splitdistance; int x2 = 0;
            int y1 = this.Height - _splitdistance; int y2=0;
            SolidBrush btransp = new SolidBrush(_tranp);
            #region Horizontal
            if (_imagelocation == imagelocation.Left)
            {
                    if (xmouse < this.Width - _splitdistance & mouse) //Small button
                    {
                        Rectangle _r = new Rectangle(x1 + 1, 1, this.Width - 2, this.Height - 1);
                        GraphicsPath p = new GraphicsPath();
                        int _rtemp = _radius; _radius = 4;
                        DrawArc(_r, p);
                        _radius = _rtemp;
                        gr.FillPath(btransp, p);
                        

⌨️ 快捷键说明

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