Form size ???


Galen Somerville

My current screen resolution is set to 1024 x 768. My form size always comes
up as 1032 x 748.

I have tried the help sample
' Retrieve the working rectangle from the Screen class
' using the PrimaryScreen and the WorkingArea properties.
Dim workingRectangle As System.Drawing.Rectangle = _

' Set the size of the form slightly less than size of
' working rectangle.
Me.Size = New System.Drawing.Size(workingRectangle.Width, _

' Set the location so the entire form is visible.
Me.Location = New System.Drawing.Point(0, 0)

the workingRectangle comes up as 1024 x 740. the Me.Size comes up as 1032 x
748 and location as -4 x -4

It doesn't matter what the StartPosition and AutoSize is set to. What gives?

I'm trying to use the Form Width to set a drawing Panel (PictDraw) to the
maximum width based on the the width being a multiple of 4. I guess I'll
have to use the SystemDrawing.Size(workingRectangle.Width) in the following
code. The Form margin is set to Single.

Index = Me.Width - 2
Index = Int(Index / 4)
Index = Index * 4
gScreen.HorPixels = Index
With PictDraw
X1Y1.X = Int(Int((Me.Width - Index) ) / 2)
X1Y1.Y = 0
.Location = X1Y1
X2Y2.X = gScreen.HorPixels
X2Y2.Y = 450
.Size = X2Y2
End With

Any ideas as to why the form always comes up 1032 X748 ?


Kevin Westhead

You should consider setting the location to be the location of the working
area rectangle, otherwise your form might not display properly on desktops
where the taskbar is along either the top or left edges. E.g.

Location = workingRectangle.Location
Size = workingRectangle.Size

When is the code that sets the size called? Is it called after
InitializeComponent? You could try handling the LocationChanged and
SizeChanged events of the form and see if they are raised when your code
sets the properties. It could be that some other code is changing the
properties after you, which means you'll see the events raised again.


Maybe your Form's Minimum size is set to that?.. there is a property for
Minimum size.. check that...


Herfried K. Wagner [MVP]

Galen Somerville said:
My current screen resolution is set to 1024 x 768. My form size always
comes up as 1032 x 748.

Form's cannot be larger than the desktop's working area.

Galen Somerville

I know, that'swhy I asked the questions. I was basing my Panel width based
on Me.Width and the Panel always filled the screen with no Form border
showing. I set a breakpoint and it shows Me.Width as 1032.

That's when I added the workingRectangle code to try to correct it. Still


Cor Ligthert [MVP]


I have the idea that you are doing the same problamatic things as was be
done in the VB versions from the previous milenium

Do you know the properties Dock and Anchor.

They will make your live probably much easier.

I hope this helps,


Galen Somerville


All controls have Anchor set. The control in question is a user control and
intitially it is a small square in an unused portion of screen.

When required it is sized at run time. I have found that the following code
cures my problem
With gScreen

..HorPixels = Screen.GetBounds(Rect).Width

..VerPixels = Screen.GetBounds(Rect).Height

End With


Stephany Young

The point everyone has seemed to missed is that you have your form

When a form is maximized the width of the form is the working area width +
the form left border width + the form right border width and the height of
the form is the working height is the working area height + the form top
border height + the form bottom border height. The position of the form is
0 - the form left border width, 0 - the form top border width.

This 'positioning' and 'sizing' means that a maximized form automatically
takes account of the position and size of the taskbar (if it is showing) no
matter where it actually positioned.

The upshot is, the portion of the maximized form that you can actually see
is the Title Bar and the client area - some of the client area may be
'reserved' for menubars, toolbars, statusbars and other controls that do not
form part of the client area depending on which VS version you are using.

It seems to me that you really want to position and size your user control
in relation to the client area and therefore you can use Me.ClientSize
property for this purpose without having to resort to convuluted maths.

Stephany Young

Is what you you are trying to achieve as follows:

1. Make the width of the panel the multiple of 4 pixels that is less than or
equal to the width of the client area

2. Make the height of the panel the multiple of 4 pixels that is less than
or equal to the height of the client area

3. Center the panel in the client area

If so then it is as simple as:

Panel.Size = New Size(Me.ClientSize.Width - (Me.ClientSize.Width Mod 4),
Me.ClientSize.Height - (Me.ClientSize.Height Mod 4)

Panel.Location = New Location((Me.ClientSize.Width - Panel.Width) / 2),
(Me.ClientSize.Height - Panel.Height) / 2)

Galen Somerville


That explains why Me.Width doesn't work. I did end up using the Client area
width but I still do the math to get multiples of 4 pixels for the Panel.

Other than setting the Anchor points I'm more interested in getting the
whole program working properly before I worry about resizing all forms to
greater than 1024 x 768.


Galen Somerville

The heigth is fixed.

In VB6 my Picturebox always filled the screen horizontally. Now I decided to
let the forms borders show. It's a single border so I assume we are looking

Panel.Size = New Size(Me.ClientSize.Width - ((Me.ClientSize.Width- 2) Mod

Panel.Location = New Location((Me.ClientSize.Width - Panel.Width) / 2),


Stephany Young


The ClientSize.Width is already the width of the portion of tyhe form
'inside' the borders, so the calculation is:

Panel.Size = New Size(Me.ClientSize.Width, IHeight)

Panel.Location = New Location(0, (Me.ClientSize.Height - Panel.Height) /

Note that the location of the Panel is in relation to the top left of the
client area of the form, not the top left of the screen.

Galen Somerville

Me.ClientSize came out as 1,024 so I'm back to
Panel.Size = New Size(Me.ClientSize.Width - ((Me.ClientSize.Width- 2) Mod
4), 573)

and I want it at top of Client area so
Panel.Location = New Point((Me.ClientSize.Width - Panel.Width) / 2), 0)


Galen Somerville


The actual code ended up as follows

PictDraw.Size = New Size((Int((Me.ClientSize.Width - 2) / 4)) * 4,
PictDraw.Location = New Point(((Me.ClientSize.Width -
PictDraw.Width) / 2), 0)
gScreen.HorPixels = PictDraw.Width


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