Hi all,
I'm creating a control derived from System.Windows.Forms.Control
I override the OnPaint() method.
In this method, I need to draw a string in an area.
This area is a rectangle (called fRect)
I want to display a text centered vertically.
I used MeasureString, but the result is not always very good...
Hear is a peace of code :
...
System.Drawing.Graphics g = null;
...
g = System.Drawing.Graphics.FromHwnd( this.Handle );
...
Rectangle fRect =
new Rectangle( 0, 0, 200, 100 );
Color fColor = Color.FromArgb( 255, this.BackColor );
SolidBrush fBrush = new SolidBrush( fColor );
g.FillRectangle( fBrush, fRect );
...
SolidBrush tBrush = new SolidBrush( this.TextColor );
StringFormat tFormat = new StringFormat();
tFormat.LineAlignment = StringAlignment.Center;
tFormat.Alignment = StringAlignment.Center;
g.DrawString(
this.Text,
this.Font,
tBrush,
new Rectangle( 0, 0, fRect.Width, fRect.Height ) ,
tFormat );
Am I missing something ?
Thank you in advance !

Signature
Ceci est une signature automatique de MesNews.
Site : http://mesnews.no-ip.com
Allen Anderson - 19 Apr 2004 20:17 GMT
when you say the text is not alwys good, what exactly do you mean?
What part of it is not drawing correctly?
Allen Anderson
http://www.glacialcomponents.com
mailto: allen@put my website url here.com
>Hi all,
>
[quoted text clipped - 33 lines]
>
>Thank you in advance !
Johnny - 20 Apr 2004 15:43 GMT
When I say the text is not always good, it's mean that the text is not
exactly in the center of the rectangle...
I really can't explain why !
Allen Anderson a émis l'idée suivante :
> when you say the text is not alwys good, what exactly do you mean?
> What part of it is not drawing correctly?
[quoted text clipped - 40 lines]
>>
>> Thank you in advance !

Signature
Ceci est une signature automatique de MesNews.
Site : http://mesnews.no-ip.com