RichTextBox Control for Visual Basic 6.0 Users
The RichTextBox control in Visual Basic 6.0 is replaced by the Windows Forms RichTextBox control in Visual Basic 2008. The names of some properties, methods, events, and constants are different, and in some cases there are differences in behavior.
Conceptual Differences
AutoVerbMenu Property
In Visual Basic 6.0, the AutoVerbMenu property of a RichTextBox control is used to display a context menu with a set of standard commands.
In Visual Basic 2008, the AutoVerbMenu property no longer exists. To provide a context menu for a RichTextBox control, use a ContextMenuStrip component. For more information, see AutoVerbMenu property was not upgraded.
DisableNoScroll Property
In Visual Basic 6.0, the DisableNoScroll property determines whether scroll bars appear as unavailable when there are too few lines of text to scroll vertically or too few characters to scroll horizontally in a RichTextBox control.
In Visual Basic 2008, the DisableNoScroll property no longer exists. You can use the ScrollBars property to force the scroll bars to appear, but you cannot make them appear as unavailable.
FileName Property and LoadFile Method
In Visual Basic 6.0, either the FileName property or the LoadFile method can be used to load an .rtf or text file into a RichTextBox control.
In Visual Basic 2008, only the LoadFile method is available; you cannot assign a file at design time.
SelPrint Method
In Visual Basic 6.0, the SelPrint method of a RichTextBox control can be used to print the contents of the control. It takes a single argument, hDC, which specifies the device context of the device.
In Visual Basic 2008, the SelPrint method no longer exists, and device contexts are no longer used for printing. The RichTextBox control does not provide a method to print its content. However, you can extend the RichTextBox class to use the EM_FORMATRANGE message. You can then send the content of a RichTextBox to an output device, such as a printer. For more information, see SelPrint property was not upgraded.
SelTabCount Property
In Visual Basic 6.0, the SelTabCount property determines the number of tab positions in the selected paragraph(s) or in those paragraphs following the insertion point.
In Visual Basic 2008, the SelTabCount property no longer exists; it is replaced by the Length parameter of the SelectionTabs property (SelectionTabs.Length).
Span Method
In Visual Basic 6.0, the Span method of a RichTextBox control can be used to select a range of text based on a set of specified characters.
In Visual Basic 2008, the Span method no longer exists. You can use the Find method with the characterSet() argument to find a specified character, and then use the SelectedText property to select the range.
Upto Method
In Visual Basic 6.0, the Upto method of a RichTextBox control can be used to move the insertion point up to, but not including, the first character that is a member of a set of specified characters.
In Visual Basic 2008, the Upto method no longer exists. You can use the Find method with the characterSet() argument to find a specified character, and then use the SelectionStart property move the insertion point.
Additional Differences
In addition, there are numerous conceptual differences that apply to all controls, including differences in data binding, font handling, drag-and-drop features, Help support and more. For more information, see Windows Forms Concepts for Visual Basic 6.0 Users.
Code Changes for the RichTextBox Control
The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.
Code Changes for Searching in a RichTextBox Control
The following code demonstrates how to search from the insertion point to the end of a sentence in a RichTextBox control and highlight it. The example requires a RichTextBox control with one or more sentences entered into the Text property, and it requires a Button control. Since the code is being called from the button's Click event, the HideSelection property of the RichTextBox should be set to False; otherwise the highlighting will not be visible.
' Visual Basic 6.0
' Make sure that HideSelection is set to False.
Private Sub Command1_Click()
RichTextBox1.Span ".?!", True, True
End Sub
' Visual Basic' Make sure that HideSelection is set to False.PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
Dim endChars() AsChar = NewChar() {".", "!", "?"}
Dim intEnd AsInteger
intEnd = RichTextBox1.Find(endChars, RichTextBox1.SelectionStart)
RichTextBox1.SelectionLength = intEnd - RichTextBox1.SelectionStart
EndSub
RichTextBox Control Property, Method, and Event Equivalencies
The following tables list Visual Basic 6.0 properties, methods, and events, along with their Visual Basic 2008 equivalents. Those properties, methods, and events that have the same name and behavior are not listed. All Visual Basic 2008 enumerations map to the System.Windows.Forms namespace unless otherwise noted.
This table provides links to topics explaining behavior differences. Where there is no direct equivalent in Visual Basic 2008, links are provided to topics that present alternatives.
Properties
Visual Basic 6.0 |
Visual Basic 2008 Equivalent |
---|---|
Appearance |
New implementation. For more information, see Appearance and BorderStyle Properties for Visual Basic 6.0 Users. |
AutoVerbMenu |
New implementation. For more information, see AutoVerbMenu property was not upgraded. |
BackColor |
Note:
Colors are handled differently in Visual Basic 2008. For more information, see Color Handling for Visual Basic 6.0 Users.
|
Container |
|
DataBindings DataChanged DataField DataFormat DataMember DataSource |
New implementation. For more information, see Data Access for Visual Basic 6.0 Users. |
DisableNoScroll |
New implementation. |
DragIcon DragMode |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
FileName |
LoadFile method |
Font FontBold FontItalic FontName FontSize FontStrikethrough FontUnderline |
Note:
Fonts are handled differently in Visual Basic 2008. For more information, see Font Object for Visual Basic 6.0 Users.
|
ForeColor |
Note:
Colors are handled differently in Visual Basic 2008. For more information, see Color Handling for Visual Basic 6.0 Users.
|
Height |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
HelpContextID |
New implementation. For more information, see Help Support for Visual Basic 6.0 Users. |
HWnd |
|
Index |
New implementation. For more information, see Control Arrays for Visual Basic 6.0 Users. |
Left |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
MouseIcon |
New implementation. For more information, see Cannot set a custom MousePointer. |
MousePointer |
For a list of constants, see MousePointer for Visual Basic 6.0 Users. |
OLEDragMode OLEDropMode |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
Parent |
FindForm method |
SelAlignment |
|
SelBold |
|
SelBullet |
|
SelCharOffset |
|
SelColor |
|
SelFontName |
|
SelFontSize |
|
SelHangingIndent |
|
SelIndent |
|
SelItalic |
|
SelLength |
|
SelProtected |
|
SelRightIndent |
|
SelRTF |
|
SelStart |
|
SelStrikethru |
|
SelTabCount |
SelectionTabs.Length |
SelTabs |
|
SelText |
|
SelUnderline |
|
TextRTF |
|
ToolTipText |
ToolTip component For more information, see ToolTip Support for Visual Basic 6.0 Users. |
Top |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
WhatsThisHelpID |
New implementation. For more information, see Help Support for Visual Basic 6.0 Users. |
Width |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
Methods
Visual Basic 6.0 |
Visual Basic 2008 Equivalent |
---|---|
Drag |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
GetLineFromChar |
|
LinkExecute LinkPoke LinkRequest LinkSend |
No equivalent. For more information, see Dynamic Data Exchange for Visual Basic 6.0 Users. |
Move |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
OLEDrag |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
SelPrint |
New implementation. For more information, see SelPrint property was not upgraded. |
SetFocus |
|
ShowWhatsThis |
New implementation. For more information, see Help Support for Visual Basic 6.0 Users. |
Span |
No direct equivalent. Use the Find method with a characterSet argument. |
Upto |
No direct equivalent. Use the Find method with a characterSet argument. |
ZOrder |
BringToFront or SendToBack function |
Events
Visual Basic 6.0 |
Visual Basic 2008 Equivalent |
---|---|
Change |
|
DblClick |
|
DragDrop DragOver |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
GotFocus |
|
LostFocus |
|
OLECompleteDrag OLEDragDrop OLEDragOver OLEGiveFeedback OLESetData OLEStartDrag |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
SelChange |
|
Validate |
Upgrade Notes
When a Visual Basic 6.0 application is upgraded to Visual Basic 2008, any RichTextBox controls are upgraded to Windows Forms RichTextBox controls, and properties, methods and events are upgraded to their equivalents. Where there may be differences in behavior, upgrade comments are inserted into the code.
See Also
Reference
RichTextBox Control Overview (Windows Forms)