TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Stephen Walsh
NA
15
15.5k
Display font dialog size from FontDialog into combo box
Apr 16 2013 5:39 AM
Sorry if this is a little confusing. I am quite new to c#. I am creating a text editor & I have hit a problem using a font dialog & selecting size. Basically I want the font family & size selected in the font dialog to be displayed in 2 combo boxes. I have managed to do this with the family but not the size.
Here is my code:
private void tsbtnChooseFont_Click(object sender, EventArgs e)
{
using (FontDialog fdlg = new FontDialog())
{
if (txtMain.SelectionFont != null)
if (fdlg.ShowDialog() == DialogResult.OK)
{
txtMain.SelectionFont = fdlg.Font;
tscmbFont.Text = ""; // clear text before adding new
tscmbFont.SelectedText = fdlg.Font.FontFamily.Name.ToString();
tscmbFontSize.Text = "";
tscmbFontSize.SelectedText = fdlg.Font.Size.ToString();
}
}
}
The names are pretty self explanatory but I will explain anyway.
txtMain is the richtextbox to type in
tscmbFont is the combo box which displays the font family
tscmbFontSize is the combo box which displays the font size.
I'm guessing the problem lies with the line "tscmbFontSize.SelectedText = fdlg.Font.Size.ToString();" for example when size 14 is selected the box displays 25 & when size 16 is selected the box displays 75.
Any help would be appreciated. Thanks in advance.
Reply
Answers (
3
)
Generate HTML string from an XML
hand cursor - datagridview cell