1

First of all, I would like to talk about the application very briefly. There is a child form inside the main form in my application, and this child form also contains a datagridview. You can see the structure I'm talking about in the picture below.

Application Structure

I have a very secret and magic function. This function works with hotkey and the working time of the function is a bit long so I want to make a standby screen. When I press the hotkey, I want the datagridview to darken a little and the message "Please wait" appears in the middle of the childform. If you don't understand, please take a look at the picture below.

It's what I want it to be

For this, I put a panel on the datagridview and set it to

panel.BackColor = Color.FromArgb(50, Color.Black);
panel.Visible = false;

also myFunction() does this.

private void myFunction()
{
  panel.Visible = true;
  // Top secret codes {...}
  panelVisible = false;
}

But this method didn't work. The panel appears but it deletes the gridview behind it like this.

----- :'( -----

I searched a lot but couldn't solve the problem. Does anyone have a better method or solution suggestion?

emogo
  • 13
  • 4
  • The screenshot isn't look like as it had any transparency. It just appears to be disabled and thus grayed out. If you really want a partially transparent overlay form you can play with the `Opacity` property. Or, see [this](https://stackoverflow.com/q/51370670/5114784) answer to see how to create a Windows 10 blurry transparency effect in WinForms. – György Kőszeg Oct 22 '22 at 15:02
  • If you want to use a transparent / translucent Panel, you have to create a Custom Control, to set some specific styles. The background Color is not enough. See the example [here](https://stackoverflow.com/a/54158350/7444103) -- Or something like this: [Translucent circular Control with text](https://stackoverflow.com/a/51435842/7444103) – Jimi Oct 22 '22 at 15:32
  • panel.Parent = datagridview1; panel.Location = ... – Hans Passant Oct 23 '22 at 23:18
  • Just disable the main form and display a secondary, borderless one with "please wait"...? – Idle_Mind Oct 24 '22 at 00:51

1 Answers1

0

You can have a function that you call when the operation starts. This function displays the label "Please wait" and fills gridview columns with the desired color:

private void standbyScreen()
{
        foreach (DataGridViewColumn col in dataGridView1.Columns)
        {
            col.DefaultCellStyle.BackColor = Color.FromArgb(50, 50, 50); 
            col.DefaultCellStyle.ForeColor = Color.FromArgb(80,80,80);          
        }
        pleaseWaitLbl.Show();
}

This code make a standby screen for DataGridView:

enter image description here

and a function to end the operation that turns standby screen into normal:

private void normalScreen()
{
        foreach (DataGridViewColumn col in dataGridView1.Columns)
        {
            col.DefaultCellStyle.BackColor = Color.Gray; 
            col.DefaultCellStyle.ForeColor = Color.White;              
        }
        pleaseWaitLbl.Hide();
}

enter image description here

This was just an example, you can choose better colors for standby screen. I hope this helps

Hossein Sabziani
  • 1
  • 2
  • 15
  • 20