Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2006

Tip: Looking for answers? Try searching our database.

Help with richedit based custom control for final university project

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lee - 20 Apr 2006 11:00 GMT
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
Marc Gravell - 20 Apr 2006 11:13 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.