Re: C# Large Font Small Font Bug???? Fix???
From: Nick Malik [Microsoft] (nickmalik_at_hotmail.nospam.com)
Date: 12/29/04
- Next message: mboizeau_at_free.fr: "Re: Strange encoding behaviour"
- Previous message: oraclevsmicrosoft: "C# code generation"
- In reply to: Jim: "Re: C# Large Font Small Font Bug???? Fix???"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 29 Dec 2004 13:48:41 GMT
I am going to guess. I do not know for certain, but it is possible that the
.Width value of the panel returns the wrong value when you've changed from
one font size to another, due to the use of the AutoScaleBaseSize method in
the form load. This may be self-correcting. After the resize event, the
Width value may be updated to a good value.
My concern is that I'm not sure why you are doing this:
SizeF sf = Form.GetAutoScaleSize (this.Font);
this.AutoScaleBaseSize = sf.ToSize ();
this.AutoScale = true;
You are getting the size of the form based on the size of the base font for
the form, (which may trigger the resize event before the form even paints),
and THEN you are setting the Autoscale property to true, which will have the
exact same (desired) effect when the form paints. I haven't played with
these methods very much, but the first two lines seem counterintuitive.
Also:
There's something interesting to note about your event code... if the .Width
value of the panel is small enough, your factor 'n' goes to zero. You never
check. This may happen since you have autoscale to true and the form hasn't
painted yet (see the above code).
All of the following mathematical operations that follow will produce
exceptions (divide by zero), and you have no try-catch block.
That's a pretty sure-fire way to kill an app.
I'd suggest a couple of things:
First: change the datatype of 'n' from int to float. Your numbers will be
more accurate and you are far less likely to drop to zero.
Second: add a check: if (n < 1). This will catch the zero condition as well
as the mathematical anomolies that would occur if you divide by a fraction.
Third: put in a try-catch statement. In the check above and in the catch
statement, use a different method of spacing your controls (thumbnail
images?) that doesn't depend on the width parameter.
I hope this helps
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Jim" <mp3dontspammesupport@wi99.riverr.com> wrote in message
news:43rAd.66470$NO5.39832@twister.rdc-kc.rr.com...
> My code in frmMain resize event is:
>
> private void frmMain_Resize(object sender, System.EventArgs e)
>
> {
>
> int n;
>
> n=pnlMain.Width/110;
>
> for(int i=0; i<Thumb.Count; i++)
>
> {
>
> //relocate thumbs in panel
>
> thumb[i].Top = 10+10*(i/n)+100*(i/n);
>
> thumb[i].Left = 10*((i%n)+1)+ 20 + 100*(i%n);
>
> }
>
> }
>
>
>
>
>
> Our
>
> autosize
>
> code in frmmain is: public frmMain()
>
> {
>
> //
>
> // Required for Windows Form Designer support
>
> //
>
> InitializeComponent();
>
> SizeF sf = Form.GetAutoScaleSize (this.Font);
>
> this.AutoScaleBaseSize = sf.ToSize ();
>
> this.AutoScale = true;
>
> //
>
> // TODO: Add any constructor code after InitializeComponent call
>
> //
>
> }
>
>
>
> Thanks for any help you can give us!!!!
>
>
>
>
>
>
>
> "Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> wrote in message
> news:JVUzd.814147$8_6.426668@attbi_s04...
> > what code do you have in your resize event?
> >
> > --
> > --- Nick Malik [Microsoft]
> > MCSD, CFPS, Certified Scrummaster
> > http://blogs.msdn.com/nickmalik
> >
> > Disclaimer: Opinions expressed in this forum are my own, and not
> > representative of my employer.
> > I do not answer questions on behalf of my employer. I'm just a
> > programmer helping programmers.
> > --
> > "Jim" <mp3dontspammesupport@wi99.riverr.com> wrote in message
> > news:owMwd.129118$ye4.85285@twister.rdc-kc.rr.com...
> >> When I develop a project when my screen is set to small fonts, that
same
> >> project errors on frmMain Resize when I switch to Large fonts.
> >>
> >> When I develop in large fonts then it errors when the screen is
switched
> > to
> >> small fonts.
> >>
> >> Is this a bug in C#? Is there code that can fix this or what??
> >>
> >>
> >
> >
>
>
- Next message: mboizeau_at_free.fr: "Re: Strange encoding behaviour"
- Previous message: oraclevsmicrosoft: "C# code generation"
- In reply to: Jim: "Re: C# Large Font Small Font Bug???? Fix???"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|