Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In the designer, when you click on the lightning bolt for Events there is usually a Click event but I never see a DoubleClick event.

 

I want to put DoubleClick events in my code (my program).

C#
  • *Experts*
Posted

Try this:

 

Private Sub Your_Control_Name_Here_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Your_Control_Name_Here.DoubleClick

'Do something special

End Sub

 

All Controls respond to double clicks.

 

btw: Divil, did you write the DotNetWidgets menu generator? If so you did a great job!

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
I pretty much knew how to do it but I would think that double clicks are common and VS would have them like the rest of the Events. But I guess not. If anyone knows where that event would be please let me know. Maybe I have a cheap version of MSVC#? I got it from office max for 100 bucks.
C#
Posted (edited)

I agree, the control your using is the richtextbox control, and i've checked both vb and c# - no DoubleClick from list of events (thunderbolt icon in c# and dropdowns in code from vb)

It is, however available as a valid event via code. The help also doesn't show the event, but it does show that the control inherits from the Control class. (All Control objects have a doubleclick event)

 

Any comments? Is this maybe a bug or is there some reason around this?

 

 

EDIT: It might be in code but it doesn't work. Found a msdn artical about event sequence, confirming no double click event:

 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwindowsformsarchitecture.asp

It's just weird that its available in code (ide doesn't complain..):confused:

Edited by Cywizz
Howzit??
Posted (edited)

Should be in the mouse down event args.

 

The menu - you'll have to do that on your own

 

(snippet from my code)

 


class ParameterDrivenTextbox ...


   Private mMenuAlternativeUnits As ContextMenu
   Private mAlternativeUnits As DataTable

Public Function LoadAlternativeUnits() As Boolean

       Dim myBR As New BusinessRules.ParameterContainerBR()
       Dim aRow As DataRow
       Dim aMenuItem As MenuItem

       If Not Me.mMenuAlternativeUnits Is Nothing Then
           Me.mMenuAlternativeUnits = Nothing
       End If
       Me.mMenuAlternativeUnits = New ContextMenu()

       mAlternativeUnits = myBR.GetAlternativeUnits(me.GUID)

       If Not mAlternativeUnits Is Nothing Then

           If mAlternativeUnits.Rows.Count > 0 Then

               'Build the  popup menu ...
               For Each aRow In mAlternativeUnits.Rows

                   aMenuItem = New MenuItem(Utility.ConvertToString(aRow("_AE_Bezeichnung")))
                   aMenuItem.RadioCheck = True
                   AddHandler aMenuItem.Click, AddressOf Me.UnitsMenu_Clicked
                   Me.mMenuAlternativeUnits.MenuItems.Add(aMenuItem)
               Next

               Return True
           Else
               Return False
           End If
       Else
           Return False
       End If
   End Function

   Private Sub UnitsMenu_Clicked(ByVal Sender As System.Object, ByVal e As System.EventArgs)

       Dim theMenuItem As MenuItem = CType(Sender, MenuItem)


   End Sub




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

       If (e.Button <> MouseButtons.Right) Then
           Exit Sub
       End If

       mMenuAlternativeUnits.Show(btnUnit, New System.Drawing.Point(e.X, e.Y))

   End Sub

end class

 

 

Sure - this adds code always adds the same handler to the menu items, yopu could also add the individually, one by one, not in a loop.

Edited by Heiko
.nerd
  • *Gurus*
Posted

All controls have those events, because the base class has them. It is, however, possible that the inherited controls already have behaviour for those events and aren't calling them at all. In which case, they can't get rid of the events themselves (inheritance doesn't let you do that) but they can hide the events from the property browser using attributes.

 

Bottom line - if the event doesn't show in the property browser, it's probably for a good reason. But it's still there, and you can always wire it up with code on the off-chance that it still works.

 

DiverDan: Yes I did write them, thanks for the praise :) Look out for a designable Outlook Bar there in the next day or two.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • *Experts*
Posted

If you just want a context menu, set the ContextMenu property of the control. It will override any built-in windows context menu, such as a TextBox's Copy/Cut/Paste - so you'll have to add them manually if you want those menus plus your own.

 

If you want to do something special before showing the context menu, you'll have to use the MouseDown event. If you want to trigger the menu in the Click event, you'll need to manually keep track of which button was pressed in the MouseDown event (such as a bool variable bRightButtonDown) so that you'll know about it in the Click event (which doesn't give you which buttons are down). There is no right click event :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted (edited)

Why does this not work?

 

ContextMenu C=new ContextMenu();

C=contextMenu1;

if(MouseButtons==MouseButtons.Right) C.Show();

 

When I put the . in after C nothing pops up, it is not recognized. Something is wrong.

Edited by aewarnick
C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...