By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

Size of unused MDIClient window

P: n/a
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.
Aug 1 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Phil" <N/A>'s wild thoughts were released on Wed, 1 Aug
2007 14:24:58 +0100 bearing the following fruit:
>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

https://mvp.support.microsoft.com/profile/Jan.Hyde
Aug 1 '07 #2

P: n/a

"Jan Hyde (VB MVP)" <St***********@REMOVE.ME.uboot.comwrote in message
news:v1********************************@4ax.com...
"Phil" <N/A>'s wild thoughts were released on Wed, 1 Aug
2007 14:24:58 +0100 bearing the following fruit:
>>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?
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.
Aug 1 '07 #3

P: n/a
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 2 '07 #4

P: n/a
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.
Aug 2 '07 #5

P: n/a
>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?
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?
Aug 2 '07 #6

P: n/a
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

Aug 7 '07 #7

P: n/a
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

Aug 10 '07 #8

P: n/a
>
How about the problem now?
I think this one's all sorted now.
Thanks a lot for your help.
Aug 10 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.