Click here to Skip to main content
12,957,007 members (58,907 online)
Rate this:
Please Sign up or sign in to vote.
I would like to type the text which have more than one font type and get the font details seperately. That is if i used three font type one is Times New Roman, second font type is Bamini (Tamil font) and third one is wingdings. The text in the richtextbox is "welcome to richtext".I applied the first font type to "welcome", second font type to "to" and third font type to "richtext". i would like to get the details of the font seperately in a string variable...I just started the code. Tell me how to implement it????
The code is
for (int iCurChar = 0; iCurChar < richTextBox1.Text.Length; iCurChar++)
               richTextBox1.Select(iCurChar, 1);
               char CurrChar = richTextBox1.Text[iCurChar];
               Color CurrColor = richTextBox1.SelectionColor;
               Font CurrFont = richTextBox1.SelectionFont;
               int iFontHeight = CurrFont.Height;
Posted 6-Jul-12 22:45pm
Updated 6-Jul-12 23:07pm
Shankar23G 7-Jul-12 7:14am
Mr. Sandeep Mewara tell me how to implement it???

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Collections;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Richtxtbx
public partial class Form1 : Form
Font CurrFont;
Color CurrColor;
string prevfont;

TextBox txtbxtext = new TextBox();
string textcolor;
int textsize;
string xml;

FontDialog f = new FontDialog();
ColorDialog c = new ColorDialog();

TextWriter tw = new StreamWriter("test.txt");

public Form1()

prevfont = f.Font.ToString();
private void button1_Click(object sender, EventArgs e)
for (int iCurChar = 0; iCurChar < richTextBox1.Text.Length; iCurChar++)
richTextBox1.Select(iCurChar, 1);
char CurrChar = richTextBox1.Text[iCurChar];
CurrFont = richTextBox1.SelectionFont;
CurrColor = richTextBox1.SelectionColor;
int iFontHeight = richTextBox1.SelectionFont.Height;
char tempchar = CurrChar;
if (prevfont == richTextBox1.SelectionFont.ToString())
string[] temp = prevfont.Split(',');
string s = temp[0].Substring(12);
xml = "" + txtbxtext.Text + "";
txtbxtext.Text = "";
prevfont = richTextBox1.SelectionFont.ToString();
private void button2_Click(object sender, EventArgs e)

if (f.ShowDialog() == DialogResult.OK)
richTextBox1.SelectionFont = f.Font;


private void button3_Click(object sender, EventArgs e)
if (c.ShowDialog() == DialogResult.OK)
richTextBox1.SelectionColor = c.Color;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,924
CHill60 3,550
Maciej Los 3,312
ppolymorphe 2,120
Jochen Arndt 1,973

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 13 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100