最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實現滑動開關效果

 更新時間:2021年07月26日 11:08:10   作者:qq53716684  
這篇文章主要為大家詳細介紹了C#實現滑動開關效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

C#重繪checkbox生成滑動開關,供大家參考,具體內容如下

通過調用checkbox控件的paint事件,在重繪事件里判斷checked屬性,如果選中繪制選中圖形,如果未選中繪制未選中圖形。

效果圖:

繪制圓角矩形方法:

 /// <summary>
        /// 填充圓角矩形
        /// </summary>
        /// <param name="g"></param>
        /// <param name="brush"></param>
        /// <param name="rect"></param>
        /// <param name="cornerRadius"></param>
        public static void FillRoundRectangle(Graphics g, Brush brush, Rectangle rect, int cornerRadius)
        {
            using (GraphicsPath path = CreateRoundedRectanglePath(rect, cornerRadius))
            {
                g.FillPath(brush, path);
            }
        }
        /// <summary>
        /// 圓角矩形路徑
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="cornerRadius"></param>
        /// <returns></returns>
        internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
        {
            GraphicsPath roundedRect = new GraphicsPath();
            roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
            roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
            roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
            roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
            roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
            roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
            roundedRect.CloseFigure();
            return roundedRect;
        }

重繪代碼:

private void RectangleCheckBoxButton(object sender, PaintEventArgs e)
{
            CheckBox rButton = (CheckBox)sender;
            Graphics g = e.Graphics;
            g.Clear(this.BackColor);

            Rectangle RoundRect = new Rectangle(0, 0, 50, 30);            
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //FillRoundRectangle(g, Brushes.White, radioButtonrect, 15);
            

            if (rButton.Checked)
            {
 
                Color color =Color.FromArgb( 55, 197, 90);
                Brush b1 = new SolidBrush(color);
                FillRoundRectangle(g, b1, RoundRect, 15);
                
                using (Pen pen = new Pen(Color.FromArgb(255, 255, 255)))
                {             
                    FillRoundRectangle(g, Brushes.White, new Rectangle(22, 2,26, 26), 13);
                }
            }
            else
            {
                using (Pen pen = new Pen(Color.FromArgb(255, 255, 255)))
                {
                    FillRoundRectangle(g, Brushes.Silver,  RoundRect, 15);
                    FillRoundRectangle(g,Brushes.White, new Rectangle(2, 2, 26, 26), 13);
                    
                }
            }
            Font f = new Font("微軟雅黑", 12);
            g.DrawString(((CheckBox)sender).Text,f ,  Brushes.White, new PointF(60, 6));
}

調用:

private void checkBox1_Paint(object sender, PaintEventArgs e)
{
 RectangleCheckBoxButton(sender, e);
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

天全县| 宾阳县| 阿拉善盟| 哈巴河县| 翁源县| 涪陵区| 贺州市| 阿尔山市| 益阳市| 轮台县| 英山县| 平原县| 赤峰市| 泰安市| 茶陵县| 高陵县| 玉门市| 英吉沙县| 拉萨市| 友谊县| 漯河市| 垦利县| 临泉县| 汤原县| 怀柔区| 陕西省| 龙江县| 阿鲁科尔沁旗| 奉节县| 思南县| 长泰县| 志丹县| 岳普湖县| 合肥市| 兴仁县| 呼玛县| 海盐县| 夹江县| 临猗县| 个旧市| 德令哈市|