请教, GDI+自绘控件实现这个透明

.Net技术 码拜 7年前 (2017-04-24) 1221次浏览
问一下图片上这部分怎么透明, 自绘控件显示下面控件
请教, GDI+自绘控件实现这个透明

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            myButton1.BackColor = Color.Transparent;
            myButton1.Parent = this;
        }
    }
    class MyButton : Button
    {
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);
            //base.OnPaint(pevent);
            pevent.Graphics.FillEllipse(Brushes.Yellow, 0, 0, this.Width, this.Height);
        }
    }
}
解决方案

40

        protected override void OnPaint(PaintEventArgs pevent)
        {
            using (var p = new GraphicsPath())
            {
                p.AddEllipse(new Rectangle(0, 0, Width, Height));
                Region = new Region(p);
                pevent.Graphics.Clear(Color.Yellow);
            }
        }

请教, GDI+自绘控件实现这个透明


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明请教, GDI+自绘控件实现这个透明
喜欢 (0)
[1034331897@qq.com]
分享 (0)