Click here to Skip to main content
Rate this: bad
good
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
Edited 6-Jul-12 23:07pm
v2
Comments
Shankar23G at 7-Jul-12 7:14am
   
Mr. Sandeep Mewara tell me how to implement it???

1 solution

Rate this: bad
good
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()
{
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;
}
}
}
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 380
1 _Amy 255
2 Richard Deeming 250
3 Nirav Prabtani 223
4 CHill60 175
0 _Amy 110
1 Maciej Los 90
2 OriginalGriff 85
3 Mehdi Gholam 80
4 Sergey Alexandrovich Kryukov 75


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 13 Jul 2012
Copyright © CodeProject, 1999-2014
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