populating combobox

C

Chris

Hi,

I need a combobox populated with system fonts and was wondering if the
following would be adequate:

Declare

"FontFamily[] ff = FontFamily.Families;"

as a form member.

In form constructor populate combo box as follows:

"for (int i = 0; i < ff.Length; i++)
{
comboBox1.Items.Add(ff.Name);
}"

and then event in combobox:

"richTextBox1.SelectionFont = new Font(comboBox1.Text, comboBox2.Text);"

Does the above present any problems I should know about?

Would using something like:

"ff[x].IsStyleAvailable(FontStyle.Regular))"

check if the font is available in the stated format on the users machine?

Any help would be greatly appreciated.


Chris
 
C

Chris

Ok I've done the following:

if (ff.IsStyleAvailable(FontStyle.Bold) &&

ff.IsStyleAvailable(FontStyle.Italic) &&

ff.IsStyleAvailable(FontStyle.Regular) &&

ff.IsStyleAvailable(FontStyle.Strikeout) &&

ff.IsStyleAvailable(FontStyle.Underline))

{

comboBox1.Items.Add(ff.Name);

}

So the combobox is only populated with fonts valid in all styles?

Then I overrode the draw method of the combobox so it displays the font
names in the font type:

private void comboBox1_Draw(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
if (comboBox1.Items.Count > 0)
{
for (int i = 0; i <= e.Index; i++)
{
e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(),
new
System.Drawing.Font(comboBox1.Items[e.Index].ToString(), 8),
System.Drawing.Brushes.Black,
e.Bounds);
}
}

}

Is this a valid way of doing this? Should I be aware of any potential
problems or exceptions? Sorry if these are basic questions, but I've only
been learning C# for the past week or so, so any help is appreciated.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top