Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What event occurs immediately after a control is displayed for the first time?

I know there is UserControl.Load, which occurs before the control becomes visible for the first time. And I know there is UserControl.HandleCreated, which occurs when a handle is created for the control.

But I'm looking for what event occurs when the control is actually shown for the first time.

Reason:

I am dealing with a DataGridView which has a bunch of data put into it before the control is shown. I can't color the rows (BackColor) without the control being painted (the commands simply don't work). The commands to color rows only works once the control has been painted for the first time. So I need to capture that event and colorize the rows at that point.

dataGridView1.Rows[index].DefaultCellStyle.BackColor = Color.Red;

The above line works when the control is shown but does not work with the control is not shown.

like image 773
Michael Mankus Avatar asked May 15 '13 13:05

Michael Mankus


1 Answers

You can use the VisibleChanged event.

private void UserControl_VisibleChanged(object sender, EventArgs e)
{
    if (this.Visible) { ... }
    else { ... }
}
like image 133
Mike Perrenoud Avatar answered Sep 28 '22 01:09

Mike Perrenoud