?
Solved

Right Align a DrawString

Posted on 2004-09-20
2
Medium Priority
?
3,859 Views
Last Modified: 2007-11-27
Hi Guys,

I'm probably asking about the impossible but I'll give it a go anyway.

Can I right align a DrawString...?  I realise that it is drawn with x and y axes and is measured from the top-left hand corner of the DrawString.  The only way would probably be to make the DrawString measure from the top-righ hand corner and go right to left instead of left to right.

My code is below:          

text = "Net Sales Value"
e.Graphics.DrawString(text, printFont2, System.Drawing.Brushes.Black, 510, 230)

text = "Tax Value"
e.Graphics.DrawString(text, printFont2, System.Drawing.Brushes.Black, 610, 230)

Any suggestions?

Thanks in advance...

JK
0
Comment
Question by:jakekula
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
fulscher earned 2000 total points
ID: 12099886
JK,

Use the Graphics.MeasureString to calculate the width of the string, then offset the start position of DrawString.

Something like this:

Dim sf as SizeF

text = "Net Sales Value"
sf = MeasureString(text, printFont2)
e.Graphics.DrawString(text, printFont2, System.Drawing.Brushes.Black, 800-sf.Width, 230)

text = "Tax Value"
sf = MeasureString(text, printFont2)
e.Graphics.DrawString(text, printFont2, System.Drawing.Brushes.Black, 800-sf.Width, 230)

Hope this helps
Jan
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12100486
Hi Jakekula

it is much easier than that, just use the stringformat

        Dim recf As New RectangleF(0, 0, 300, 20)
        Dim hh As New StringFormat
        hh.Alignment = StringAlignment.Far
        g.DrawString("hello", Me.Font, New SolidBrush(Color.Black), recf, hh)

this will right align in the rectangle recf
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question