Reputation: 15847
I have a WinForm where I override the OnPaint
, this form is a MDI parent. The OnPaint
is however not triggered even when the WinForm
is shown with a child? I have tried to use Invalidate
and the Update
but does not trigger the OnPaint
eather?
I have tried the Paint event but its the same here?
Any idea?
Upvotes: 1
Views: 1470
Reputation: 13690
When you set Form.IsMdiContainer
, it actually just adds a MdiClient
control to the form. Your child forms are actually displayed within the MdiClient control and not the form itself. Your form's Paint event is being raised, but the MdiClient is docked in the form so you don't see it. You need to access the MdiClient's paint event instead.
public partial class Form1 : Form
{
public Form1() {
InitializeComponent();
mdiClient = Controls[0] as MdiClient;
if (mdiClient != null) {
mdiClient.Paint += OnMdiClientPaint;
}
}
private MdiClient mdiClient;
private void OnMdiClientPaint(object sender, PaintEventArgs e) {
e.Graphics.FillRectangle(Brushes.Blue, mdiClient.ClientRectangle);
}
}
Upvotes: 2