Click here to Skip to main content
15,903,523 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with String.Replace() Pin
Judah Gabriel Himango23-Aug-07 6:55
sponsorJudah Gabriel Himango23-Aug-07 6:55 
GeneralRe: Problem with String.Replace() Pin
Gump61923-Aug-07 7:14
Gump61923-Aug-07 7:14 
GeneralRe: Problem with String.Replace() Pin
Judah Gabriel Himango23-Aug-07 8:00
sponsorJudah Gabriel Himango23-Aug-07 8:00 
GeneralRe: Problem with String.Replace() Pin
Gump61923-Aug-07 8:08
Gump61923-Aug-07 8:08 
AnswerRe: Problem with String.Replace() Pin
Chase Davis23-Aug-07 7:08
Chase Davis23-Aug-07 7:08 
GeneralRe: Problem with String.Replace() Pin
Gump61923-Aug-07 7:16
Gump61923-Aug-07 7:16 
Questionregistry - create printer - redirect port Pin
HarryFlodder23-Aug-07 4:58
HarryFlodder23-Aug-07 4:58 
QuestionRichTextBox Formatting Help Pin
solutionsville23-Aug-07 3:46
solutionsville23-Aug-07 3:46 
Ok, I know it is long...

In an OpenFile() routine I am trying to change the color on the text of a file at a specific position, and do this prior to it loading into a RichTextBox.Text property. I can do this with the findSequenceNumbers() routine below;

If I do it after it loads by using the findSequenceNumbers() routine it takes about 3 - 4 minutes dpending on the file size as it scrolls thru the text box.

I want to perform this formatting using the RichTextBox.RTF property however I do not understand it, nor do I understand where I would fit it in. I did create the file and save it after I formatted it as an RTF document and when I open it in a text editor this is what is at the top;

{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}
{\colortbl ;\red0\green0\blue139;}
\viewkind4\uc1\pard\lang1033\f0\fs20

A formatted line with the color change looks like this;

2007/08/13 14:00:03 [144007]ARES_EINDICATION 010.050.016.010 420.1.01 (6901) RX 68 bytes 69 01 26 02 28 A4 AA 20 76 96 51 44 50 76 08 45 46 00 34 02 02 C7 88 \cf1\b 01\cf0\b0 C7 88 AA 50 76 08 45 46 20 76 96 51 44 D7 07 08 0D 0D 3B 3B 00 00 10 06 0A 06 06 06 06 06 06 0A 0A 06 06 06 06 0A 0A 9B 67 5F 91 F8 \par


-------------------------------------------
private void OpenFile()
{
try
{
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
{
string strExt;
strExt = System.IO.Path.GetExtension(OpenFileDialog.FileName);
strExt = strExt.ToLower();

if (OpenFileDialog.FileName == "")
{
return;
}
switch (strExt)
{
default:
if (strExt == ".rtf")
{
rtbDoc.LoadFile(OpenFileDialog.FileName, RichTextBoxStreamType.RichText);
}
else
{
StreamReader rtfReader;
rtfReader = new StreamReader(OpenFileDialog.FileName);
rtbDoc.Text = rtfReader.ReadToEnd();
rtfReader.Close();
rtfReader = null;
rtbDoc.SelectionStart = 0;
rtbDoc.SelectionLength = 0;
}
break;

case ".dat":
rtbDoc.Text = Streamer.LayoutInput(OpenFileDialog.FileName);
break;
}
currentFile = OpenFileDialog.FileName;
rtbDoc.Modified = false;
this.Text = "Train Control Editor: " + currentFile.ToString();
}
else
{
MessageBox.Show("Open File request cancelled by user.", "Cancelled");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error");
}
}

-------------------------------------------
private void findSequenceNumbers()
{
toolStripStatusLabel.Visible = toolStripProgressBar.Visible = true;
toolStripProgressBar.Value = 0;
int lineNum = 0;
bool startingNewLine = true;
FontStyle style = FontStyle.Bold;
string[] lines = rtbDoc.Lines;
string text = rtbDoc.Text;
toolStripProgressBar.Maximum = text.Length;
for (int i = 0; i < text.Length; i++)
{
if (startingNewLine)
{
if ((lines[lineNum].Contains("ARES_EINDICATION")) || (lines[lineNum].Contains("ARES_INDICATION")))
{
i += 169;

rtbDoc.Select(i, 2);
rtbDoc.SelectionFont = new Font(rtbDoc.SelectionFont, rtbDoc.SelectionFont.Style ^ style);
rtbDoc.SelectionColor = Color.DarkBlue;
}
else if (lines[lineNum].Contains("]CODELINE_INDICATION_MSG"))
{
i += 160;
rtbDoc.Select(i, 2);
rtbDoc.SelectionFont = new Font(rtbDoc.SelectionFont, rtbDoc.SelectionFont.Style ^ style);
rtbDoc.SelectionColor = Color.DarkBlue;
}
else
{
i += lines[lineNum].Length - 1;
}
startingNewLine = false;
Application.DoEvents();
}
if (text[i] == '\n')
{
startingNewLine = true;
lineNum++;
}
toolStripProgressBar.Value = i;
}
toolStripStatusLabel.Visible = toolStripProgressBar.Visible = false;
rtbDoc.Select(0, 0);
rtbDoc.ScrollToCaret();
}
--------------------------------------------------


Thanks,

Brian
AnswerRe: RichTextBox Formatting Help Pin
mav.northwind23-Aug-07 4:04
mav.northwind23-Aug-07 4:04 
AnswerRe: RichTextBox Formatting Help Pin
solutionsville23-Aug-07 4:32
solutionsville23-Aug-07 4:32 
AnswerRe: RichTextBox Formatting Help Pin
Big Daddy Farang23-Aug-07 7:35
Big Daddy Farang23-Aug-07 7:35 
AnswerRe: RichTextBox Formatting Help Pin
solutionsville23-Aug-07 7:44
solutionsville23-Aug-07 7:44 
QuestionUser credentials cannot be used for local connections Pin
abhishek.mumbai23-Aug-07 3:41
abhishek.mumbai23-Aug-07 3:41 
AnswerRe: User credentials cannot be used for local connections Pin
SfBf2-Nov-09 16:47
SfBf2-Nov-09 16:47 
QuestionVS 2003 to VS 2005 migration problems Pin
Abhi Lahare23-Aug-07 3:38
Abhi Lahare23-Aug-07 3:38 
AnswerRe: VS 2003 to VS 2005 migration problems Pin
Paul Conrad26-Aug-07 9:23
professionalPaul Conrad26-Aug-07 9:23 
QuestionString Formate Pin
Thaer Hamael23-Aug-07 3:27
Thaer Hamael23-Aug-07 3:27 
AnswerRe: String Formate Pin
snorkie23-Aug-07 3:40
professionalsnorkie23-Aug-07 3:40 
GeneralRe: String Formate Pin
Keith Barrow23-Aug-07 3:52
professionalKeith Barrow23-Aug-07 3:52 
GeneralRe: String Formate Pin
DavidNohejl23-Aug-07 4:07
DavidNohejl23-Aug-07 4:07 
AnswerRe: String Formate Pin
Keith Barrow23-Aug-07 3:44
professionalKeith Barrow23-Aug-07 3:44 
AnswerRe: String Formate Pin
Martin#23-Aug-07 4:00
Martin#23-Aug-07 4:00 
AnswerRe: String Formate Pin
CCosgrove8123-Aug-07 7:08
CCosgrove8123-Aug-07 7:08 
QuestionAbout Httpwebrequst & response Pin
Dipti D Jadhav23-Aug-07 2:56
Dipti D Jadhav23-Aug-07 2:56 
QuestionGive me an idea about image processing Pin
greekius23-Aug-07 2:53
greekius23-Aug-07 2:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.