Valakik
Member
- Joined
- Nov 8, 2020
- Messages
- 12
- Programming Experience
- Beginner
Hello
Long time ago I mentioned that I am making parental control app nowadays and I stuck with one thing.
I am trying to cover the screen with transparent black form so the kids can't use their laptop when the time is up.
Before I had this code in load form event:
After is like this:
Both method don't help me that the transparent black form will be showed on all of the screens (if there are more than 1 screen, laptop screen and a separate screen).
The form just shows on the primary screen.
How can I do that on both screen will be showed?
Note: The TimeEndedForm is just for to able request more time if I am not at home so the kids can do things if they need something to do. Behind the TimeEndedForm appears the black transparent form/panel.
Thank you in advance all of the answers.
Long time ago I mentioned that I am making parental control app nowadays and I stuck with one thing.
I am trying to cover the screen with transparent black form so the kids can't use their laptop when the time is up.
Before I had this code in load form event:
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();
}
After is like this:
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();
}
Both method don't help me that the transparent black form will be showed on all of the screens (if there are more than 1 screen, laptop screen and a separate screen).
The form just shows on the primary screen.
How can I do that on both screen will be showed?
Note: The TimeEndedForm is just for to able request more time if I am not at home so the kids can do things if they need something to do. Behind the TimeEndedForm appears the black transparent form/panel.
Thank you in advance all of the answers.