问一下图片上这部分怎么透明, 自绘控件显示下面控件
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);
}
}
