|
-
Nov 17th, 2000, 12:33 AM
#1
Well guys, I have seen this asked before. About how to make text SubScript. As like H2O would be H²O (lower 2). I just wrote this for all yous that want it.
Treat it with care .
It's not the best.
But this gives you the idea.
Code:
Private Sub SubScript(rtb As RichTextBox, SubString As String, Size As Integer)
SubString$ = Mid$(Trim$(rtb.Text), InStr(rtb.Text, SubString$), Len(SubString$))
With rtb
.SelStart = InStr(1, rtb.Text, SubString$) - 1
.SelLength = Len(SubString$)
.SelFontSize = Size
.SelText = SubString$
End With
End Sub
Usage
Private Sub Command1_Click()
Call SubScript(RichTextBox1, "MyString", 8)
End Sub
-
Nov 17th, 2000, 12:54 AM
#2
transcendental analytic
Eeeh, am i correct:
you search up the first substring and then change it's size to 8? well how do you do superscript then?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 17th, 2000, 01:07 AM
#3
I don't know. Because with SubScript, you just set the Font's size to a smaller number. With SuperScript, if you were to raise the Font's size to a larger number, you'd just get a huge number. So I'm not sure about how to go about doing so. And I don't think anyone knows. RichTextBox simply does not support these properties/functions. Maybe we should beg Microsoft to put them in next version of RichTextBox. I'm sure they could do it. They can do just about anything...because they are Microsoft!
-
Nov 19th, 2000, 02:17 PM
#4
transcendental analytic
Well i know, or i just checked it out. The rtfTExt for a
"1 km^2" is the following:
Code:
{\rtf1\ansi\ansicpg1252\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\fswiss\fprq2 Arial;}{\f3\froman Times New Roman;}}
{\colortbl\red0\green0\blue0;}
\deflang1053\pard\plain\f2\fs24 1 km\plain\f2\fs16\up12 2\plain\lang1035\f3\fs20
\par }
so i guess it does something like you did but with some more code, like up16.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 19th, 2000, 03:34 PM
#5
Keep in mind, however, that chaning the font size is not "ture subscript." Programs like MS Word, will actually have it lower (or raised) yet, the font size remains the same.
-
Nov 19th, 2000, 03:43 PM
#6
transcendental analytic
Nope, i got that straight from a word document i made with wordpad.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 19th, 2000, 03:59 PM
#7
I was referring to Matthew Gates's function.
-
Nov 19th, 2000, 04:43 PM
#8
transcendental analytic
Well but the rtf format is doing something similar, raising the character and using a smaller font
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 20th, 2000, 01:04 AM
#9
Fanatic Member
This was something I was actually messing with a few weeks ago as I was making an MDI text editor with an RTB and wanted to add super/subscripts. This was before I got distracted and did other stuff... but anyway, you can use the .SelCharOffset property to change how text appears. If it's 0, the text is normal. Positive integers will be superscripted by the number of twips, and negatives will be subscripted. That's as far as I went though because I got too tied up in my grad work . It would need some tweaking to make it look right, ie figuring out a good number of twips to use for sub and super based on font size. This might be what things like Word actually do (but that's just a guess on my part).
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Nov 20th, 2000, 01:08 AM
#10
Hey hey! Go easy on me Megatron, I tried to manipulate the Subscript function (or html function, whatever..). It works, not the best, but it's good .
And Kaverin, I will take a look at your idea/what you tried as well.
-
Nov 20th, 2000, 01:32 AM
#11
Kaverin, the .SelCharOffset property isn't exactly the best. It does raise the text a bit, but it isn't very great. Doesn't lower it at all.
http://msdn.microsoft.com/library/de...haroffsetx.htm
-
Nov 20th, 2000, 01:44 AM
#12
Fanatic Member
I think a RichTextBox supports Subscript and Superscript, but the vb control doesn't. 
But, =) on vbaccelerator is a rtb control that creates the rtb with the api. And that control supports subscript and supercript.
-
Nov 21st, 2000, 02:56 PM
#13
Fanatic Member
Matt, I don't know exactly what you did, but it works fine for me. It both superscripts and subscripts. Did you take into account that the .SelCharOffset is in twips, and you should convert that value to points (based on the font size) in order to make it look best? At first I didn't do that, and was just using something like half of the font size, and because .SelCharOffset was in twips, I didn't see any effect. Just multiply the font size by 20 to get the points into twips, and I used 1/3 of that value as a distance for the formatting and it looked fine.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Nov 21st, 2000, 04:47 PM
#14
Here is an updated method.
Code:
'Used for SubScripts
Function SubScript(rtb As RichTextBox, text As String, amount As Integer, size As Integer)
rtb.SelCharOffset = amount
rtb.SelFontSize = size
rtb.SelText = text
End Function
'Used for SuperScripts
Function SuperScript(rtb As RichTextBox, text As String, amount As Integer, size As Integer)
rtb.SelCharOffset = amount
rtb.SelFontSize = size
rtb.SelText = text
End Function
Add a RichTextBox and a CommandButton
Code:
'Prints H20 -4 (2 in SubScript and -4 in Superscript)
RichTextBox1.SetFocus
RichTextBox1.SelText = "H"
SubScript RichTextBox1, "2", -40, 8
RichTextBox1.SelText = "O"
SuperScript RichTextBox1, "-4", 40, 8
-
Nov 21st, 2000, 06:26 PM
#15
Hyperactive Member
Megatron,
I tried your code and the "O" is also subscripted. And the font size does not change at
all. Tried it in VB6.
-
Nov 23rd, 2000, 03:19 PM
#16
This should fix the problems.
Code:
'Used for SubScripts
Function SubScript(rtb As RichTextBox, text As String, amount As Integer, size As Integer)
prevfnt = rtb.SelFontSize
rtb.SelCharOffset = amount
rtb.SelFontSize = size
rtb.SelText = text
rtb.SelCharOffset = 0
rtb.SelFontSize = prevfnt
End Function
'Used for SuperScripts
Function SuperScript(rtb As RichTextBox, text As String, amount As Integer, size As Integer)
prevfnt = rtb.SelFontSize
rtb.SelCharOffset = amount
rtb.SelFontSize = size
rtb.SelText = text
rtb.SelCharOffset = 0
rtb.SelFontSize = prevfnt
End Function
Private Sub Command1_Click()
'Prints H20 -4 (2 in SubScript and -4 in Superscript)
RichTextBox1.SetFocus
RichTextBox1.SelText = "H"
SubScript RichTextBox1, "2", -40, 8
RichTextBox1.SelText = "O"
SuperScript RichTextBox1, "-4", 40, 8
End Sub
-
Dec 13th, 2012, 11:10 AM
#17
Addicted Member
Re: RichTextBox SubScript
Only a 12 year old thread, but I had the same problem, but I only needed 1 text box with a couple of subscripts and I was doing this in .Net.
My Solution was to type the text in a normal text box on my form and lay it out so it looked right except for the subscript, then screenshot it and load it into Paint and then cut and paste the smaller number twos that happened to be on the form and put them over the normal size ones. I initially redid all the text in word, but couldn't find the right background colour so abandoned that. When saving the file, the jpg format sometimes dithered the background, but a bmp seemed fine. Put the picture in a picturebox and all look fine.
Kristian
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|