Results 1 to 16 of 16

Thread: how to use a Right click option?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    how to use a Right click option?

    Hey everyone,

    Does anyone know how i can make it so when somebody right clicks on one of the items in a text box then a form will show?

    So basically

    User > right clicks item in text box > form5.show

    Thankyou,

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: how to use a Right click option?

    vb Code:
    1. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, _
    2. X As Single, Y As Single)
    3.     '~~> If user presses Right Click
    4.     If Button = 2 Then
    5.         '~~> Dirty Trick to disable the popup menu that comes
    6.         '~~> When you right click
    7.         Text1.Enabled = False
    8.         Me.SetFocus
    9.         Text1.Enabled = True
    10.        
    11.         '~~> Show the form
    12.         Form2.Show
    13.     End If
    14. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: how to use a Right click option?

    koolsid uses mousedown... I use mouseup ... either way....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Addicted Member
    Join Date
    Sep 2000
    Location
    UK
    Posts
    199

    Re: how to use a Right click option?

    Interesting 'dirty trick' with the right click popup menu, but it doesn't seem to work for me.

    The menu still appears after form2 opens?

    Any ideas?

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: how to use a Right click option?

    @Paul: Show me the code that you are trying...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: how to use a Right click option?

    This is how you should do it.
    Code:
    Option Explicit
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
                   ByVal hWnd As Long, _
                   ByVal wMsg As Long, _
                   ByVal wParam As Long, _
                   ByRef lParam As Any) As Long
                   
    Private Const WM_RBUTTONDOWN  As Long = &H204
    
    Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        SendMessage Me.hWnd, WM_RBUTTONDOWN, 0, 0&
        Form2.Show
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: how to use a Right click option?

    Awesome thanks guys,

    Infact, How can i make it when they right click a menu comes up? with menu items i've put in the "Menu Editor?"

    Thanks!

  8. #8
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: how to use a Right click option?

    Use PopupMenu.
    Code:
    PopupMenu MenuName
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: how to use a Right click option?

    Remove the dirty trick.... and show your menu
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: how to use a Right click option?

    awesome thanks, How ever...

    When i am clicking on the item in the listbox, even without right clicking but left clicking on it, it shows the menu! I need it so just when i right click,

    I used Dee-U's code!

    Thanks,

  11. #11
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: how to use a Right click option?

    vb Code:
    1. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, _
    2. X As Single, Y As Single)
    3.     '~~> If user presses Right Click
    4.     If Button = 2 Then
    5.         '~~> Dirty Trick to disable the popup menu that comes
    6.         '~~> When you right click
    7.         Text1.Enabled = False
    8.         Me.SetFocus
    9.         Text1.Enabled = True
    10.        
    11.         '~~> Show your popup menu
    12.         PopupMenu MenuName
    13.     End If
    14. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: how to use a Right click option?

    this is the part that determines if the button was the left (1) or right (2)
    If Button = 2 Then

    So you'll need that.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: how to use a Right click option?

    Hiay, that works ! Thanks, how ever.

    Im using a list box which is getting information from my web server. The code im using for that is

    vb Code:
    1. Dim Titles() As String
    2. Dim Tmp, Tmparray
    3.  
    4. ReDim tvStations(0) As String
    5.  
    6.  
    7. myURL = "http://www.onlinetvr.com/software/tv.dat"
    8.  
    9. StringVariable = Inet4.OpenURL(myURL, 0)
    10.  
    11. Titles = Split(StringVariable, vbLf)
    12.  
    13.  
    14. alista.Clear
    15.  
    16. For i = 0 To UBound(Titles)
    17.   If Trim(Titles(i)) <> "" Then
    18.     Tmparray = Split(Titles(i), "==>")
    19.     ReDim Preserve tvStations(UBound(tvStations) + 1) As String
    20.    
    21.     If Tmparray(0) <> "" Then
    22.       tvStations(UBound(tvStations) - 1) = Trim(Tmparray(1))
    23.       alista.AddItem Trim(Tmparray(0))
    24.     End If
    25.   End If
    26. Next i
    27.    '
    28.    '

    And it splits them into seperate items in the listbox.

    Im trying to use your code so that when a user right clicks one of the items (Not the list box it's self. ) Then the mnu pops up. Cause at the moment no matter where i right click in the list box even if a item aint selected on then it shows the menu still. Which i cant have as the mnu is so when a user clicks preview in the menu it plays the item thats selected in the list box.
    this is what the mnu items code im using is

    vb Code:
    1. Private Sub mnu_preview_Click()
    2. SendMessage Me.hWnd, WM_RBUTTONDOWN, 0, 0&
    3.     preview.Close
    4. preview.URL = tvStations(alista.ListIndex)
    5. End Sub
    Hope this makes sense and sorry for the long message!

  14. #14
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: how to use a Right click option?

    Use the .SelCount property to determine if an item is selected or not.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: how to use a Right click option?

    How do i do that? Please explain, Thanks

  16. #16
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: how to use a Right click option?

    If .SelCount is greater than 0 then there is a selected item, otherwise none.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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