Screen width in VB.NET different than VB6

G

Guest

I'm trying to write a form resize event to have a datagrid resize itself as
the form size changes. Here's the code I wrote:

DataGrid1.Width = Me.Width - (20)
DataGrid1.Left = 10
DataGrid1.Top = 10
DataGrid1.Height = Me.Height - (20)

This should leave a 10 pixel buffer around the grid. When I run this, the
right edge space is visually smaller than the left side, and the grid is
running off the bottom.

When I did stuff like this in VB6, I had to use scaleheight and scalewidth
for the form so the resizes did what it was supposed to, to account for form
edging. I dont see a VB equivalent. So how do I dynamically have the grid
center itself. I do not want to use the anchor property, because that's based
on the form, and sometimes I leave a gap for things like a menubar or command
buttons at the top of a form.

Thanks
 
T

Tom Dacon

Use the ClientRectangle property of the form. The dimensions represent the
client area of the form, exclusive of borders and title bars and menus.

Tom Dacon
Dacon Software Consulting
 
L

Lloyd Sheen

You could create the following which will require no code.

First a new form then 4 panels docked at the top, bottom, left and right.
Make the top and bottom hieghts 10 and the left and right have widths of 20.
Then one panel (more generic and you can add to the panel) which is docked
fill.

This will give you a form which can be resized and the datagrid resized
along with it. Simply change the size of the panels at the sides to change
the perspective of the datagrid or panel. There is another property (not
sure what it is called) that allows this in VB Express (2005) without the
extra panels.

Lloyd Sheen
 
G

Guest

Thanks. What's funny is I was looking for this for about a week, and right
after I posted I finally found it in MSDN. I did a query on borders, and that
led me to form.borders, which led to the client rectangle. Amazing how you
figure things out a short time after you ask the question.

Do you know of an MSDN page where the VB6 form stuff is compared to the
VBNet form. Something like a list of fields, scaleheight =
clientrectangle.height

Thanks
 

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