Selecting Text

  • Thread starter Thread starter mBird
  • Start date Start date
M

mBird

I have a basic app that draws some text: Graphics.DrawString(...).
I want to be able to mouse select that text and copy to clipboard. Does
anyone know of any sample info on doing that.
Thank you.
 
* "mBird said:
I have a basic app that draws some text: Graphics.DrawString(...).
I want to be able to mouse select that text and copy to clipboard. Does
anyone know of any sample info on doing that.

Why not use a TextBox or RichTextBox control?
 
Create a rectangle structure around your text (don't draw the rectangle).
Then when a user clicks inside that rectangle, copy the text to the
clipboard.

Example:

'--- Dimension of your text
Dim rect as New Rectangle(50,50,200,100)

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles
MyBase.MouseDown

'-- Did the your click your text? If so, copy it
If rect.contains(e.X,e.Y) then

'------Copy data to clipboard -----------------

End If


End Sub
 
Hi --
I can not figure out how to do the "Copy data to clipboard" part below. I
tried making a rectangle around mytext and doing:
Rectangle r = new Rectangle(10, 170, 300, 40);

Clipboard.SetDataObject(r, true);

But that does not copy anything?

Thanks for any info.
 
'-- Draw out string
Dim str as String ="Text to draw"

Dim gr As Graphics = CreateGraphics()

gr.DrawString=(str,Me.Font, Brushes.Black, 10, 10)

gr.Dispose()



'-- Then in the mouse down event
If rect.contains(e.X,e.Y) then


'-- Draw the string not the rect itself
Clipboard.SetDataObject(str,true)----------------------------------------(Se
e str above)

End If
 
Back
Top