Frantic- 02-16-2005, 04:04 PM How can i do this?
I have the options in a text box. Here is what I have been trying...
Textbox named "Inpt"
ComboBox named "FontBox"
For now, ill have one item in the box, "Times New Roman."
Here is my code...
Option Explicit
Private Sub FontBox_Change()
Dim FontName As String
FontName = FontBox
Inpt.FontName = FontName
End Sub
Private Sub Form_Load()
FontBox.AddItem "Times New Roman"
End Sub
Private Sub mnuExit_Click()
Unload Me
End Sub
Private Sub mnuNew_Click()
Inpt.Text = ""
End Sub
NEOLLE 02-16-2005, 04:27 PM use the Font property to change the font.
Text1.Font = "Parchment"
:)
Frantic- 02-16-2005, 05:21 PM not working :confused:
Squishy 02-16-2005, 05:23 PM Private Sub cmdChangeFont_Click()
Inpt.FontName = FontBox.Text 'Don't depend on default properties - always add a .Text
End Sub
Frantic- 02-16-2005, 05:27 PM there is no command button, and FontBox is the name of the combo box
Squishy 02-16-2005, 05:30 PM That was just an example. I know FontBox is the name of the Combo box. You still need to use .Text, since FontBox on its own is just an object. VB will try to be intuitive and default to the .Text property, but it won't always work as you think it will.
Diurnal 02-16-2005, 05:32 PM Use the Click event of the combo box:
Option Explicit
Private Sub Combo1_Click()
Text1.Font.Name = Combo1.Text
End Sub
Private Sub Form_Load()
'Add some font names to the combo box.
With Combo1
.Clear
.AddItem "Verdana"
.AddItem "Courier"
.AddItem "Times New Roman"
End With
'Add some text to the text box.
Text1.Text = "This is a test."
End Sub
Frantic- 02-16-2005, 05:33 PM Ahh ok Thanks alot! :D
NEOLLE 02-16-2005, 05:35 PM I tested the Font property and it worked. Here's a sample.
You need a TextBox named Text1 and a ComboBox name Combo1.
Private Sub Form_Load()
With Combo1
.Clear
.AddItem "MS Sans Serif"
.AddItem "Blackadder ITC"
.AddItem "Arial"
.AddItem "Fixedsys"
End With
Text1.Text = "This is a sample"
End Sub
Private Sub Combo1_Click()
If Combo1.ListIndex = -1 Then Exit Sub
Text1.Font = Combo1.Text
End Sub
-- you used the Change_Event of your ComboBox, use the Click_Event.
:)
Frantic- 02-16-2005, 05:46 PM aha, some how i knew id be back, now about changing font size and color, here is what im doing for size...
Inpt.FontSize = SizeBox.Text 'This is what is supposed to change the size
SizeBox.AddItem "12pt"
SizeBox.AddItem "20pt"
'These are the sizes for now...
And for Color...
ColorBox.AddItem "Red"
ColorBox.AddItem "Blue"
'These are the choices for now...
Dim FCV As String
If ColorBox.Text = "Red" Then
FCV = "&H000000FF&"
ElseIf ColorBox.Text = "Blue" Then
FCV = "&H00FF0000&"
End If
Inpt.ForeColor = FCV
Squishy 02-16-2005, 06:03 PM 'populating your comboboxes
With ColorBox
.AddItem "Red"
.AddItem "Blue"
End With
With sizeBox
.AddItem "12" 'this has to be an integer, so leave out the 'pt'
.AddItem "14"
End With
'setting color
If ColorBox.Text = "Red" Then
Text1.ForeColor = vbRed
Else 'you don't need to check for blue, since there are only two possible choices
Text1.ForeColor = vbBlue
End If
'setting size
Text1.FontSize = sizeBox.Text
Frantic- 02-16-2005, 08:20 PM ***NEVER MIND I SOLVED IT *****
ok, here is my code so far.
Private Sub cmdApply_Click()
Dim FCV As String
If ColorBox.Text = "Red" Then
FCV = vbRed
ElseIf ColorBox.Text = "Blue" Then
FCV = vbBlue
ElseIf ColorBox.Text = "Black" Then
FCV = vbBlack
End If
Inpt.FontName = FontBox.Text
Inpt.ForeColor = FCV
Inpt.FontSize = SizeBox.Text
End Sub
Private Sub Form_Load()
With FontBox
.AddItem "Arial"
.AddItem "Times New Roman"
.AddItem "Courier"
.AddItem "Georgia"
End With
With SizeBox
.AddItem "12pt"
.AddItem "20pt"
End With
With ColorBox
.AddItem "Black"
.AddItem "Red"
.AddItem "Blue"
End With
im getting a type mismatch for
Inpt.FontSize = SizeBox.Text
Squishy 02-16-2005, 10:01 PM Look at my code. I pointed out that the FontSize property takes an Integer input, and will not accept the "pt" part. You can either process the string with code and remove the pt before assigning it to the FontSize property, or just populate the ComboBox with 12, 14, etc without the pt.
Diurnal 02-16-2005, 10:33 PM You can also use the Val() function to return the numeric portion of the string:
Debug.Print Val("12pt")
Returns 12.
Squishy 02-16-2005, 10:39 PM You can either process the string with code and remove the pt before assigning it to the FontSize property
Falls into that category. ;)
Personally, I'd just drop the pt part. It saves you a bit of code, and users will still understand what the numbers are. (I mean, Winword doesn't use Pt and no one complains)
|