Design Time double click code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ShadowLocke
    New Member
    • Jan 2008
    • 116

    Design Time double click code

    I have a custom button class that inherits from 'System.Windows .Forms.Button' and i want to change the default behavior during design time when it is double clicked. i.e. when a developer doubleclicks the button it should add code for a custom event rather than the normal click event.

    Any ideas?
  • ShadowLocke
    New Member
    • Jan 2008
    • 116

    #2
    Garr..jumped the gun again..


    System.Componen tModel.DefaultE vent

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      (subscribed)
      I was unaware of this, good info

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I'm curious how this works out. I would have expected the inherited "click" event to take place as soon as the first click happened, making it hard to receive a double-click.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Originally posted by tlhintoq
          I'm curious how this works out. I would have expected the inherited "click" event to take place as soon as the first click happened, making it hard to receive a double-click.
          If there is no code i nthe regular click event, it shouldn't matter right?
          Althought the MouseEvents.Cli cks property would tell you if it was a single or double (or more?) clicks?

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Originally posted by ShadowLocke
            i want to change the default behavior during design time when it is double clicked. System.Componen tModel.DefaultE vent
            Since a button does not have a double-click event, specifying it as the default action for the CustomButton shouldn't magically gift it with a new capability.

            The new CustomButton will still need to have its own code to handle and raise a double-click event. Once the double-click event exists, then making it the default event for the Visual Studio designer would have an effect at design time.

            Originally posted by Plater
            If there is no code in the regular click event, it shouldn't matter right?
            If the single-click event has no purpose in life, why go through the trouble of creating a custom double-click? One could just use the single-click for that purpose.

            ShadowLocke: Please let us know how your CustomButton with your custom double-click event works out. I'm guessing you are doing something inside the click event to check for a second click within a short period of time. If it doesn't happen then raise the click, if it does happen then raise a custom double-click

            Comment

            • ShadowLocke
              New Member
              • Jan 2008
              • 116

              #7
              No no, this was purely for design time. The double clicking is done inside of visual studio.

              For example, I (as a developer) drop my custom button on the form, then I double click it to goto the code behind of the form. VS automatically adds the click event for me. By putting the DefaultEvent attribute at the top of a custom control class, you can choose what event is automatically added by visual studio.

              Edit:
              What i ended up doing was adding two new events (preclick, and postclick) We wanted the preclick to be the default event given to the coder when they double clicked the custom control.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Ahh, ok! So the double click was not the event, but merely the "action" yo uwere doing in the IDE to have it auto-create an event handler.
                That makes sense.

                Comment

                • cloud255
                  Recognized Expert Contributor
                  • Jun 2008
                  • 427

                  #9
                  This sounds really interesting, could you maybe show how the syntax of this story works?

                  And you mention you only put a line of code in the custom control, is this line of code then used by VS to build the metadata for the control? I'd like to play with this and see what to possibilities are...

                  Comment

                  • ShadowLocke
                    New Member
                    • Jan 2008
                    • 116

                    #10
                    Here is a simple example:

                    Code:
                    [DefaultEvent("ue_preclick")]
                    public class CustomButton : Button
                    {	
                    	public delegate void ue_postclick_handler(EventArgs e);
                    	public event ue_postclick_handler ue_postclick;
                    
                    	public delegate void ue_preclick_handler(CancelEventArgs e);
                    	public event ue_preclick_handler ue_preclick;
                    
                    	public delegate void ue_click_handler(EventArgs e);
                    	public event ue_click_handler ue_click;
                    	
                    	protected override void OnClick(EventArgs e)
                    	{
                    		CancelEventArgs l_cea = new CancelEventArgs(false);
                    
                    		if (ue_preclick != null)
                    			ue_preclick(l_cea);
                    
                    		if (!l_cea.Cancel)
                    		{
                    			Enabled = false;
                    
                    			if (ue_click != null)
                    				ue_click(e);
                    
                    			Enabled = true;
                    
                    			if (ue_postclick != null)
                    				ue_postclick(e);
                    		}
                    
                    	}
                    }

                    Comment

                    • tlhintoq
                      Recognized Expert Specialist
                      • Mar 2008
                      • 3532

                      #11
                      I was mistaken too. I thought he wanted to add a double-click event to an inherited button control.

                      Comment

                      Working...