I have a file watcher which basically detects some edits on stuff. When that happens, this method is called. This basically hides for a brief moment the form (and the button that has its same size) so it can capture the screen beneath and make the button's color as default, hover and click, taking the dominant color of the captured area. That, in practical terms, makes the button "almost transparent". More about the matter down below.
I wish to make the button actually transparent but I cannot because using Color.Transparent makes the button only clickable if the user clicks exactly where the click registers any color that is NOT transparent- i.e. if you click on a transparent area of the button, nothing happens. So, I wish to capture instead the area beneaht the button and the form and use it to set the button's "look" (lke, background image). In particular, i would need to set it as look even when clicked and hovered, because i don't want its default behavior change its appearance when interacting with the mouse (it's only supposed to be interacted with the mouse). Do you know perhaps a simple way to use the screenshot (in this code is already there, it's basically "pixel") as a perennial look and not get overwritten by mouse behavior?
C#:
private void colorupdate()
{
this.Invoke((MethodInvoker)delegate
{
this.Visible = false;
});
Dictionary<Color, int[]> colori = new Dictionary<Color, int[]>();
using (Bitmap pixel = new Bitmap(this.Width, this.Height))
{
using (Graphics captureGraphics = Graphics.FromImage(pixel))
{
captureGraphics.CopyFromScreen(new Point(this.Location.X, this.Location.Y), Point.Empty, new Size(this.Width, this.Height));
}
for (int x = 0; x < this.Width; x++)
{
for (int y = 0; y < this.Height; y++)
{
Color colore = pixel.GetPixel(x, y);
if (!colori.ContainsKey(colore)) { colori.Add(colore, new int[] { 1, x, y }); }
else { colori[colore][0]++; }
}
}
}
int dss = colori.OrderByDescending(set => set.Value[0]).First().Value[0];
int[] ds = colori.OrderByDescending(set => set.Value[0]).First().Value;
Color color = colori.OrderByDescending(set => set.Value[0]).First().Key;
this.Invoke((MethodInvoker)delegate
{
button1.BackColor = color;
button1.FlatAppearance.MouseOverBackColor = color;
button1.FlatAppearance.MouseDownBackColor = color;
button1.FlatStyle = FlatStyle.Flat;
button1.FlatAppearance.BorderSize = 0;
this.Visible = true;
});
}
I wish to make the button actually transparent but I cannot because using Color.Transparent makes the button only clickable if the user clicks exactly where the click registers any color that is NOT transparent- i.e. if you click on a transparent area of the button, nothing happens. So, I wish to capture instead the area beneaht the button and the form and use it to set the button's "look" (lke, background image). In particular, i would need to set it as look even when clicked and hovered, because i don't want its default behavior change its appearance when interacting with the mouse (it's only supposed to be interacted with the mouse). Do you know perhaps a simple way to use the screenshot (in this code is already there, it's basically "pixel") as a perennial look and not get overwritten by mouse behavior?