Coffeehouse Post

Single Post Permalink

View Thread: Comparing two TextBoxes in C# windows forms
  • User profile image

    You cannot highlight different parts of a textbox different colours, so you will need to think of a different approach to achieve your goal.

    If I were you, I'd try breaking this problem into two; firstly there's the functional problem: "Given two strings, how can I describe how they are different". This isn't necessarilly obvious, but look at something like the levenstein distance algorithm and you might get some pointers as to where to start or google for algorithms for "diff"-ing strings.

    The second problem is one of rendering the output: "Given a description of the differences between two strings (in whatever format my program provides it to me), put this on the screen in a visible way". One way you might want to consider is using a RichTextBox or outputting HTML directly into a WebBrowser control.

    Decouple these. That way you will only have two self contained and moderately hard problems to solve instead of one sprawling and really hard problem to solve. When you've finished the first problem, feed it's output into the input of the second and you'll have your total solution.