Tab representation in Richtextbox
Posted on 2000-05-17
Help! I have created my own editor using a Richtextbox control and have hit a snag that may put a serious dent in the whole project. The thing is, the editor is to be used for writing Cobol- and as you may know, column spacing is critical. When text is inserted into the Richtextbox by either pasting or by the loadfile method, tab characters occupy the same width as 7 spaces (with courier font) as opposed to 8 spaces with your conventional textbox. I could punt and revert back to a standard textbox, but I would then lose all of the cool "colored reserved word" tricks I have come up with. Changing fonts helps slightly, but things just don't line up. Once again, the idea is that multiple lines (some of which contain tabs, and some of which contain spaces) will visually "line up" in the Richtextbox- then after the contents are saved and reopened with a conventional editor such as notepad, things are skewed all over the place. I am suprised no one has ever talked about this issue.I have found one fix that works- it is... Richtextbox1.seltabs(0) = 8. Using this line prior to loading a file works good for me and others on NT, but the people who I have forewarded the .exe to (who are using windows 2000) have experienced this error: invalid property array index. As it sits, my new app. will not be win2k compliant. I also checked the richtextbox ocx's and they were the same version. This is my first post to this bbs, so I look foreward to any and all input.
In win2k I can add this line:
text1(0).SelTabCount = 1
'before this line
text1(0).SelTabs(0) = 8
and the error goes away, and the first tab gets converted
to 8 spaces... BUT- subsequent tabs are STILL 7 spaces.
Same for fixedsys font. Using text1(0).SelTabs(1) = 8
before loading a file causes the same error. It looks as
though I will have to loop through and deal with the tabs
individually if I can't find an answer. Its really got me
stumped. One other note- I have used the EM_SETTABSTOPS
api with good results on a regular text box, but the
Richtextbox doesn't want to respond to that call. I am
determined to figure this out!
Thanks for the ideas, Mike