Reputation: 24470
I need to create a text editing control in C# and I'm not sure where to start.
For a bit of context: a C# program is going to edit an XML document (using this control). The XML document can be converted to HTML.
The XML document will contain the following:
I want this control to take the XML and render it and act as an WYSIWYG editor for the XML.
For the moment, I'm not to concerned about implementing all the above details (although they will need to be implemented eventually), I just want to know where to start with creating this control. Should I be inheriting from TextBoxBase (or TextBox) and going from there? And what methods would I need to override? Or should I inherit from Control (in which case I think I'd need to all the text box stuff - selecting text, copy and paste, the caret etc. - myself, which is something I don't really want to do, but I am prepared to do if I have to).
I am aware of preexisting controls like TX Text Control that do something like what I want (although this one is far more powerful than I need), but I can't use these (this is for a university project), and besides, I really do want to know how to make this from scratch.
Upvotes: 1
Views: 4156
Reputation: 56123
Should I be inheriting from TextBoxBase (or TextBox) and going from there?
You can't inherit from TextBoxBase (its constructor is internal
).
So you can inherit from TextBox or from Control or UserControl.
The problem with TextBox is that its painting is done by unmanaged code, which isn't overridden when you override OnPaint. For further details, see this question, answer and comments.
I am aware of preexisting controls like TX Text Control that do something like what I want
The TX Text Control is something else: it's implemented using Win32 code, with a .NET wrapper/API.
Upvotes: 2
Reputation: 31743
The topic of creating a feature rich edition control with syntax highlighting, code completion, etc. has been discussed by the developers of #develop in their book "dissecting a C# Application"
http://www.icsharpcode.net/OpenSource/SD/InsideSharpDevelop.aspx
(I think you can't buy it anymore, the link says it's available for free to download but the links seems to be broken)
The book basically explain the core features of #develop (pre V1, so it's kinda outdated), including the code editor and (what is important, too) which mistakes they made during the process.
Upvotes: 2
Reputation: 576
A few years ago I used the excellent open source Scintilla editor as a base to derive a custom C# control from. Worked great. Nowadays it's even easier if you leverage the ScintellaNET project (CodePlex) which has already done the wrapper work for you. Of course, if you don't mind paying, you can't go wrong with Actipro's SyntaxEditor.
Upvotes: 0
Reputation: 6335
Inheriting from Control
will require lots of work, such as painting, implementing default behaviour, etc..
I think you can start with studying RichTextBox control because all of your requirements can be done by changing RichtextBox control.
Upvotes: 0