[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Problem with Graphics.DrawString() method...

Posted on 2004-09-10
13
Medium Priority
?
214 Views
Last Modified: 2008-02-01
Hi Experts,
   
         I am facing a problem with Graphics.DrawString() method.
My Requirment is to write numbers which are right aligned..
e.g.
Items      Price
Item1           34.00
Item2         551.00
Item3        5678.00
Item4            5.00
Item5       3000.00
Item6       4567.00

But I am not able to print it this way, I tried with most of the combination of StringFormat class
e.g.

StringFormat objSF = new StringFormat(StringFormatFlags.DirectionRightToLeft);
objSF.Alignment = StringAlignment.Far;  
                  
Can somebody tell me how to takle this problem.


Thanks
Bharat




0
Comment
Question by:bharat_mane
[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
  • 7
  • 5
13 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12024299
Try this:

StringFormat objSF = new StringFormat();
objSF.Alignment = Alignment.Far;

This should be all.
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12024302
Sorry, a typo:

StringFormat objSF = new StringFormat();
objSF.Alignment = StringAlignment.Far;
0
 

Author Comment

by:bharat_mane
ID: 12024330
Thanks TheAvenger,
  but i have already tried this.
  It is not coming the way i am looking for,.
o/p comes like this

                     2
                     5
          555.00  
       5555.00            
       5555.00            
            55.00
            55.00
            55.00


can you tell me why this must be happning?

Thanks
Bharat

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:TheAvenger
ID: 12024343
Do you give the same right coordinate of the rectangle in the draw string?

I think that draw string is not the best function :-(( It really aligns things in its own way..... But for this I think it should work....
0
 

Author Comment

by:bharat_mane
ID: 12024368
Hi TheAvenger
I am specifying like this
x=50
for (i = 0; i <quantity.Length; i++)
{

      y += 20;
      g.DrawString(quantity[i],fntAddress,br1,x + 600,y,objSF);
      
}

or is there any other way i can work with is....?

Thanks
Bharat
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12024387
OK, here's the problem: you give a POINT and not a RECTANGLE. Make it like this:

x=50
int width = 100;
int height = 20;
for (i = 0; i <quantity.Length; i++)
{

     y += height;
     g.DrawString(quantity[i],fntAddress,br1, new RectangleF (x + 600, y, width, height), objSF);
}
0
 

Author Comment

by:bharat_mane
ID: 12025753
Thanks TheAvenger,
    Even this i had tried but no luck.
Still it is not coming, the way it should as right aligned. Here only difference is spacing is changing between the numbers.
I don't know why it is changing the spacing.

Is there any other way....?


Thanks
Bharat
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 200 total points
ID: 12025890
I made a small test with the following code:

SolidBrush textBrush = new SolidBrush (this.ForeColor)
string[] quantity = new string[] {"2", "5", "555.00", "5555.00", "5555.00", "55.00"};
int x=0;
int w = 100;
int h = 20;
int y = 0;
StringFormat objSF = new StringFormat();
objSF.Alignment = StringAlignment.Far;
for (int i = 0; i <quantity.Length; i++)
{

      y += h;
      e.Graphics.DrawString(quantity[i],this.Font,textBrush, new RectangleF (x, y, w, h), objSF);
}

I aligns the text perfectly on the right.
0
 

Author Comment

by:bharat_mane
ID: 12026161
Hi TheAvenger
thank you for your immediate replies.
Sorry to disturb you again and again.
But the problem is I am using third party component and it has derived class from graphics class. So I have to use that only.
By looking at your code I am bit confused from where are you referring this e.Graphics.DrawString()

Can you please tell me what is this e is it System.EventArgs e or something else.

Let me explain you clear scenario. I am trying to build PDF and for this I am using PDF n more components provided by www.rarefind.com this component has graphics class. If I am not wrong they are using most of the methods as it is.
And few of them must have been modified. I have already told them about this. They are working on it.

If this problem is related to graphics class then I apologies my mistake to take your precious time.

Thank you once again
Bharat

0
 

Author Comment

by:bharat_mane
ID: 12026198
If this problem is related to graphics class then I apologies my mistake to take your precious time.
By this line I mean   www.rarefind.com's  graphics class and not .NET's graphics class.

Thanks
Bharat


0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12026204
The code I posted is from the Paint event of the control and the argument e is of type System.Windows.Forms.PaintEventArgs. It has the current control Graphics object as a property, so I can draw in the control directly using it. So I am drawing on the screen.

Unfortunately I cannot tell you anything about this third party control. I don't know if they use the default Graphics class or have overriden all methods :-((
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12026210
No problem for the time, that's why we participate in EE, to help each other find the problems and solutions for them.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
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, …
Suggested Courses

656 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