Cut,Copy,Paste 
Author Message
 Cut,Copy,Paste

Hello,

In VB.NET, I dropped a MainMenu on a Form and added File, Edit, View, Window
and Help items. Under Edit, I added Cut, Copy and Paste.

Q1) Ctrl+X, Ctrl+C and Ctrl+V are not listed in the Shortcut property
options.

Q2) How do I implement cut, copy and paste so that it works on the currently
selected TextBox? The examples given work with only one specific TextBox:

    private void Menu_Copy(System.Object sender, System.EventArgs e)
     {
        // Ensure that text is selected in the text box.
        if(textBox1.SelectionLength > 0)
            // Copy the selected text to the Clipboard.
            textBox1.Copy();
     }

Thanks,
TP



Sun, 08 May 2005 07:15:29 GMT  
 Cut,Copy,Paste
Try:

    Const WM_CUT = &H300
    Const WM_COPY = &H301
    Const WM_PASTE = &H302
    Private Declare Ansi Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As
Int32, ByVal lParam As Integer) As Integer
    Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem3.Click
        Dim iret As Integer
        iret = SendMessage(Me.ActiveControl.Handle, WM_CUT, 0, 0)
    End Sub

    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem4.Click
        Dim iret As Integer
        iret = SendMessage(Me.ActiveControl.Handle, WM_COPY, 0, 0)
    End Sub

    Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem5.Click
        Dim iret As Integer
        iret = SendMessage(Me.ActiveControl.Handle, WM_PASTE, 0, 0)
    End Sub

Works for me!

HTH

Quote:
> Hello,

> In VB.NET, I dropped a MainMenu on a Form and added File, Edit, View,
Window
> and Help items. Under Edit, I added Cut, Copy and Paste.

> Q1) Ctrl+X, Ctrl+C and Ctrl+V are not listed in the Shortcut property
> options.

> Q2) How do I implement cut, copy and paste so that it works on the
currently
> selected TextBox? The examples given work with only one specific TextBox:

>     private void Menu_Copy(System.Object sender, System.EventArgs e)
>      {
>         // Ensure that text is selected in the text box.
>         if(textBox1.SelectionLength > 0)
>             // Copy the selected text to the Clipboard.
>             textBox1.Copy();
>      }

> Thanks,
> TP



Sun, 08 May 2005 08:47:09 GMT  
 Cut,Copy,Paste
I'm surprised that something so basic as cut, copy and paste isn't built
into the .NET Framework and that I must call a Windows API function with
hard-coded constants.

Thanks,
TP



Quote:
> Try:

>     Const WM_CUT = &H300
>     Const WM_COPY = &H301
>     Const WM_PASTE = &H302
>     Private Declare Ansi Function SendMessage Lib "user32" Alias
> "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam
As
> Int32, ByVal lParam As Integer) As Integer
>     Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MenuItem3.Click
>         Dim iret As Integer
>         iret = SendMessage(Me.ActiveControl.Handle, WM_CUT, 0, 0)
>     End Sub

>     Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MenuItem4.Click
>         Dim iret As Integer
>         iret = SendMessage(Me.ActiveControl.Handle, WM_COPY, 0, 0)
>     End Sub

>     Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MenuItem5.Click
>         Dim iret As Integer
>         iret = SendMessage(Me.ActiveControl.Handle, WM_PASTE, 0, 0)
>     End Sub

> Works for me!

> HTH


> > Hello,

> > In VB.NET, I dropped a MainMenu on a Form and added File, Edit, View,
> Window
> > and Help items. Under Edit, I added Cut, Copy and Paste.

> > Q1) Ctrl+X, Ctrl+C and Ctrl+V are not listed in the Shortcut property
> > options.

> > Q2) How do I implement cut, copy and paste so that it works on the
> currently
> > selected TextBox? The examples given work with only one specific
TextBox:

> >     private void Menu_Copy(System.Object sender, System.EventArgs e)
> >      {
> >         // Ensure that text is selected in the text box.
> >         if(textBox1.SelectionLength > 0)
> >             // Copy the selected text to the Clipboard.
> >             textBox1.Copy();
> >      }

> > Thanks,
> > TP



Sun, 08 May 2005 23:17:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Cut, Copy, Paste

2. disabling cut/copy/paste

3. cut/copy/paste

4. Cut/Copy/Paste

5. Cut, Copy Paste, Select All

6. Cut\Copy\Paste\Scream!

7. cut,copy,paste

8. Creating my own right-mouse-button cut-copy/paste menu

9. Cut, Copy Paste controls from browser

10. Cut,Copy,Paste

11. Enabling/Disabling Cut, Copy, Paste

12. Drag/Drop vs Cut/Copy/Paste

 

 
Powered by phpBB® Forum Software