Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Combo makes RTB`s visible?


Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2000, 10:13 PM
golash
Guest
 
Posts: n/a
Default Combo makes RTB`s visible?


I've run into a problem with this code. I am intending
to open 6 richtextboxes from a click on a combo box.
The code works correctly if I click form the top of the list.
If I start from the middle of the list none of the RTB`s
are visible.

Thanks

Private Sub UserForm_Initialize()
ComboBox1.AddItem "Introduction"
ComboBox1.AddItem "Setup"
ComboBox1.AddItem "Tongue & Groove"
ComboBox1.AddItem "Butt"
ComboBox1.AddItem "Dovetail"
ComboBox1.AddItem "Pullouts"
ComboBox1.ListIndex = 0

End Sub
Private Sub ComboBox1_Click()
Select Case ComboBox1.ListIndex
Case 0 'Introduction"
RichTextBox1.Visible = True
Case 1 'Setup'
RichTextBox2.Visible = True
Case 2 'Tongue & Groove
RichTextBox3.Visible = True
End Select
End Sub




Reply With Quote
  #2  
Old 11-24-2000, 04:46 AM
chrizb
Guest
 
Posts: n/a
Default Re: Combo makes RTB`s visible?

Here is the ms help: This works

With the RichTextBox control the end user can change various attributes of text such as font, font size, and font color. In this scenario, three ComboBox controls appear on an application's toolbar to show attributes of text in the RichTextBox control:



Using these ComboBox controls, the user can select a font, font color, and font size to apply to selected text.

The following objects are used in this scenario:

Form object named "frmRTF"


Toolbar control named "tlbRTF"


ComboBox control named "cmbFontColor"


ComboBox control named "cmbFontName"


ComboBox control named "cmbFontSize"


RichTextBox control named "rtfData"
Note The following steps are a general outline of the creation process. Each step is explained in greater detail later in this topic.

To create three combo boxes that display attributes

Set the Form object's ScaleMode to centimeters.


Create a Toolbar control.


Create three ComboBox controls on the Toolbar control.


In the Form object's Load event, populate the ComboBox controls.


In the ComboBox controls' Click event, set the SelFontName, SelFontColor, or SelFontSize property.


In the RichTextBox control's SelChange event, use the SelFontName, SelFontColor, or SelFontSize property to change the appropriate ComboBox control's List property.
Set the Form Object's ScaleMode to Centimeters
The Form object's ScaleMode property determines which measurement unit is used for certain properties. On the RichTextBox control, the SelIndent. SelHangingIndent, and other properties, use the ScaleMode unit. For these properties, it's more convenient to use centimeters rather than twips. In addition, when creating Button objects with the PlaceHolder style, the ScaleMode property determines how the Button object's width is measured.

To set the form object's ScaleMode property to centimeters

Click the Form object.


Press F4 to display the Properties window.


Click the ScaleMode property and select 7 (centimeters).
Create a Toolbar Control
On the Toolbox, double-click the Toolbar control icon. In the Properties window, double-click Name and change the name of the control to tlbRTF.

Create Three ComboBox Controls
Three ComboBox controls will be placed on the Toolbar. Each ComboBox control will be populated with font attributes.

To create three ComboBox controls

On the Toolbox, click the ComboBox control icon.


Draw a ComboBox control on the Toolbar control.


Set the Name property for each of the three ComboBox controls according to the following table:ComboBox Property Value
ComboBox1 Name cmbFontName
ComboBox2 Name cmbFontSize
ComboBox3 Name cmbFontColor


Populate the ComboBox Controls
The ComboBox controls must also be populated with appropriate values. The following code populates each ComboBox control in the Form_Load event.

Private Sub Form_Load()
' Add colors to cmbFontColor.
With cmbFontColor
.AddItem "Black"
.AddItem "Blue"
.AddItem "Red"
.AddItem "Green"
.ListIndex = 0
End With

Dim i As Integer
With cmbFontName
For i = 0 to Screen.FontCount - 1
.AddItem Screen.Fonts(i)
Next i
' Set ListIndex to 0.
.ListIndex = 0
End With

With cmbFontSize
' Populate the combo with sizes in
' increments of 2.
For i = 8 To 72 Step 2
.AddItem i
Next i
' Set ListIndex to 0
.ListIndex = 1 ' size 10.
End With
End Sub

In the ComboBox Controls' Click event: Set the SelFontName, SelColor, or SelFontSize Property
To set the font, color, and font size for a RichTextBox control, use the SelFontName, SelColor, and SelFontSize properties. For each of the ComboBox controls, set the appropriate property in the Click event. After setting the property, you may want to set the focus back to the RichTextBox control:

Private Sub cmbFontName_Click()
rtfData.SelFontName = cmbFont
rtfData.SetFocus
End Sub

Private Sub cmbFontSize_Click()
rtfData.SelFontSize = cmbFontSize.Text
rtfData.SetFocus
End Sub

Private Sub cmbFontColor_Click()
' Change font colors of text using the
' Select Case statement with the ListIndex of the
' ComboBox control. Set the colors with
' the intrinsic constants for color.
Me.Show
With rtfData
Select Case cmbFontColor.ListIndex
Case 0
.SelColor = vbBlack
Case 1
.SelColor = vbBlue
Case 2
.SelColor = vbRed
Case 3
.SelColor = vbGreen
End Select
End With
' Return focus to the RichTextbox control.
rtfData.SetFocus
End Sub

In the SelChange Event: Use the SelFontName, SelColor, or SelFontSize property to change the appropriate ComboBox control's List property
The ComboBox control can also be used to notify the user of text attributes as the insertion point is moved in the RichTextBox control. The SelChange event occurs either when the insertion point is moved, or when selected text is changed. Thus, in the SelChange event, check the SelFontName, SelFontColor, and SelFontSize properties and reset the appropriate ComboBox control.

Private Sub rtfData_SelChange()
' SelFontSize returns the font size, or Null if
' it's mixed.
If Not IsNull(rtfData.SelFontSize) Then
cmbFontSize.Text = rtfData.SelFontSize
End If

' Show Font name in the ComboBox.
cmbFont.Text = rtfData.SelFontName

' Show color of text in the ComboBox. Use the
' intrinsic constants for color to determine
' the color of the text.
Select Case rtfData.SelColor
Case vbBlack
cmbFontColor.ListIndex = 0
Case vbBlue
cmbFontColor.ListIndex = 1
Case vbRed
cmbFontColor.ListIndex = 2
Case vbGreen
cmbFontColor.ListIndex = 3
End Select
End Sub



Reply With Quote
  #3  
Old 11-27-2000, 02:16 PM
NoahBody NoahBody is offline
Senior Contributor
 
Join Date: Apr 2000
Location: Edge City, CA
Posts: 799
Default Re: Combo makes RTB`s visible?

Shouldn't the second part be more like:

Private Sub ComboBox1_Click()
Select Case ComboBox1.ListIndex
Case 0 'Introduction"
RichTextBox1.Visible = True
Case 1 'Setup'
RichTextBox2.Visible = True
Case 2 'Tongue & Groove
RichTextBox3.Visible = True
Case 3 'Butt
RichTextBox4.Visible = True
Case 4 'Dovetail
RichTextBox5.Visible = True
Case 5 'Pullouts
RichTextBox6.Visible = True
End Select

And if so, what's the problem??

->Noah

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->