Results 1 to 10 of 10

Thread: How do you program a main menu bar?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    How do you program a main menu bar?

    What is the code to make the cut, copy, and paste buttons work? If someone could respond soon that would be helpful, thanks.

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: How do you program a main menu bar?

    I did the copy and paste, I'm sure the cut is very similar.
    VB Code:
    1. Private Sub mnuCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuCopy.Click
    2.         For Each oControl As Control In Me.Controls
    3.             If oControl.Focused Then
    4.                 If TypeOf oControl Is TextBox Then
    5.                     If CType(oControl, TextBox).SelectionLength > 0 Then
    6.                         CType(oControl, TextBox).Copy()
    7.                     End If
    8.                 End If
    9.             End If
    10.         Next
    11.     End Sub
    12.  
    13.     Private Sub mnuPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPaste.Click
    14.         For Each oControl As Control In Me.Controls
    15.             If oControl.Focused Then
    16.                 If TypeOf oControl Is TextBox Then
    17.                     If Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) = True Then
    18.                         CType(oControl, TextBox).Paste()
    19.                     End If
    20.                 End If
    21.             End If
    22.         Next
    23.     End Sub
    Last edited by wild_bill; May 12th, 2005 at 09:22 AM.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    Re: How do you program a main menu bar?

    ummmmmmm..... it didnt work

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: How do you program a main menu bar?

    Okay, I'll use my super psychic powers to determine the exception, and I'll get back to you. Just kidding. Did you copy/paste the entire thing, or did you create your own menu click events?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    Re: How do you program a main menu bar?

    wait no it does work but I still cant get the cut to work.

  6. #6
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: How do you program a main menu bar?

    I made a new menu item, mnuCut. I went into my Form code and selected mnuCut, then selected the Click event, this created a new sub. I copied the code from the copy sub, pasted it into the new sub, and replaced the .Copy() with a .Cut(), and it worked.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    Re: How do you program a main menu bar?

    Do you know how to get a save, load and print buttons to work??
    If there is somebody here more of a noob you can have my spot as noob.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do you program a main menu bar?

    The simplest way to code Cut, Copy and Paste is to use SendKeys.Send() to send the Ctrl+X, Ctrl+C and Ctrl+V key combinations to your app
    VB Code:
    1. SendKeys.Send(^X) 'Cut.
    2. SendKeys.Send(^C) 'Copy.
    3. SendKeys.Send(^V) 'Paste.
    That way you don't have to fiddle around to work out whether the correct type of control is focused and what text is selected. As far as Save, Load and Print are concerned, they mean different things to different apps, so it is up to you. You may want to use the SaveFileDialog, OpenFileDialog and PrintDialog classes in some way. To print, you will generally be using the PrintDocument class and its PrintPage event. You may also want to employ a PrintPreviewDialog.

  9. #9
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Wink Re: How do you program a main menu bar?

    Just a side note,... this code works better if you put quotes around the value.
    VB Code:
    1. Call SendKeys.Send("^C") 'Copy.
    ~Peter


  10. #10
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: How do you program a main menu bar?

    i just use the Clipboard object directly

    Clipboard.SetDataObject()
    Clipboard.GetDataObject()
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width