[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Right Align a DrawString

Posted on 2004-09-20
2
Medium Priority
?
4,002 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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