Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / April 2004

Tip: Looking for answers? Try searching our database.

DrawString problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johnny - 14 Apr 2004 19:11 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.