Windows Develop Bookmark and Share   
 index > Windows Forms General > Help creating a changing text size button?
 

Help creating a changing text size button?

I want a button like the one in microsoft word 2003 that will change the font size of the text I select in my textbox.

When i click the arrow of the box I would like several options to pop up. I have the button, but I don't know where to start with the code. If I could have help with this, it would be much appreciated.

TheTrueFace  Monday, December 24, 2007 8:30 PM
TheTrueFace wrote:

And why is there a combo box 2 involved in this????? IM LOST!!



Didn't you say that you want to have two ComboBoxes?? As your post said like this:

TheTrueFace wrote:

Yea something like that, but I'm not quite sure how to set that up. I would like to have two combo boxes though. One for the font style and one for the font size.

Zhi-Xin Ye  Friday, December 28, 2007 4:09 AM
something like:

create a comboBox with dropdownstyle DropDown,

change your font size with

myLabel.Font = new Font( myLabel.Font.FontFamily, newFontSize);

when SelectedValueChanged and it's valid numeric value, change your font size like above.

TheTrueFace wrote:

I want a button like the one in microsoft word 2003 that will change the font size of the text I select in my textbox.

When i click the arrow of the box I would like several options to pop up. I have the button, but I don't know where to start with the code. If I could have help with this, it would be much appreciated.

H. _冬_ Tony  Monday, December 24, 2007 8:41 PM

Yea something like that, but I'm not quite sure how to set that up. I would like to have two combo boxes though. One for the font style and one for the font size.

TheTrueFace  Monday, December 24, 2007 8:52 PM

You can do something like this


Code Block

void Form9_Load(object sender, EventArgs e)

{

//Font style

System.Drawing.FontFamily[] families = new

System.Drawing.Text.InstalledFontCollection().Families;

foreach (FontFamily ff in families)

{

this.comboBox1.Items.Add(ff.Name);

}

this.comboBox1.SelectedIndex = 0;

//Font size

this.comboBox2.Items.Add(8);

this.comboBox2.Items.Add(9);

this.comboBox2.Items.Add(10);

this.comboBox2.Items.Add(11);

this.comboBox2.Items.Add(12);

this.comboBox2.Items.Add(14);

this.comboBox2.Items.Add(16);

this.comboBox2.Items.Add(18);

this.comboBox2.Items.Add(20);

this.comboBox2.Items.Add(22);

this.comboBox2.Items.Add(24);

this.comboBox2.Items.Add(26);

this.comboBox2.Items.Add(28);

this.comboBox2.Items.Add(36);

this.comboBox2.Items.Add(48);

this.comboBox2.Items.Add(72);

this.comboBox2.SelectedIndex = 0;

this.comboBox1.SelectedIndexChanged +=

new EventHandler(comboBox_SelectedIndexChanged);

this.comboBox2.SelectedIndexChanged +=

new EventHandler(comboBox_SelectedIndexChanged);

}

void comboBox_SelectedIndexChanged(object sender, EventArgs e)

{

this.richTextBox1.Focus();

this.richTextBox1.SelectionFont =

new Font(this.comboBox1.SelectedItem.ToString(),

float.Parse(this.comboBox2.SelectedItem.ToString()));

}

Zhi-Xin Ye  Tuesday, December 25, 2007 2:50 PM

why did you give me two combo boxes??

and when I type in all of my names and all, I get this one error.

Error1'System.Windows.Forms.TextBox' does not contain a definition for 'SelectionFont' and no extension method 'SelectionFont' accepting a first argument of type 'System.Windows.Forms.TextBox' could be found (are you missing a using directive or an assembly reference?)C:\Documents and Settings\Donovan\My Documents\Visual Studio 2008\Projects\Hidden Note\HiddenNote.cs40729Hidden Note
TheTrueFace  Wednesday, December 26, 2007 4:56 AM
The code I provided above is for RichTectBox control, NOT TextBox, however, the TextBox does NOT have a "SelectionFont" property anditdoes NOT support multiple font, if you wantmultiple font in the text, aRichTextBox control is more suitable.
Zhi-Xin Ye  Wednesday, December 26, 2007 10:35 AM

I'm using a rich text box........ I still get the error

TheTrueFace  Friday, December 28, 2007 4:01 AM

What's the error you come with RichTextBox?

Zhi-Xin Ye  Friday, December 28, 2007 4:04 AM

And why is there a combo box 2 involved in this????? IM LOST!!

TheTrueFace  Friday, December 28, 2007 4:04 AM
TheTrueFace wrote:

And why is there a combo box 2 involved in this????? IM LOST!!



Didn't you say that you want to have two ComboBoxes?? As your post said like this:

TheTrueFace wrote:

Yea something like that, but I'm not quite sure how to set that up. I would like to have two combo boxes though. One for the font style and one for the font size.

Zhi-Xin Ye  Friday, December 28, 2007 4:09 AM

Ok never mind, I figured it out, sorry and thanks...

TheTrueFace  Friday, December 28, 2007 4:17 AM

You can use google to search for other answers

Custom Search

More Threads

• win apps + Web Browser control
• possible/how to identify when WebBrowser scrollbars are disabled?
• Please help on how to select multiple checkboxes in C#
• To retrieve all the open windows Title
• draw filled rectangle
• Class : Methods : Controls
• formatting numbers in DataGridview
• Individually Align DataGridView Column Headers?
• datagrid repaint problem
• Threading problems with Sys Tray Application,