PC Review


Reply
Thread Tools Rate Thread

Custom initial size of Form

 
 
Sergey Hrushev
Guest
Posts: n/a
 
      30th Apr 2009
Hello All!

I found quite strange problem with a Form from System.Windows.Forms:

What I need is the borderless Form which must have initial dimensions and
position
specified by application (i.e. not default ones).
So for my form I've specified FormBorderStyle = None and StartPosition =
Manual.
After that I've called SetBounds(...) for it and made it visible with
Visible = true.

But the dimensions of the form on screen were different from ones I
specified in SetBounds.
I tried to look for something like StartPosition but for size (StartSize or
something),
but it seems nothing exists for this.

From other side when I've tried to set Visible = true at first and then
SetBounds(...) all was working correctly.
But this causes so terrible flickering that this method seems to be
unusable.

Does anybody know how this problem can be solved?

Best regards,
Sergey Hrushev.


 
Reply With Quote
 
 
 
 
Bernd Rausch
Guest
Posts: n/a
 
      30th Apr 2009
Sergey Hrushev schrieb:
> But the dimensions of the form on screen were different from ones I
> specified in SetBounds.
> I tried to look for something like StartPosition but for size (StartSize or
> something),
> but it seems nothing exists for this.
> Does anybody know how this problem can be solved?


If the form is bigger than specified, this may be a problem with
autoscaling. Do you have a high dpi setting? Does the problem occur if
you change the display settings to normal (96dpi)?
If so, than you should read this article:
http://msdn.microsoft.com/en-us/library/ms229605.aspx

I don't have a simple "click that option and it works" solution, because
I depends how you would like to handle those situations (high dpi
settings, large font settings, ...). Do you resize your form and your
content? Only your content, but not your form? Do you ignore it
completely and override the user preferences? Not a simple problem.

Hope to help,
Bernd Rausch
 
Reply With Quote
 
Sergey Hrushev
Guest
Posts: n/a
 
      30th Apr 2009
Hello Bernd Rausch,

thank you for your answer!

> I don't have a simple "click that option and it works" solution, because
> I depends how you would like to handle those situations (high dpi
> settings, large font settings, ...). Do you resize your form and your
> content? Only your content, but not your form? Do you ignore it
> completely and override the user preferences? Not a simple problem.


This form doesn't need any scaling, also it doesn't contain any controls.
And only custom painting is used for it.
So no any DPI & co. problems ever exist.

The situation is very simple in theory, and in WinAPI there's no such a
problem at all
but what to do in WinForms if I just need for example dimensions 100*100?

What I can't understand is why only first time my SetBounds(...) dimensions
are became overridden?
But when I change dimensions of already displayed form they're remains
correct and not scaled/changed.

Best regards,
Sergey Hrushev.


 
Reply With Quote
 
Bernd Rausch
Guest
Posts: n/a
 
      7th May 2009
Sergey Hrushev schrieb:
> This form doesn't need any scaling, also it doesn't contain any controls.
> And only custom painting is used for it.
> So no any DPI & co. problems ever exist.


When does this problem occur? Always? Or just in high dpi settings? Only
on some computers? Did you try to change the AutoScaleMode of your form?

> The situation is very simple in theory, and in WinAPI there's no such a
> problem at all
> but what to do in WinForms if I just need for example dimensions 100*100?


When you set the Bounds to 100x100, what are the real bounds of the
form? Is the form getting bigger or smaller?

I just created a Demo Project. Just a form without controls, size set to
200x200 and the following method:

protected override void OnPaint( PaintEventArgs e ) {
e.Graphics.DrawString(
this.ClientRectangle.ToString( ),
this.Font,
Brushes.Black,
5f, 5f );
base.OnPaddingChanged( e );
}

If I start the programm with normal dpi settings, the text is
{X=0,Y=0,Width=192,Height=166}. If I change to high dpi settings
(Display properties -> Settings -> Extended -> DPI Settings [sorry, I'm
using a German version, so the naming may not be correct]), reboot
Windows and start the program again, the form is bigger and the text is
{X=0,Y=0,Width=256,Height=204}.
If I change the AutoScaleMode property of my form to None, then the size
is the same, regarless of the dpi settings.

Hope to help,
Bernd Rausch
 
Reply With Quote
 
Sergey Hrushev
Guest
Posts: n/a
 
      12th May 2009
Hello Bernd Rausch,

thank you for your answer!

> When does this problem occur? Always? Or just in high dpi settings? Only
> on some computers?


The problem occurs only first time the form being displayed.
It's independent of current DPI setting and occurs always when form is
displayed "first time".
I tried on different computers and the result was always 100% the same.

> Did you try to change the AutoScaleMode of your form?


Yes, I tried to switch off the AutoScaleMode unfortunatelly without any
effect.

> When you set the Bounds to 100x100, what are the real bounds of the
> form? Is the form getting bigger or smaller?


I need quite small forms (for some special purposes) and the size of form on
the
screen is always larger than the one I specified.
I tried many times with different settings (AutoScaleMode and etc.) but the
form was
always bigger than specified.

Best regards,
Sergey Hrushev.


 
Reply With Quote
 
Sergey Hrushev
Guest
Posts: n/a
 
      12th May 2009
Hello Bernd Rausch,

thank you for your answer!

> When does this problem occur? Always? Or just in high dpi settings? Only
> on some computers?


The problem occurs only first time the form being displayed.
It's independent of current DPI setting and occurs always when form is
displayed "first time".
I tried on different computers and the result was always 100% the same.

> Did you try to change the AutoScaleMode of your form?


Yes, I tried to switch off the AutoScaleMode unfortunatelly without any
effect.

> When you set the Bounds to 100x100, what are the real bounds of the
> form? Is the form getting bigger or smaller?


I need quite small forms (for some special purposes) and the size of form on
the
screen is always larger than the one I specified.
I tried many times with different settings (AutoScaleMode and etc.) but the
form was
always bigger than specified.

Best regards,
Sergey Hrushev.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom size for form printout seeker Microsoft Access Forms 0 17th Dec 2009 03:06 AM
How do I control the initial size of a datasheet form Dan Neely Microsoft Access Form Coding 1 17th Jul 2007 09:19 PM
Initial size of Custom Control =?Utf-8?B?TWlyZWsgRW5keXM=?= Microsoft Dot NET Compact Framework 0 18th Aug 2006 10:34 AM
Custom Form Size Recognition SeekMocha Printers 0 22nd Mar 2005 02:17 AM
Custom Form size Nancy Windows XP Print / Fax 1 16th Oct 2003 08:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:24 PM.