Problem with XP style

  • Thread starter Thread starter Janez
  • Start date Start date
J

Janez

Hi,

I have main form with listview on it and context menu with many menu
items is attached to this listview. In these menu items I create new
form (always the same form), set position properties of the controls
and visibility (depends on the menu item clicked) and display form
(ShowDialog). So position of the controls, height of the form and
visibility of the appropriate groupbox are determined at run time.
For example
Private Sub menu1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles menu1.Click
frm2 = New Form2
try
With frm2
.Height = 430
.button1.Top = 380
.button2.Top = 380
'here fill some listbox and comboboxes with data
......
.Text = "Something"
.Groupbox1.Visible = True
.ShowDialog()
End With
Finally
frm2.Dispose()
End Try
End Sub
However, I have noticed that when I run my application on Windows XP
with XP Style apperance, my buttons which are at the bottom of the
screen are hidden below the bottom of the form. They are not
completely gone, but some portion of them is hidden. I also noticed
that this only happens when I change Height of the form at run time.
If for example, I change height of the form at the design time to 430
and comment out the height property in the code, everything is
displayed as should. However, I need to change the height of the form
at run time.
How could I avoid this?
 
Hi Janez,

Try using DockPadding for your form. It is in the properties, you can set
all of them if you want but for your case concentrate on the bottom padding.
This will put a space between the last control on your page and the bottom
of the form.

Danielle
 
As I noticed this only happens when form border style is set to
FixedSingle (I use this with my form), FixedDialog, Fixed3D or
Sizable. If it is set to, for example FixedToolWindow, it works OK,
but of course the X button in upper right corner is smaller and there
is no icon in left upper corner.
So obviously it is a problem with FormBorderStyle property.
Anybody with the same problem?

Regards
Janez
 
That's because Windows XP's title bar is taller than on other OSes. So when
you set your form's Height to 430, the title bar and top border take up 30
of those 430 pixels and the bottom border takes up another 4, leaving you
with 396 pixels for your controls. This is as opposed to a 26-pixel title
bar/top border on Windows 2000 and below, which gives you a 400-pixel-high
client area. So you've got somewhere around 4 fewer pixels on XP.

It's generally a bad idea to set the form's size using its Width and Height
properties, unless you've set it to FormBorderStyle.None, because the user
can change their title bar font (and therefore the height of the title bar)
on any OS, and can also change the thickness of the resize borders (thus
affecting the width as well).

Unless you've got a very compelling reason to do otherwise, you should
always set the form's size by using ClientSize, not using Width and Height.
 
Joe,

thank you for a very good explanation and a tip about setting form's
size. It works fine.

Regards
Janez
 
Back
Top