110,538
社区成员
发帖
与我相关
我的任务
分享
public Form1()
{
InitializeComponent();
pictureBox1.Load("1.jpg");
using (var p = new GraphicsPath())
{
p.AddString("方案二", new FontFamily("方正琥珀简体"), 1, 32, Point.Empty, new StringFormat());
panel1.Region = new Region(p);
}
drawPictureBox.BackColor = Color.Transparent;
textPictureBox.BackColor = Color.Transparent;
bottomPictureBox.BackColor = Color.Transparent;
textPictureBox.Parent = bottomPictureBox;
drawPictureBox.Parent = textPictureBox;
现在要实现拖动bottomPictureBox时上面两层不动。private Region GetRegion(Bitmap bmp)
{
Region res = new Region();
res.MakeEmpty();
var colorTransparent = bmp.GetPixel(0, 0);
var a = Enumerable.Range(0, bmp.Width).ToList();
var b = Enumerable.Range(0, bmp.Height).ToList();
var q = from x in a
from y in b
where bmp.GetPixel(x, y) != colorTransparent
select new Rectangle(x, y, 1, 1);
foreach (var r in q) res.Union(r);
return res;
}
bottomPictureBox.Region = GetRegion(new Bitmap(bottomPictureBox.Image));