Solved

Howto write symbols to a Richtextbox

Posted on 2003-11-23
11
1,878 Views
Last Modified: 2013-12-26
Hi Experts

I recently had a similar question
(/Programming/Programming_Languages/Visual_Basic/Q_20791775.html)
regarding write symbols to a word document, but due to compat. and the amount of time it takes to use the automation, I have chosen to use a RTB and saving it as .rtf - but my problem is:
How do I send (write) symbols to a RTB?

I want to use a monospaced font (aka old MS Linedraw) for this I picked Courier New.

I need the special chars to build/draw a box (DOS-like) :  ┌ ┐┬└ ┘┴

Please add a little code-sample.

Regards
Robsoft

XP Pro - VB6/SP5 - Office 2000
0
Comment
Question by:Robsoft
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 1

Expert Comment

by:anaadoul
ID: 9806197
why don't you try the sendkeys
first of all get the ascii of the character you want to send
then use the following

SendKeys Chr(TheAsciiNumber)

---------------------------------
There Are 10 Kind OF People
Those Who Understands Binary AND Those Who Don't
0
 

Author Comment

by:Robsoft
ID: 9806572
anaadoul, I'm not trying to send/write to another application - I have RTB (hidden) to which I want to write symbols (Courier New).
I don't think you can use Sendkeys on a control - or am I missing something?

/Robin
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9806848
If these, http://enterprisestorageforum.webopedia.com/TERM/E/extended_ASCII.html are what you are looking for then you are out of luck.  The Chr() function returns the ANSI extended set, not the ASCII extended set.  Typically, this http://www.alanwood.net/unicode/latin_1_supplement.html is what you get when you pass 128 - 250 to chr() for most fonts in windows.

If you want the old dos characters, you have to find a font that specifically has the characters in it.

Idle_Mind
0
 

Author Comment

by:Robsoft
ID: 9806903
Yes, thats true Idle_Mind, that's why I am seeking a way to get the same functionality when
writing to a Richtextbox (where you can set the font!) as when I'm writing to a Word doc. (automation):

Selection.InsertSymbol Font:="Courier New", CharacterNumber:=9484, Unicode _
        :=True

What or how should the above statement be changed to get the character to a Richtextbox?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9807413
As far as I know, there is no equivalent function in VB.  The InsertSymbol() function can only be used within Office Applications.

I suppose if you wanted to get tricky enough you could create a word document, insert the symbol, cut it the clipboard, and then paste it into your RichTextBox, but that's basically where you were already.

Idle_Mind
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 7

Expert Comment

by:wsteegmans
ID: 9807706
Did you already tried the wide AscW and ChrW$ (in VB, VBA and VB.Net)? You just have to use it like that:
ChrW$(9484) and it returns the character you want: ┌

Everything about VB-strings (and optimizing strings):
http://www.aivosto.com/vbtips/stringopt.html

Some general info about using UNICODE in VB (with also API-Solutions):
http://www.mvps.org/vb/hardcore/html/whatisunicode.htm
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9808077
Not much out there on this subject.  I don't have any personal experience with unicode but from what I can see you need to do three things:

1) Have language support installed on your computer

2) Use the MS Forms 2.0 Controls

3) Use the ChrW() function instead of Chr().

These links may be of interest to you.

http://www.unicode.org/charts/PDF/U2500.pdf

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q193/5/40.asp&NoWebContent=1

Idle_Mind
0
 
LVL 7

Accepted Solution

by:
wsteegmans earned 500 total points
ID: 9810744
Tested it yesterday with VB.Net ... In VB.Net the RTB can handle UNICODE ...

However, VB6 and most OCX really don't use Unicode. Though VB uses Unicode internally, but all strings are converted to single byte characters, when passed to external subroutines. Most standard controls also don't use Unicode to store and display any text.

Considering the fact that Forms 2.0 is a dead technology and there isn't a Rich Text Box in it (and it's not allowed to distribute it with your program), you can look for an alternative RTB ActiveX, but I couldn't find any interesting, or you must stay using the ANSCI/ASCII set :-(

Funny thing is: When you copy/paste (Ctrl+C/Ctrl+V) these characters from your Word Document to your Richt Text Box, then it works ... What happens, to copy content from a RT App (Word) to the RTB-Control, the data in the ClipBoard is probably stored in Rich Text Format.

For example, copy/paste one of your characters and then watch the property TextRTF of your RTB, you will get something like this:
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\fnil\fcharset0 Futura Lt BT;}}
\viewkind4\uc1\pard\lang3081\f0\fs20\u9484?\lang1033\f1\fs17
\par }

When you do it in the other way. Set the TextRTF-Propery of an empty RTB-Control to this
{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\fnil\fcharset0 Futura Lt BT;}}
\viewkind4\uc1\pard\lang3081\f0\fs20\u9484?\lang1033\f1\fs17
\par }

You first sign will show up. You also see the UNICODE-value in this fragment (u9484) So, I guess you have to use the real RTF-code to create these characters in your RTB-Control, because UNICODE can't be used directly ...

The Richt Text Format (RTF) Specification
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtfspec/html/rtfspec.asp

Regards.
0
 

Author Comment

by:Robsoft
ID: 9811880
Hi guys

Thank's for your comments, I have accepted wsteegmans answer.

Seems I'm out of luck here.
I still have to decide how to deal with it, either RTF codes, some ActiveX or
stick with the solution I have, which I don't like!

VB.Net is a bit in the future for me, too bloated.

Best wishes
0
 

Expert Comment

by:lthames
ID: 10074262
Dear Robsoft,

I know this is late but I do have a solution to your problem.  in an RichTextEdit box you can manipulate the text in the box as well as the headers for the rtf file.  You can add MS line drawing characters by concatinating them into the richtext string at the point you want.  For example:  
                    rtfEdit.TextRTF = rtfEdit.TextRTF & "\u9556?"  

adds a drawing character to the end of the text in the text edit box.  You may have to insert it at a specific point which will take some calculation to figure it out.  

For my usage I am building the rtf header manually and then adding one character at a time and then finishing with the rtf footer.  If you have any questions you can email me @ lynn@excelss.com
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 11750258
I have similar problem facing in rich text box. I am unable to display greek characters in RTF box. I have a database which stores greek data but when i am setting the text property with rs.fields(0) then it doesn't display properly. Please help me.

-sameer
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now