Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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
Updated 6-Jul-12 23:07pm
v2
Comments
Shankar23G 7-Jul-12 7:14am    
Mr. Sandeep Mewara tell me how to implement it???

1 solution

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()
{
InitializeComponent();

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())
{
txtbxtext.AppendText(CurrChar.ToString());
}
else
{
string[] temp = prevfont.Split(',');
string s = temp[0].Substring(12);
xml = "" + txtbxtext.Text + "";
MessageBox.Show(xml);
txtbxtext.Text = "";
txtbxtext.AppendText(tempchar.ToString());
}
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;
}
}
}
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900