2
我一直在试图模仿Windows 7的截屏工具,它是如何将半透明灰色图层叠加在屏幕上的,该图层在选择区域内变得完全透明。我走得很近。我正在显示覆盖整个屏幕的无边界50%不透明灰色窗体,并且具有紫红色的TransparencyKey。然后在那个表格的顶部画两个矩形。用于透明的固体紫红色矩形和用于红色边框的另一个矩形。它有效,但前提是我做了三件事中的一件,其中没有一件是选择。C#透明实心矩形以50%不透明的形式绘制
- 禁止双缓冲,这使得形式闪烁同时提请
- 更改桌面颜色模式从32位
- 到16bit的制作形式100%不透明
这里是我的代码。任何有关如何使这项工作的建议?
public partial class frmBackground : Form
{
Rectangle rect;
public frmBackground()
{
InitializeComponent();
this.MouseDown += new MouseEventHandler(frmBackground_MouseDown);
this.MouseMove += new MouseEventHandler(frmBackground_MouseMove);
this.Paint += new PaintEventHandler(frmBackground_Paint);
this.DoubleBuffered = true;
this.Cursor = Cursors.Cross;
}
private void frmBackground_MouseDown(object sender, MouseEventArgs e)
{
Bitmap backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
rect = new Rectangle(e.X, e.Y, 0, 0);
this.Invalidate();
}
private void frmBackground_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
rect = new Rectangle(rect.Left, rect.Top, e.X - rect.Left, e.Y - rect.Top);
this.Invalidate();
}
private void frmBackground_Paint(object sender, PaintEventArgs e)
{
Pen pen = new Pen(Color.Red, 3);
e.Graphics.DrawRectangle(pen, rect);
SolidBrush brush = new SolidBrush(Color.Fuchsia);
e.Graphics.FillRectangle(brush, rect);
}
}
不,它不会。如果他的表格有0.2不透明度并且刷子有128个alpha,他将在他的矩形上得到0.2 * 128阿尔法 – dimitris93 2015-04-24 09:35:31