瓦拉基克
会员
- 已加入
- 2020年11月8日
- 留言内容
- 9
- 编程经验
- Beginner
您好
很久以前,我提到我现在正在制作父母控制应用程序,但我坚持做一件事。
我试图用透明的黑色形式遮盖屏幕,以便孩子们在时间到时不能使用笔记本电脑。
在加载表单事件中获得此代码之前:
之后是这样的:
两种方法都不能帮助我在所有屏幕上显示透明的黑色表单(如果有多个屏幕,笔记本电脑屏幕和单独的屏幕)。
该表格仅显示在主屏幕上。
如何在两个屏幕上都显示?
注意:TimeEndedForm仅用于在我不在家的情况下请求更多时间,以便孩子们在需要做的事情时可以做一些事情。在TimeEndedForm的后面出现黑色的透明表单/面板。
预先感谢您所有的答案。
很久以前,我提到我现在正在制作父母控制应用程序,但我坚持做一件事。
我试图用透明的黑色形式遮盖屏幕,以便孩子们在时间到时不能使用笔记本电脑。
在加载表单事件中获得此代码之前:
C#:
Bitmap bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
using (Graphics G = Graphics.FromImage(bmp))
{
G.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
G.CopyFromScreen(this.PointToScreen(new Point(0, 0)), new Point(0, 0), this.ClientRectangle.Size);
double percent = 0.60;
Color darken = Color.FromArgb((int)(255 * percent), Color.Black);
using (Brush brsh = new SolidBrush(darken))
{
G.FillRectangle(brsh, this.ClientRectangle);
}
}
// put the darkened screenshot into a Panel and bring it to the front:
using (Panel p = new Panel())
{
p.Location = new Point(0, 0);
p.Size = this.ClientRectangle.Size;
p.BackgroundImage = bmp;
this.Controls.Add(p);
p.BringToFront();
// display your dialog somehow:
TimeEndedForm timended = new TimeEndedForm();
timended.Show();
}
之后是这样的:
C#:
Bitmap bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
using (Graphics G = Graphics.FromImage(bmp))
{
G.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
G.CopyFromScreen(this.PointToScreen(new Point(0, 0)), new Point(0, 0), this.ClientRectangle.Size);
double percent = 0.60;
Color darken = Color.FromArgb((int)(255 * percent), Color.Black);
using (Brush brsh = new SolidBrush(darken))
{
G.FillRectangle(brsh, this.ClientRectangle);
}
}
// put the darkened screenshot into a Panel and bring it to the front:
using (Panel p = new Panel())
{
int height = 0;
int width = 0;
foreach (Screen screen in Screen.AllScreens)
{
//take smallest height
height = (screen.Bounds.Height <= height) ? screen.Bounds.Height : height;
width += screen.Bounds.Width;
}
p.Location = new Point(0, 0);
this.Size = new Size(width, height);
// p.Size = this.ClientRectangle.Size;
p.Size = new Size(width, height);
p.BackgroundImage = bmp;
this.Controls.Add(p);
p.BringToFront();
// display your dialog somehow:
TimeEndedForm timended = new TimeEndedForm();
timended.Show();
}
两种方法都不能帮助我在所有屏幕上显示透明的黑色表单(如果有多个屏幕,笔记本电脑屏幕和单独的屏幕)。
该表格仅显示在主屏幕上。
如何在两个屏幕上都显示?
注意:TimeEndedForm仅用于在我不在家的情况下请求更多时间,以便孩子们在需要做的事情时可以做一些事情。在TimeEndedForm的后面出现黑色的透明表单/面板。
预先感谢您所有的答案。