MDI Form

  • Thread starter Thread starter [Gho]
  • Start date Start date
G

[Gho]

I want to paint an image in the midle of my MDI Form.
But the problem is that this image always on top, so i
can't see the form i opened.
How to add image to MDI form whith "Image Top most =false"
 
Hi Gho,

I want to paint an image in the midle of my MDI Form.
But the problem is that this image always on top, so i
can't see the form i opened.
How to add image to MDI form whith "Image Top most =false"

You need to paint the image onto the MdiClient window which is the
container for all the MDI child windows. Here's an example:

// In the MDI Parent form.
private MdiClient _mdiClient;
private Image _backImage;
...
public MDIParent() // The constructor of the MDI Parent form class.
{
...
Stream imageStream =

Assembly.GetExecutingAssembly().GetManifestResourceStream("MyApp.MyImage.jpg
");

_backImage = new Bitmap(imageStream);

foreach(Control control in this.Controls)
{
_mdiClient = control as MdiClient;

if (_mdiClient != null)
{
_mdiClient.Paint +=new PaintEventHandler(_mdiClient_Paint);
_mdiClient.Resize +=new EventHandler(_mdiClient_Resize);
break;
}
}
...
}
...
private void _mdiClient_Paint(object sender, PaintEventArgs e)
{
float x = _mdiClient.ClientRectangle.Left
+ ((_mdiClient.ClientSize.Width - _backImage.Width) / 2.0f);
float y = _mdiClient.ClientRectangle.Top
+ ((_mdiClient.ClientSize.Height - _backImage.Height) / 2.0f);

e.Graphics.DrawImage(_backImage, x, y, _backImage.Width,
_backImage.Height);
}

private void _mdiClient_Resize(object sender, EventArgs e)
{
_mdiClient.Invalidate();
}
...

Hope that helps.

Regards,
Dan
 
Back
Top