Michael Mankus
Michael Mankus

Reputation: 4778

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.

Upvotes: 12

Views: 7115

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

You can use the VisibleChanged event.

private void UserControl_VisibleChanged(object sender, EventArgs e)
{
    if (this.Visible) { ... }
    else { ... }
}

Upvotes: 9

Related Questions