Why are forms painted within controls stretched?

D

Dean Slindee

In all instances where I show a form inside a control (tabpage, panel), the
controls within the shown form are stretched vertically about 5% from the
original. That is, if a textbox with an actual height =16 in the original
form appears to have a height =~18 when the form is shown within a container
control. Why? Is there some setting that specifies "maintain original
dimensions"? Occurs with all border styles:
FormBorderStyle.None

FormBorderStyle.FixedToolWindow

FormBorderStyle.FixedSingle

FormBorderStyle.Fixed3D

Thanks,
Dean Slindee
 
W

William Ryan

Dean: I'm not sure if it's a typo, but is the problem that you are adding a
Form to a given control or vice versa? If the latter, it sounds like a
problem with the anchor property (or the Dock proptery).
 
D

Dean Slindee

Neither. I am painting a form within a container control. The entire
painted form and all the controls the painted form contains are vertically
"elongated" by about 5%. Here is the calling statement:
Call FormShowInControl(frmQueryPro, pagSearch, FormBorderStyle.None)

and the sub called:
Public Sub FormShowInControl(ByVal frm As Form, _

ByRef ctl As Control, _

ByVal style As FormBorderStyle)

With frm

..TopLevel = False

..ControlBox = False

..Parent = ctl

..FormBorderStyle = style

..Show()

..BringToFront()

..Left = 0

..Top = 0

End With

End Sub


frmQueryPro is painted vertically larger within pagSearch (a tabPage) than
it actually appears within the VS Studio designer. (Sort of hoping it's a
video card problem, but I can consistently generate it throughout the
project, numerous forms and host controls)
Thanks,
Dean Slindee
 
P

Peter Huang

Hi Dean,

I can not reproduce the problem. Here are my test steps.

[Form3](Add an TextBox and a button)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(Me.TextBox1.Height)
End Sub

[Form1](add an button, a TabContol and a TabPage onto the form)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim fm As New Form3
MsgBox(fm.TextBox1.Height)
Me.FormShowInControl(fm, Me.TabControl1.TabPages(0),
FormBorderStyle.FixedToolWindow)
End Sub

I get the TextBox1.Height are all 20, they are equal before and after the
FormShowInControl.
I think you may try to create a new project an add two form as me to see if
the problem persists.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
H

Herfried K. Wagner [MVP]

* "Dean Slindee said:
Neither. I am painting a form within a container control. The entire
painted form and all the controls the painted form contains are vertically
"elongated" by about 5%.

Is the form's width "enlongated" too?
 
D

Dean Slindee

Not at all, just the height. I measured a full form's height in VS designer
at 4 7/8 inches, then in a tabPage control, expanded to 5 1/2 inches. I
also loaded the whole project onto another brand of computer with a
different video card. Same problem exactly, so it's not the video card or
the driver.

Dean Slindee
 
D

Dean Slindee

Peter,

Thank you so much for devising that simple test. I lifted your code and put
it in my project.
In the designer, the textboxes are all height = 20. When I click the
button, the height value says 21.
(Which is the 5% elongation I estimated). I'm, I'm .... (speechless).

This test was run with both Microsoft and 3rd party text boxes, results were
the same.
I further took the project and installed it on a completely different PC.
Same results exactly, thus eliminating the suspicion of video card or
drivers.

Also, I nested one more form and tabcontrol within the test tabcontrol and
reran the test. Still 21, which means the elongation happens only once.

Dean
 
D

Dean Slindee

I forgot to mention that the spacing between the controls is also elongated
by 5%
 
D

Dean Slindee

Found the source of the problem. The tabcontrol I'm using (from a
well-respected 3-party vendor)
is causing the problem on any controls painted within it's pages. I have
put together a test project demonstrating the problem and emailed it to the
vendor.

Thanks again for your simple test situation. I extended it to illustrate
the problem to the vendor.

Dean Slindee
 
P

Peter Huang

Hi Dean,

Based on further test, I find that when I set font of the TabPage from
Microsoft Sans Serif, 8.25pt to Microsoft Sans Serif, 9pt, I will get 20
before show the form in the tabpage, and get 21 after show the form in the
tabpage.

So I think you may try to take a look at if you are using the same font on
the form and the container control.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
C

Cor

Hi Dean,

When you send next time a message, can you tell that in advance, saves a lot
of times from people who try to help you?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top