Size of unused MDIClient window

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

Is it possible to find the size of the MDIClient area, excluding the space
already used by docked controls?
I have thought I could perhaps create a new control, set it's Dock property
to Fill and see how big that is, but there must be a better way. I would
have to do this in the Resize event
TIA
Phil.
 
Is it possible to find the size of the MDIClient area, excluding the space
already used by docked controls?
I have thought I could perhaps create a new control, set it's Dock property
to Fill and see how big that is, but there must be a better way. I would
have to do this in the Resize event

Can I ask why you need to know? Is it because you fear there
won't be enough space left for a form?
 
Jan Hyde (VB MVP) said:
Can I ask why you need to know? Is it because you fear there
won't be enough space left for a form?

The reason I'm asking at the moment is because I want to draw on the
backgound of the MDI form, so I need to be able to identify which parts
aren't covered by other (docked) controls, so that my drawing is not
obscured.
 
Hi Phil,

Based on my understanding, you have an MDI parent and a control, e.g. a
ListView, which is docked on the MDI parent. You'd like to get the size of
the MdiClient that is not covered by the ListView. If I'm off base, please
feel free to let me know.

In fact, the MdiClient is a control that is contained in an MDI parent. We
can get it by looping the child control collection of the MDI parent. Once
we get the MdiClient control, we know its size. The following is a sample.

Dim mc As MdiClient = Nothing
For Each ctrl As Control In Me.Controls
If (ctrl.GetType().Equals(GetType(MdiClient))) Then
mc = CType(ctrl, MdiClient)
exit For
End If
Next

When we add a control in an MDI parent and dock it to a side, the MdiClient
control won't be covered by the added control, instead, it will take the
rest space of the MDI parent. So we needn't calculate the size of the
MdiClient that is not covered by other control at all.

If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Based on my understanding, you have an MDI parent and a control, e.g. a
ListView, which is docked on the MDI parent. You'd like to get the size of
the MdiClient that is not covered by the ListView. If I'm off base, please
feel free to let me know.

That's basically it, yes. I actually have a menustrip, a toolstrip and a
couple of panels with other controls on them. These are all docked in the
mdi parent window, and I plan to allow the user to move some of these
around.
In fact, the MdiClient is a control that is contained in an MDI parent. We
can get it by looping the child control collection of the MDI parent. Once
we get the MdiClient control, we know its size. The following is a sample.

Dim mc As MdiClient = Nothing
For Each ctrl As Control In Me.Controls
If (ctrl.GetType().Equals(GetType(MdiClient))) Then
mc = CType(ctrl, MdiClient)
exit For
End If
Next

Thanks. This looks like what I need. I had discovered this myself, but it
didn't seem to be giving the right results, but I'll try this again. I had
actually found another way of getting a reference to the MDIClient. like
this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
With New Form2
.mdiparent = Me
mc = .Parent
.Dispose()
End With
End Sub

Not sure which way is more efficient?
When we add a control in an MDI parent and dock it to a side, the
MdiClient
control won't be covered by the added control, instead, it will take the
rest space of the MDI parent. So we needn't calculate the size of the
MdiClient that is not covered by other control at all.

OK. That seems to work. The following code draws a line from one corner to
the other:

Private Sub mc_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles mc.Paint
With e.Graphics
.DrawLine(Pens.White, 0, 0, mc.Width, mc.Height)
End With
End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
Refresh()
End Sub
If you have any question, please feel free to let me know.

Thanks. I changed the code above to call DrawImage instead of DrawLine. I
want the image to be on the right hand side. So I used the following, but
the image is placed too far to the right, and get's clipped:

.DrawImage(Image, mc.Width - Image.Width, 0)

Not sure what I'm doing wrong here. Are the units of the image width
different from that of the MDIClient window?

Cheers,
Phil.
 
Thanks. I changed the code above to call DrawImage instead of DrawLine. I
want the image to be on the right hand side. So I used the following, but
the image is placed too far to the right, and get's clipped:

.DrawImage(Image, mc.Width - Image.Width, 0)

Not sure what I'm doing wrong here. Are the units of the image width
different from that of the MDIClient window?

I've had a bit more of a play, and it seems that DrawImage is actually
drawing the image bigger than it should be, so it was in the right place all
along. If I explicitly set the width and height it works fine:

.DrawImage(Image, mc.Width - Image.Width, 0, Image.Width, Image.Height)

The help says "Draws the specified image, using its original physical size".
This is obviously not the physical size in terms of pixels. Presumably it is
taking into account the HorizontalResolution and VerticalResolution property
values?
 
Hi Phil,

Thank you for your prompt reply.

What's the format of the image you draw in the MdiClient in your
application?

I performed several tests on BMP and GIF images. When I draw the images in
the MdiClient using your sample code " .DrawImage(Image, mc.Width -
Image.Width, 0)", the right line of the images are clipped. I got the same
result when I tried the code " .DrawImage(Image, mc.Width - Image.Width, 0,
Image.Width, Image.Height)".

I had a try drawing the same image in a Panel, and the result was that the
right line of the image didn't get clipped at all.

So it seems that it is the 3D border of the MdiClient that covers the
image's right line. Then I tried to remove the 3D border of the MdiClient
and saw that the image was drawn in the MdiClient completely.

If you'd like to have a try removing the 3D border of the MdiClient, you
may refer to my following post to get how to do it:

http://msdn.microsoft.com/newsgroups/managed/Default.aspx?query=Custom+form+
border+ljlevend2%40nospam.nospam

Hope this helps.
Please let me know if you have any question.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
What's the format of the image you draw in the MdiClient in your
application?

The main image I was using was a JPG, but I have tried it with a BMP too,
and see the same thing.
I performed several tests on BMP and GIF images. When I draw the images in
the MdiClient using your sample code " .DrawImage(Image, mc.Width -
Image.Width, 0)", the right line of the images are clipped. I got the same
result when I tried the code " .DrawImage(Image, mc.Width - Image.Width,
0,
Image.Width, Image.Height)".

That's interesting. For me the images are definitely different sizes for the
two commands.
Perhaps it depends on the chosen screen resolution and/or size of monitor
screen?
Here is a screenshot:
http://www.triton-technology.co.uk/Phil/MdiClientDrawImage.JPG
The two test images I used are also there, if you want to try them
http://www.triton-technology.co.uk/Phil/
I had a try drawing the same image in a Panel, and the result was that the
right line of the image didn't get clipped at all.

So it seems that it is the 3D border of the MdiClient that covers the
image's right line. Then I tried to remove the 3D border of the MdiClient
and saw that the image was drawn in the MdiClient completely.

When I look very closely, I can see this effect on my system, but this isn't
the effect I am referring too. I am getting much more of the image clipped
when I don't specify the width & height, not just a few pixels.
If you'd like to have a try removing the 3D border of the MdiClient, you
may refer to my following post to get how to do it:

http://msdn.microsoft.com/newsgroups/managed/Default.aspx?query=Custom+form+
border+ljlevend2%40nospam.nospam

Thanks, I shall take a look at this. I don't think I want to remove the 3D
border, but I will most likely need to take it's width into account.

Cheers,
Phil.
 
Hi Phil,

Thank you for your reply.

I download the JPG file you provided and perform a test in my project. I do
see the JPG picture is clipped on the right side and the clipped part is
not a few pixels.

I look up Graphics.DrawImage Method (Image, Int32, Int32) in MSDN and find
the following remark:

"(This method)Draws the specified image, using its original physical size,
at the location specified by a coordinate pair. "

"An Image stores a value for pixel width and a value for horizontal
resolution (dots per inch). The physical width, measured in inches, of an
image is the pixel width divided by the horizontal resolution. Similar
remarks apply to pixel height and physical height."

Since the term of the physical width and height is different from that of
Width and Height property of the Image, it explains why the JPG picture is
clipped in the MdiClient within our projects.

It's correct to use the overload method Graphics.DrawImage Method (Image,
Int32, Int32, Int32, Int32) to specify the width and height in pixel to
address this problem.

Hope this helps.
If you have any question, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
I look up Graphics.DrawImage Method (Image, Int32, Int32) in MSDN and find
the following remark:

"(This method)Draws the specified image, using its original physical size,
at the location specified by a coordinate pair. "

"An Image stores a value for pixel width and a value for horizontal
resolution (dots per inch). The physical width, measured in inches, of an
image is the pixel width divided by the horizontal resolution. Similar
remarks apply to pixel height and physical height."
Yes. I see that now.
I think I must have looked at the help for the Graphics.DrawImage Method but
not the detail page for the specific overload.

Thanks for your help.
Cheers,
Phil

P.S. Now I just need to figure out how to get the size of the MDIClient
border so that I can subtract this off.
 
Hi Phil,

Thank you for your quick response.
Now I just need to figure out how to get the size of the MDIClient border
so that I can subtract this off.

The 3D border is the Non-Client area of an MdiClient control. We can use
the two properties Size and ClientRectangle of the MdiClient class to get
the width of the 3D border. The following is a sample.

' mc is an MdiClient control
Dim borderWidth As Integer = (mc.Size.Width - mc.ClientRectangle.Width) / 2

-or-

Dim borderWidth As Integer = (mc.Size.Height- mc.ClientRectangle.Height) / 2

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Phil,

How about the problem now?

If you have any question, please feel free to let me know.

Thank you for choosing Microsoft!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Back
Top