c# 自定义透明控件实现透明遮罩效果
By
admin
at 2025-01-15 • 0人收藏 • 413人看过
winfrom中有个picturebox 里面显示一个动态图片(或者是嵌入了一个摄像头控件) , 为了防止这个图片(或摄像头)被鼠标交互事件影响, 需要在其上覆盖一个遮罩, 阻止鼠标消息给它
新建类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
namespace demo
{
public partial class Zhezhao : Panel
{
protected Graphics graphics;
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; // 实现透明样式
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
}
protected override void OnPaint(PaintEventArgs e)
{
}
}
}编译后, vs2022工具栏就会多出一个zhezhao的控件, 把这个拖放进winform中即可.
1 个回复 | 最后更新于 2025-02-10
登录后方可回帖
还是wpf方便一点