Help with richedit based custom control for final university project

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

Hi all, I'm trying to programatically change the background color of
lines of text and running into a few difficulties, anyone got any
suggestions?

my relevant code is as follows:

public void colorLines() {
//_Paint = false; //don't want to update while we are doing
this
//loop thru lines like addText() does
//call checkColors(lineNo)
//print line
// _Paint = true; //now we update.
int curChar = 0;
for (int curLine=0; curLine < this.Lines.Length; curLine++)
{
if (this.Lines[curLine].Length > 0)
{
this.Select(curChar, this.Lines[curLine].Length);
this.SelectionBackColor =
checkColorByLine(curLine);
curChar += this.Lines[curLine].Length + 1;
this.SelectionBackColor = Color.Empty;
}
}
}

and

public Color checkColorByLine(int lineNo)
{
//search hash table for line no
//what color should that line no be?
//return LineColor
//System.Console.WriteLine("Checking Line: " + lineNo);
//System.Console.WriteLine("ColorTable Size: " +
colorTable.Count);
foreach (DictionaryEntry de in colorTable)
{
ArrayList tempArray = (ArrayList)de.Value;
for (int x = 0; x < tempArray.Count; x++)
{
if (tempArray[x].Equals(lineNo))
{
return (Color)de.Key;
}
}
}
return Color.Empty;
}

This is all done from within an extended rich text box control

What tends to happen is that more than one line of text gets colored...
I'm fairly sure I've got some broken logic or something, but I've been
staring at this code too long to work out what it is!

Cheers :)

Lee
 
See reply in microsoft.public.dotnet.languages.csharp

(note: you might want to avoid cross-posting, as it makes it very hard for
people with the same issue to trace a conversation, and leads to lots of
people replying to posts that have already been resolved - which this one
probably isn'y [yet] (at least, not to your satisfaction)...)

Marc
 
Back
Top