Changing font based on data value
Changing font based on data value
Hi,
I have two linked tables in my data source, one contains row of the data I'm interested in presenting to the user, and the other conatins information on how the row should be formatted, including fontname, fontsize, bold, underline etc etc. Each row needs to have potentially unique formatting, hence the one for one relationship. Is there anyway either in dotnet or preferably in the report designer I can tell a report object to assume the font characteristics from fields within it's own data; i.e in the BeforePrintEvent can I set something like Bill.Description.Font.Bold = Bill.Font, where Bill is my datasource, descritpion if my field, and I have a field also in my datasource colled 'bold' which I want to get the value from.
Any help much appreciated,
Regards,
Jon.
I have two linked tables in my data source, one contains row of the data I'm interested in presenting to the user, and the other conatins information on how the row should be formatted, including fontname, fontsize, bold, underline etc etc. Each row needs to have potentially unique formatting, hence the one for one relationship. Is there anyway either in dotnet or preferably in the report designer I can tell a report object to assume the font characteristics from fields within it's own data; i.e in the BeforePrintEvent can I set something like Bill.Description.Font.Bold = Bill.Font, where Bill is my datasource, descritpion if my field, and I have a field also in my datasource colled 'bold' which I want to get the value from.
Any help much appreciated,
Regards,
Jon.
Changing font based on data value
Hello Jon,
Thank you.
For example you can use following code:jonellis wrote: I have two linked tables in my data source, one contains row of the data I'm interested in presenting to the user, and the other conatins information on how the row should be formatted, including fontname, fontsize, bold, underline etc etc. Each row needs to have potentially unique formatting, hence the one for one relationship. Is there anyway either in dotnet or preferably in the report designer I can tell a report object to assume the font characteristics from fields within it's own data; i.e in the BeforePrintEvent can I set something like Bill.Description.Font.Bold = Bill.Font, where Bill is my datasource, descritpion if my field, and I have a field also in my datasource colled 'bold' which I want to get the value from.
Code: Select all
#region Font
FontStyle style = (FontStyle)0;
if (Bill.FontBold)style |= FontStyle.Bold;
if (Bill.FontItalic)style |= FontStyle.Italic;
if (Bill.FontUnderline)style |= FontStyle.Underline;
float fontSize = Bill.FontSize;
string fontName = Bill.FontName;
Text1.Font = new Font(fontName, fontSize, style);
#endregion
#region TextColor
string textColor = Bill.TextColor;//"#556677";
Text1.TextBrush = new StiSolidBrush(ColorTranslator.FromHtml(textColor));
#endregion
#region BackColor
string backColor = Bill.BackColor;//"#9999AA";
Text1.Brush = new StiSolidBrush(ColorTranslator.FromHtml(backColor));
#endregion
Changing font based on data value
Vital, you are a star! That is excellent - thankyou very much.
Changing font based on data value
Please contact us if you need any help.
Changing font based on data value
Vital,
Slight problem with the code in that the bold options work, but everyting is getting set to italic & underlined also?
I actually understand VB better (a lot better!) than C#, and have tried to translate you code so I can tweak it, but I cannot get a VB version to work.
Is there any chance you could list a VB version please?
Many thanks,
Jon.
Slight problem with the code in that the bold options work, but everyting is getting set to italic & underlined also?
I actually understand VB better (a lot better!) than C#, and have tried to translate you code so I can tweak it, but I cannot get a VB version to work.
Is there any chance you could list a VB version please?
Many thanks,
Jon.
Changing font based on data value
Vital,
Scratch that. Here's my translation, which does what your C# example does.
Dim style As FontStyle = DirectCast(0, FontStyle)
If Bill.Bold Then
style = style Or FontStyle.Bold
End If
If Bill.Italic Then
style = style Or FontStyle.Italic
End If
If Bill.Underline Then
style = style Or FontStyle.Underline
End If
Dim fontSize As Single = Bill.FontSize
Dim fontName As String = Bill.Font
DataBill_Description.Font = New Font(fontName, fontSize, style)
Dim textColor As String = Bill.Colour
DataBill_Description.TextBrush = New StiSolidBrush(ColorTranslator.FromHtml(textColor))
Problem is, everything is still coming out Bold, Underlined & Italic
I am setting this code in the BeforePrint event of the databand, and have also tried adding a style = FontSyle.Regular at the top of the code. Can you help at all?
Regards,
Jon.
Scratch that. Here's my translation, which does what your C# example does.
Dim style As FontStyle = DirectCast(0, FontStyle)
If Bill.Bold Then
style = style Or FontStyle.Bold
End If
If Bill.Italic Then
style = style Or FontStyle.Italic
End If
If Bill.Underline Then
style = style Or FontStyle.Underline
End If
Dim fontSize As Single = Bill.FontSize
Dim fontName As String = Bill.Font
DataBill_Description.Font = New Font(fontName, fontSize, style)
Dim textColor As String = Bill.Colour
DataBill_Description.TextBrush = New StiSolidBrush(ColorTranslator.FromHtml(textColor))
Problem is, everything is still coming out Bold, Underlined & Italic
I am setting this code in the BeforePrint event of the databand, and have also tried adding a style = FontSyle.Regular at the top of the code. Can you help at all?
Regards,
Jon.
Changing font based on data value
Vital,
If I reset the style variable to nothing & then to regular it works fine. Thanks again for your help.
J.
If I reset the style variable to nothing & then to regular it works fine. Thanks again for your help.
J.