Link to home
Start Free TrialLog in
Avatar of ttobin333
ttobin333

asked on

vb6 Rich TextBox - prevent text export

Dear Experts,

I want to prevent any text from being copied from a VB6 rich textbox (RTB) and pasted  to another control or application.

Also, I want to prevent any drag and drop from the RTB to another control or application.

Can you please assist?

Thanks!
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you tried setting the Enabled property to False?
Avatar of ttobin333
ttobin333

ASKER

That interferes with other functions. I am just trying to disable ways to export text contained in the box, not totally disable the box.
1. You can prevent the RTF textbox from receiving focus
2. You can detect attempts at selecting text and prevent them
3. You might display the text as a picturebox image
4. In the background, you could populate the clipboard object with an empty string or a warning about copyrighted material inside a loop as long as the RTF textbox has focus.
I would like the rich text box to function as normally as possible, including editing of text and copy/pasting within the box itself. Just trying to prevent any exporting of material within the box to anywhere outside.
If you are going to allow copy/paste, then you are allowing the content to leave your application.  The clipboard is a universal (inter-application) Windows object.
Yes, I am aware of that, but I am looking for a creative solution.
You could simulate a copy/paste between controls
Would you please elaborate on the simulated copy/paste?
SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could trap the Ctrl+X, Ctrl+C, and Ctrl+V keystroke combinations as an alternative to two buttons to do the cut/copy/paste operation.
Yes, that would be smarter! hehe
Thanks guys, I think that will take care of the copy/paste issue. Any suggestions on preventing drag and drop from the textbox to outside, if possible without disabling drag and drop within the box?
Since the form real estate surrounds the textbox, you should be able to detect and thwart and dragging outside of the textbox with a form event.
Aikimark, that's a good idea, but the form OLEDragOver does not allow use of SetData or Clear for the data object. Any suggestions on how to clear the data on dragging over the form?
can you cancel the drag operation?
Aikimark, would you please provide specific information regarding VB6?
You would have to do two things:
1. Transfer the selected and dragging text to some control that becomes visible when dragging starts.
2. set the new control's dragmode property to manual

When the new control is dragged outside the textbox, set its drag property to vbCancel.

Reference.
http://msdn.microsoft.com/en-us/library/aa240985%28v=vs.60%29.aspx
Aikimark, you are referring to dragging controls…I am referring to dragging text from a rich textbox.

The point is to prevent dragging/dropping text to outside of the rich textbox. Having to drag into another control in order to prevent this does not solve the problem. The user can just drag the text directly and bypass this.
I was thinking about using the control in place of the text.

One thing you can do is to define a clip region around the textbox whenever the mouse moves with the left button pressed.  That way, the mouse can't move outside of the textbox until the mouse_up event.
That sounds like an intereting option. Can you provide the specifics?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh come on, trying to patch together bits and pieces from various other solutions…not what I am looking for.

A concise, integrated solution is desired.
When you detect a mouse move with the left button pressed, then invoke the API to prevent the mouse from leaving the confines of the textbox
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, that works partially. 2 issues:

1-The borders of the rectangle are shifted up and slightly to the left of where the textbox is.

2- After a failed external drag/drop or an internal drag/drop, the cursor remains restricted to the textbox until you perform a mouse click. I tried adding the deactivation code to the rtb_OLEDragDrop sub but this doesn't work unless drag drop is set to manual, which then requires additional drag/drop coding. Is there another way to deactivate without the extra click?
1. if it's slightly shifted, then most probably the richtextbox is not directly inside the form; in that case, the proper coordinates need to be calculated..

just modify the code accordingly.. for example if richtextbox is inside a frame called myframe
change the .top, .bottom, .left and .right from:
        .Top = (Me.Top + rtb.Top) / ypixel
        .Bottom = (Me.Top + rtb.Top + rtb.Height) / ypixel
        .Left = (Me.Left + rtb.Left) / xpixel
        .Right = (Me.Left + rtb.Left + rtb.Width) / xpixel

Open in new window

to:
        .Top = (Me.Top + rtb.Top + myframe.top) / ypixel
        .Bottom = (Me.Top + rtb.Top + myframe.top + rtb.Height) / ypixel
        .Left = (Me.Left + rtb.Left + myframe.left) / xpixel
        .Right = (Me.Left + rtb.Left + myframe.left + rtb.Width) / xpixel

Open in new window


2. i don't think there's another way..
Thanks Dany, I got the rectangle positioned correctly now.

As for deactivating the restriction: since rtb_MouseUp does not trigger after the drag/drop and requires the extra mouse click, I came up with the following and it seems to work:

Private Sub rtb_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Throw& = 1 Then
    If Button = 0 Then
        Throw& = ClipCursorBynum&(0)
        Throw& = 0
    End If
End If

Open in new window


I used the If Throw& = 1 condition so it wouldn't run constantly with MouseMove. Do you see any possible problems with this?
I just discovered that the drag restriction using ClipCursor can be bypassed if the user presses alt-tab after initiating the drag…making the drag/drop unrestricted to proceed beyond the rectangle. This was a great solution until this discovery.

Any other ideas?
have you tried intercepting the alt+tab?  Assign the key parameter to zero
Start a timer that sets focus on your application with the appactivate statement
use a variable that indicates that you are in the middle of a drag operation and add code to the form deactivate event that sets focus back to the form (appactivate) whenever the variable indicates dragging.
Thanks guys!