RichTextBox Control Conversion

  • Thread starter Thread starter Ike
  • Start date Start date
I

Ike

In converting a VB6 app over to .NET, I encounter a particularly troublesome
element regarding RichText.

Private Sub mnuEditCopy_Click()
Clipboard.SetText ActiveForm.rtfText.SelRTF
End Sub

Public datobj As New System.Windows.Forms.DataObject()

Public Sub mnuEditCopy_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles mnuEditCopy.Click
datobj.SetData(System.Windows.Forms.DataFormats.Text,
ActiveMdiChild.rtfText.SelRTF)
System.Windows.Forms.Clipboard.SetDataObject(datobj)
End Sub

Upon compilation of course, I get the error message 'rtfText' is not a
member of 'System.Windows.Forms.Form.'

HOWEVER, there are NO RichTextBoxes on any forms here - it's all just
straight text boxes (this is an ancient project I inherited from someone
else, and has been through many iterations - evidently no one ever got rid
of the references to rich text on the clipboard!).

So I am wondering how I can convert the statement
"ActiveMdiChild.rtfText.SelRTF" to refer to plain text, not richtext, so as
to avoid this error?

Thanks, Ike
 
Hi,

The error is saying that the control rtfText is not a member of
activemdichild. I am guessing that activemdichild is of the form type. You
need to directcast it to the right type form

For example if the activemdichild is form1

Public Sub mnuEditCopy_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles mnuEditCopy.Click
datobj.SetData(System.Windows.Forms.DataFormats.Text,
DirectCast(ActiveMdiChild,Form1).rtfText.SelRTF)
System.Windows.Forms.Clipboard.SetDataObject(datobj)
End Sub

Ken
-----------------
In converting a VB6 app over to .NET, I encounter a particularly troublesome
element regarding RichText.

Private Sub mnuEditCopy_Click()
Clipboard.SetText ActiveForm.rtfText.SelRTF
End Sub

Public datobj As New System.Windows.Forms.DataObject()

Public Sub mnuEditCopy_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles mnuEditCopy.Click
datobj.SetData(System.Windows.Forms.DataFormats.Text,
ActiveMdiChild.rtfText.SelRTF)
System.Windows.Forms.Clipboard.SetDataObject(datobj)
End Sub

Upon compilation of course, I get the error message 'rtfText' is not a
member of 'System.Windows.Forms.Form.'

HOWEVER, there are NO RichTextBoxes on any forms here - it's all just
straight text boxes (this is an ancient project I inherited from someone
else, and has been through many iterations - evidently no one ever got rid
of the references to rich text on the clipboard!).

So I am wondering how I can convert the statement
"ActiveMdiChild.rtfText.SelRTF" to refer to plain text, not richtext, so as
to avoid this error?

Thanks, Ike
 
This is counter to OO polymorphism, isnt it? Isnt there a means whereby I
can get what the selected text is, for a text box, for a given form, at the
form level? -Ike
 
Back
Top