By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,493 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,493 IT Pros & Developers. It's quick & easy.

Problems with printing right aligned text.

P: n/a
Hello!

I am using a thirdparty gridcontrol which has a bug in it. It consists of
that when setting a column to be right aligned it doesn't work as it should.
The column gets rightaligned, but only for text that has the same length.
The longer the text in each cell is, the longer to the left the text is
being printed. (Take a look at this file to see what it looks like:
http://www.lowrad.net/files/grid_bug.jpg)

I contacted the support about this, but they said the solution was to
override the PaintForeground method for the cell class. I did that, and
experienced the exact same bug as with the original PaintForeground method.
Unfortunately I don't have the sourcecode for the gridcontrol, but this is
my code:

protected override void PaintForeground(Xceed.Grid.GridPaintEventArgs e)
{
if (this.HorizontalAlignment == Xceed.Grid.HorizontalAlignment.Right)
{
string text = System.Convert.ToString(this.Value);
System.Drawing.SolidBrush brush = new
System.Drawing.SolidBrush(this.ForeColor);
System.Drawing.StringFormat format = new
System.Drawing.StringFormat();
format.Alignment = System.Drawing.StringAlignment.Far;

e.Graphics.DrawString(text,this.Font,brush,e.Clien tRectangle,format);
}
else
{
base.PaintForeground(e);
}
}

Now, it suprised me that the exact same problem happened since I thought
printing the text with DrawString should do it. My question now is how the
DrawString method determines where to print the text? In my eyes it must be
using the e.ClientRectangle object and the format object combined...
Therefore I started looking at the clientrectangle's size and location each
time the PaintForeground method was called, to see if they changed. But they
don't and that's where I'm stuck. How come the alignment doesn't work? What
else than the size and location of the rectangle is used when printing text
aligned to the right?

I'm VERY thankful for help here.

/David.
Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.