Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hi there,

I'm looking for a way to display very long text lines in some kind of a text box. It's for a scripting/macro language for binary data patterns. It handles very simple macros to define a data stream, together with some sequencing features. However, my program allows to expand part of the macros into the final data stream, then editing the script again (e.g. to insert bit errors for debugging purposes). Here comes the trouble: the expanded macros can lead to very long code lines, exceeding the possibilities of a TextBox or RichTextBox.

Yep, I could butcher the code down into shorter lines, but that's not what I want. If the user defines a two-line-code leading to one megabit of binary data, he gets one megabit of binary data. And he gets it in a text editor, since there is more semantics remaining he might want to edit.

Editing this with a TextBox doesn't work, because that control wraps very long lines, even if WordWrap is set to false. A RichTextBox has the same behavior, although it has a larger threshold before it wraps too long lines.

The wrapping leads to incorrect line numbers, because every wrapped line has a new line number. I need the line numbers to tell the user where to look for syntax errors.

I tried Fireball an ScintillaNet, but both seem to be buggy, especially with that long text lines.

Does anybody have an idea? A fix for TextBox or RichTextBox, or a working editor component with no word-wrapping at all, or at least with correct line number after wrapping? Syntax Highlighting would also be cool, but that's not urgent.

If it's a component/control, I need it with a license that allows to use it in a commercial product (so no GPL).
Posted
Updated 22-Feb-11 21:30pm
v2

This is very strange requirement. I think you may want to think your approach. Simply showing very long line may not be the ideal case.

As far are solution, either you have to look for 3rd part control or curve out your own control. I have not worked much with C# in the windows ( most is service, back end processing and asp.net). But I have done a lot of windows in C++. If this was C++ then the solution is to sub class your own window from CWnd or one of the base views. I am not sure sub classing TextBoxBase based may do you much. Again I am not talking from hard evidence. Look if there is higher "window" object you can sub class or create your own window control.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Feb-11 14:05pm    
I agree about strangeness and idea to rethink the approach.
This is exactly what I advised, gave a particular idea of different presentation.
(By the way, I did something like that.)
--SA
Espen Harlinn 25-Feb-11 11:29am    
Good advice, my 5
Yusuf 25-Feb-11 12:01pm    
Thanks
Perhaps you should simply write yourself a custom control to display the text as you need it. Probably you can derive your own control from TextBox and then override the method where the text lines are drawn. This is not very much work in Windows Forms and the control will then do exactly what you want.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Feb-11 12:29pm    
Basically, good answer, my 5.
A little problem is TestBox class. Normally, if such sub-classing is recommended, base class should be TextBoxBase. But it won't give you any effect (compared to just using TextBox), because OP is not satisfied with its basic behavior. So, one should derive from Control.
--SA
[no name] 22-Feb-11 12:49pm    
Thank you. Sorry, I did not have the time at work to take a closer look at the TextBox class in the MSDN. I hoped we could retain most of the basic behavior and have a little less to do.
I did not work with WinForms for quite a while and at the moment I'm writing my own IDE for XNA / DirectX,
I do have one idea, but it depends on the structure of your macro.

First of all, this is a strange macro language which uses long line. Let's consider, it's given.
This is the text-base language which is not designed to be use by normal text editors (which is sloppy, anyway), otherwise you would not

It simply means that a long line is a really big unit of code. You don't want to scroll this long line to access it, this is extremely inconvenient. You need to change the presentation and go away from text-editor look and feel. This is just a motivation.

Why not adding a visually apparent structure to the language presentation (not language itself)?
If the line is a long unit, it should have finer structure. Parse the line into sub-units, semantically, using the language syntax. Let's assume you got two-level structure: one line is one unit, with sub-units.

Now you can present it in a TreeView, each top-level node representing a single line, next-level node representing a sub-unit in the line. You can make deeper structure, depending on macro-language syntax.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900