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.
You can use the VisibleChanged
event.
private void UserControl_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible) { ... }
else { ... }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With