Hi!
Still working on my NotePad thing. My problem is that I don't know hoe to change the font and/or size on the marked text. And another problem is that when i mark a text and then click my ComboBox, the text gets unmarked. Plz, help me!
/ Erik
Printable View
Hi!
Still working on my NotePad thing. My problem is that I don't know hoe to change the font and/or size on the marked text. And another problem is that when i mark a text and then click my ComboBox, the text gets unmarked. Plz, help me!
/ Erik
I assume you're using a RichTextBox because you can't do this with the original textbox.
The text isn't really deselected when the textbox loses focus but it's rather hidden.Code:RichTextBox1.SelFontName = "Times New Roman"
RichTextBox1.SelFontSize = 16
If you don't want this behaviour set the HideSelection property to False at design time.
Good luck!
PS. Hur är livet i Linköping DS.
Thanks for the help!
PS. Bara bra =) DS.
Hi again!
The code you gave me didn't work! I don't know why. This is how it looks like:
Private Sub chooseFont_Change()
text.SelFontName = chooseFont.Value
End Sub
What do u think?
/ Erik
You need to use a RichTextBox to do this.
[Edited by Megatron on 09-17-2000 at 11:54 AM]
I just finished writing an example of working with formatted text. Add the following code to a Form with a RichTextBox, CommonDialog and a CommandButton.
When you select text in the RichTextBox then click the button, the FontDialog Box will appear and from there, you can format your text.Code:On Error Resume Next
With CommonDialog1
.Flags = cdlCFBoth Or cdlCFEffects
.FontBold = RichTextBox1.SelBold
.FontItalic = RichTextBox1.SelItalic
.FontUnderline = RichTextBox1.SelUnderline
.FontStrikethru = RichTextBox1.SelStrikeThru
.FontName = RichTextBox1.SelFontName
.FontSize = RichTextBox1.SelFontSize
.Color = RichTextBox1.SelColor
End With
CommonDialog1.ShowFont
If Err <> 32755 Then
With RichTextBox1
.SelBold = CommonDialog1.FontBold
.SelItalic = CommonDialog1.FontItalic
.SelUnderline = CommonDialog1.FontUnderline
.SelStrikeThru = CommonDialog1.FontStrikethru
.SelFontName = CommonDialog1.FontName
.SelFontSize = CommonDialog1.FontSize
.SelColor = CommonDialog1.Color
End With
End If
Hi!
It won't just work! An alert box pops up and say:
Compile Error:
Invalid Outside procedure
/ Erik
PS. I have added RichTextBox, CommonDialog and CommandButton, and I haven't changed there names. DS.
What line are you getting it on?
Put it in the CommandButton. :rolleyes:
Code:Private Sub Command1_Click()
' Megatron's code here
End Sub
Now it worked. My bad =)
But that wasn't really how I wanted it. I was thinking more like word, y'know, with these buttons. But thx anyway! I will proborbly use this in an other program.
/ Erik
I assume chooseFont is the ComboBox.Quote:
Originally posted by TimeHero
Hi again!
The code you gave me didn't work! I don't know why. This is how it looks like:
Private Sub chooseFont_Change()
text.SelFontName = chooseFont.Value
End Sub
The Change event of a ComboBox will only be fired when the user types in the textbox area. When you click to choose an item in the drop down list box the Click event is fired.
So just move the code to the Click event.
Good luck!Code:Private Sub chooseFont_Click()
text.SelFontName = chooseFont.List(chooseFont.ListIndex)
End Sub