Login required to post messages or search forums!

 

  Product Support  WinFormResizer for .NET 2.0 Support  Center Form Aft...
 Center Form After Resize
 
sarndt
4 posts
Joined
12/12/2006

Center Form After Resize
Posted: 12 Dec 06 9:22 PM

Hi...

I'm testing your product on VB 2005, Netframe 2.0 app.  Situation is, I added your control to a new app I'm building.  When deploying the app on a new target which has different resolution, the form gets resized properly but gets displayed "off center" (to the right).  It's centers fine on the development box. The form is setup to load "center on screen". 

How do I fix this?

Thanks

Steve

Support
71 posts
Joined
4/29/2006

Re: Center Form After Resize
Posted: 13 Dec 06 12:05 AM Modified By Support  on 12/13/2006 12:13:08 AM)

Hello Steve,

 

Thank you for your query.

 

The reason why the form is displaying off center and to the right is because "resizing to resolution" occurs after the form's StartPosition is set.

 

In order to center your form post "resizing to resolution" add the following lines of code after the call to InitializeComponent() in your form's constructor (VB.NET):

 

Public Sub New()

 

' This call is required by the Windows Form Designer.

InitializeComponent()

 

' Add any initialization after the InitializeComponent() call.

Dim szfHalfFormSize As SizeF = New SizeF(Me.Width / 2.0F, Me.Height / 2.0F)

 

Dim scnForm As Screen = Screen.FromControl(Me)

Dim szfHalfScreenSize As SizeF = New SizeF(scnForm.Bounds.Width / 2.0F, scnForm.Bounds.Height / 2.0F)

 

Me.Location = New Point(Convert.ToInt32(Math.Abs(szfHalfScreenSize.Width - szfHalfFormSize.Width)), _

Convert.ToInt32(Math.Abs(szfHalfScreenSize.Height - szfHalfFormSize.Height)))

 

End Sub

 

or C#

 

public Form1()

{

InitializeComponent();

 

SizeF szfHalfFormSize = new SizeF(this.Width / 2.0F, this.Height / 2.0F);

 

Screen scnForm = Screen.FromControl(this);

SizeF szfHalfScreenSize = new SizeF(scnForm.Bounds.Width / 2.0F, scnForm.Bounds.Height / 2.0F);

 

this.Location = new Point(Convert.ToInt32(Math.Abs(szfHalfScreenSize.Width - szfHalfFormSize.Width)),

Convert.ToInt32(Math.Abs(szfHalfScreenSize.Height - szfHalfFormSize.Height)));

}

 

Regards,

Fengari Software Support

sarndt
4 posts
Joined
12/12/2006

Re: Center Form After Resize
Posted: 13 Dec 06 9:03 AM

Thanks...

That did it.

Steve

sarndt
4 posts
Joined
12/12/2006

Re: Center Form After Resize
Posted: 14 Dec 06 1:39 PM

A followup question...In my application, I'm displaying a word document through word automation.  I want the word document active window to display within the top, left, height, width of the vb.net form - and am setting the active window based on the form .top, .left, etc.  If the form is resized using your resizer, will the me.top, .left, etc. display the adjusted pixel values based on the resizing or do I need to do something special to handle the adjusted values?

The reason why I'm asking is the formula I'm using so far (for instance wordapp.activewindow.height = wordapp.pixelstopoints(me.height) works properly on the development box which is 96dpi but doesn't work on the target box which is 120dpi.  But the vb.net form does work using your control.  Instead the word activewindos displays bigger.

Thanks

Steve

Support
71 posts
Joined
4/29/2006

Re: Center Form After Resize
Posted: 15 Dec 06 12:04 AM Modified By Support  on 12/15/2006 4:55:26 AM)
Hello Steve,

Embedded Word documents are ActiveX Controls. The .NET Framework wraps the Word documents container in an instance of the System.Windows.Form.Control "as best as it can".

This means that programmatic changes to properties like the Font property do not produce the desired results or do not have any affect because Word Documents can contain more than one font and a single Font property is not enough to describe the entire document.

This is the reason why WinFormResizer affects the Form and the Word Document's container but not the contents of the Word Document when changes in DPI settings occur.


Regards,
Fengari Software Support

  Product Support  WinFormResizer for .NET 2.0 Support  Center Form Aft...
Copyright © 2006-2008 Fengari Software. All rights reserved.   |  Privacy Statement  |  Terms Of Use