473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to dynamically build font...?

Tim
Hi Guys,

I want to build a font like so:
headerFont = new Font("Times New Roman", 10, FontStyle.Underline |
FontStyle.Bold);

It is going to be built dynamically from the DB. How do I build the styles
dynamically. In the above example it has underline and bold, it could also
have italics, or none of them, or a different combination.

How do I build that in code? I guess it is the pipe character which is
throwing me off.

Thanks,

Tim
Nov 17 '05 #1
6 3532
Tim
I think I found out the solution already. Didn't realize I could just set
headerFont.Bold = true.

Duh!

Tim

"Tim" <ti*@home.com> wrote in message
news:SG*******************@news20.bellglobal.com.. .
Hi Guys,

I want to build a font like so:
headerFont = new Font("Times New Roman", 10, FontStyle.Underline |
FontStyle.Bold);

It is going to be built dynamically from the DB. How do I build the styles
dynamically. In the above example it has underline and bold, it could also
have italics, or none of them, or a different combination.

How do I build that in code? I guess it is the pipe character which is
throwing me off.

Thanks,

Tim

Nov 17 '05 #2
Tim
Okay - apparently, I can't just set headerFont.Bold = true as it is read
only, so that leaves me back where I started.

Help!

Tim

"Tim" <ti*@home.com> wrote in message
news:5J*******************@news20.bellglobal.com.. .
I think I found out the solution already. Didn't realize I could just set
headerFont.Bold = true.

Duh!

Tim

"Tim" <ti*@home.com> wrote in message
news:SG*******************@news20.bellglobal.com.. .
Hi Guys,

I want to build a font like so:
headerFont = new Font("Times New Roman", 10, FontStyle.Underline |
FontStyle.Bold);

It is going to be built dynamically from the DB. How do I build the
styles dynamically. In the above example it has underline and bold, it
could also have italics, or none of them, or a different combination.

How do I build that in code? I guess it is the pipe character which is
throwing me off.

Thanks,

Tim


Nov 17 '05 #3
Tim wrote:
Hi Guys,

I want to build a font like so:
headerFont = new Font("Times New Roman", 10, FontStyle.Underline |
FontStyle.Bold);

It is going to be built dynamically from the DB. How do I build the
styles dynamically. In the above example it has underline and bold,
it could also have italics, or none of them, or a different
combination.
How do I build that in code? I guess it is the pipe character which is
throwing me off.

Thanks,

Tim


Fisrt build the FontStyle in a separate variable, *then* use it in the Font constructor.

FontStyle fs = FontStyle.None; // I'm guessing here
if (useBold)
fs = fs | FontStyle.Bold; // or shorter: fs |= FontStyle.Bold;
if (useUnderline)
fs = fs | FontStyle.Underline;
// etc.

headerFont = new Font("Times New Roman", 10, fs);
Hans Kesting
Nov 17 '05 #4
Tim,

Use the FontConverter class in the System.Drawing namespace. It will
convert a font to a string representation, and back to a Font again, with
the appropriate point size, styles, etc, etc. The output of FontConverter
would be what you store in your database (or construct from your database,
but its easier to just store the value it outputs).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <ti*@home.com> wrote in message
news:SG*******************@news20.bellglobal.com.. .
Hi Guys,

I want to build a font like so:
headerFont = new Font("Times New Roman", 10, FontStyle.Underline |
FontStyle.Bold);

It is going to be built dynamically from the DB. How do I build the styles
dynamically. In the above example it has underline and bold, it could also
have italics, or none of them, or a different combination.

How do I build that in code? I guess it is the pipe character which is
throwing me off.

Thanks,

Tim

Nov 17 '05 #5
Tim
Thank you Nicholas, I don't suppose you have an example do you?

Tim

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oy**************@TK2MSFTNGP14.phx.gbl...
Tim,

Use the FontConverter class in the System.Drawing namespace. It will
convert a font to a string representation, and back to a Font again, with
the appropriate point size, styles, etc, etc. The output of FontConverter
would be what you store in your database (or construct from your database,
but its easier to just store the value it outputs).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <ti*@home.com> wrote in message
news:SG*******************@news20.bellglobal.com.. .
Hi Guys,

I want to build a font like so:
headerFont = new Font("Times New Roman", 10, FontStyle.Underline |
FontStyle.Bold);

It is going to be built dynamically from the DB. How do I build the
styles dynamically. In the above example it has underline and bold, it
could also have italics, or none of them, or a different combination.

How do I build that in code? I guess it is the pipe character which is
throwing me off.

Thanks,

Tim


Nov 17 '05 #6
Tim,

This is from the documentation for the FontConverter class. It shows
you how to get a converter for the font, as well as get the string for a
particular font:

private void ShowFontStringConversion(PaintEventArgs e)
{

// Create the FontConverter.
System.ComponentModel.TypeConverter converter =
System.ComponentModel.TypeDescriptor.GetConverter( typeof(Font));

Font font1 = (Font) converter.ConvertFromString("Arial, 12pt");

string fontName1 = converter.ConvertToInvariantString(font1);
string fontName2 = converter.ConvertToString(font1);

e.Graphics.DrawString(fontName1, font1, Brushes.Red, 10, 10);
e.Graphics.DrawString(fontName2, font1, Brushes.Blue, 10, 30);
}

To convert from a string to an object, it's easy, just call the
ConvertFromInvariantString (you want to store these, as they are not
locale-specific):

Font f = (Font) fc.ConvertFromInvariantString(s);

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Tim" <ti*@home.com> wrote in message
news:0e*******************@news20.bellglobal.com.. .
Thank you Nicholas, I don't suppose you have an example do you?

Tim

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oy**************@TK2MSFTNGP14.phx.gbl...
Tim,

Use the FontConverter class in the System.Drawing namespace. It will
convert a font to a string representation, and back to a Font again, with
the appropriate point size, styles, etc, etc. The output of
FontConverter would be what you store in your database (or construct from
your database, but its easier to just store the value it outputs).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <ti*@home.com> wrote in message
news:SG*******************@news20.bellglobal.com.. .
Hi Guys,

I want to build a font like so:
headerFont = new Font("Times New Roman", 10, FontStyle.Underline |
FontStyle.Bold);

It is going to be built dynamically from the DB. How do I build the
styles dynamically. In the above example it has underline and bold, it
could also have italics, or none of them, or a different combination.

How do I build that in code? I guess it is the pipe character which is
throwing me off.

Thanks,

Tim



Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Patrick.O.Ige | last post by:
I have a code below and its a PIE & BAR CHART. The values now are all static but I want to be able to pull the values from a database. Can you guys give me some ideas to do this? Thanks ...
1
by: dx | last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as simple as setting oCheckBox.Checked = True.. yet for some reason it isn't. I have a user control (ascx) that that has a...
3
by: SD | last post by:
Hello, I have a form that has a panel container where I'm adding textboxes dynamically based on a query to database, so I'm looping through the records. The problem I have is that once built,...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: uncensored | last post by:
Hi, Sort of new with the whole treeview control and I was wondering is there a way to build a treeview menu using my SQL data I pull from a database instead of having to hard code it into the...
4
windows_mss
by: windows_mss | last post by:
When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map... hi, i can able to get the Correct Route and Path for the corresponding Source and destination, like...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
4
by: .Net Sports | last post by:
I need to dynamically assign a datalist attribute upon a helper function receiving data from a querystring. If a user picks a certain region, i need the datalist to display its back color, or any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.