Groups | Blog | Home
all groups > vb.net controls > february 2004 >

vb.net controls : Bold AND AlignRight in DataGridCell


DraguVaso
2/13/2004 3:34:23 PM
Hi,

I'm able to set the Font in a Datagrid-Cell to Bold with
g.DrawString(Me.GetColumnValueAtRow(source, rowNum).ToString, e.TextFont,
e.ForeBrush, bounds.X, bounds.Y)

and to Align the text to Right with
MyBase.Paint(g, bounds, source, rowNum, e.BackBrush, e.ForeBrush,
e.AlignRight)

But I can't figure out how to set it to Bold AND Align Right.

Anybody knows how to do this?

Thanks a lot in advance,

Pieter

DraguVaso
2/13/2004 4:57:44 PM
Hm, I did it like this: it seems to work fine.

If e.AlignRight Then

Dim intAlign As Integer

Dim sf As StringFormat

sf = New StringFormat(StringFormat.GenericTypographic)

Dim size As SizeF

size = g.MeasureString(Me.GetColumnValueAtRow(source, rowNum).ToString,
e.TextFont, 500, sf)

intAlign = Me.DataGridTableStyle.GridColumnStyles.Item(Me._col).Width -
size.Width - 5

g.DrawString(Me.GetColumnValueAtRow(source, rowNum).ToString,
e.TextFont, e.ForeBrush, bounds.X + intAlign, bounds.Y + 2)

Else

g.DrawString(Me.GetColumnValueAtRow(source, rowNum).ToString,
e.TextFont, e.ForeBrush, bounds.X, bounds.Y + 2)

End If


Thanks for the suggestion. although I hoped to have a 'nicer' way, hehe :-)


[quoted text, click to view]

Dmitriy Lapshin [C# / .NET MVP]
2/13/2004 5:21:23 PM
Hi,

My guess is to modify the DrawString code in the PaintText override so it
can take the required alignment into account.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
AddThis Social Bookmark Button