0

i saw this article that shows printing of listview using printdocument.. it helps me but then i want to place my list view on the middle of the page.. i want to know how to place it.. can you please help me? thank youu. !

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by paoi00
0

You have to calculate 2 things:
1. the dimensions of the form
2. the dimensions of the control (listView in your case)

Then calculate to position it in the middle.
So you can do:

int formX = this.Width;
int formY = this.Heigth;
int listX = listView1.Width
int listY = listView1.Heigth;

int X = (formX / 2) - (listX / 2);
int Y = (formY / 2) - (listY / 2);

listView1.Location = new Point(X, Y);

Edited by Mitja Bonca: changed code

0

i think its not vb.net code.. it has errors.

i change to this >> Dim formX As Integer = this.Width

but then have errors in
this.width

0

ups, sorry, this is VB`s code:

Dim formX As Integer = Me.Width
Dim formY As Integer = Me.Height
Dim listX As Integer = listView1.Width
Dim listY As Integer = listView1.Height

Dim X As Integer = (formX \ 2) - (listX \ 2)
Dim Y As Integer = (formY \ 2) - (listY \ 2)

listView1.Location = New Point(X, Y)
0

thanx for the code.. but when i put it my PrintDocument .. the listbox in my form disappears .. and the listbox in my printpreview dialogbox stills in the top of the page. .. how should i adjust it?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.