Results 1 to 11 of 11

Thread: Calling a controls parent event

  1. #1

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    Calling a controls parent event

    Hi,

    I'm making a control and I want to call an event in the control thats parent to my control.

    I detect when the mouse button has been pressed on my control by using

    VB Code:
    1. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
    2.         _x = e.X : _y = e.Y
    3.         Me.BringToFront()
    4.  
    5.  
    6.         'Dim c As Control = Me.Parent
    7.     End Sub

    Now I want to call the me.Parent OnClick event.

    I simply don't know how to do it!

    Any help would be much appreciated
    Thanks

  2. #2
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    i hope someone has the answer cause I am having the same problem.

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    You guys are probably way ahead of me but I can't understand what you are trying to do.

    If you are talking about VB.NET Windows Forms Controls what is the point of creating a derived control and using an event to refer to an event in the base control which responds to virtually the same fire?

    What is the "OnClick Event"? There is an OnClick method in HTM but all the standard controls I have ever seen have the Click Event.

    If your object is to use several derived controls and save coding why not juse use an ordinary Sub?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    taxes the reason for me is that I'm actually creating two controls.

    The first control acts as a container for the second control im designing. And because I want some kind of relationship between to the two controls I need a way.

    When my child control is clicked, the parent container control needs to do something.

    I managed to solve my problem though
    When the control mousedown event is fire, I would raise an event.
    Then on the parent control, I would capture that event and do the necessary actions I needed.

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Originally posted by Geespot
    I managed to solve my problem though
    When the control mousedown event is fire, I would raise an event.
    Then on the parent control, I would capture that event and do the necessary actions I needed.
    Which just happens to be the correct way of doing it...
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by Geespot
    taxes the reason for me is that I'm actually creating two controls.

    The first control acts as a container for the second control im designing. And because I want some kind of relationship between to the two controls I need a way.

    When my child control is clicked, the parent container control needs to do something.

    I managed to solve my problem though
    When the control mousedown event is fire, I would raise an event.
    Then on the parent control, I would capture that event and do the necessary actions I needed.

    OK.

    For my education please. Would not either of the following suffice?

    1. In the Click event of the second control, call the click event of the first control

    2. Add the click event of the second control to the handles of the first control click event. (Or is that what you mean by "Capture" which is the generic name for a VB.Net class/method?)


    And what's the "OnClick Event"? I know it's purpose is obvious but is is a custom event you have written?

    Many thanks for your response.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Originally posted by taxes
    And what's the "OnClick Event"? I know it's purpose is obvious but is is a custom event you have written?
    When inheriting you have some protected methods.
    OnClick, OnMouseDown etc.

    These events are fired before the event is relayed to the user so you can catch them.
    Then it's up to you wether you want to relay them.

    VB Code:
    1. Protected Sub OnClick()
    2. 'This sub is called when the user clicks the control
    3. 'If you do nothing in here, the Click event will not be called.
    4. 'If you want to relay the event use MyBase.OnClick and the Click event will be raised as normal.
    5. 'This way, you have the chance to do something before or after the user or even cancelling the event entirely.
    6. End Sub

    I hope this makes sense
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  8. #8
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi Pax,

    Thank you.

    Is that restricted to inherited controls? I have only inherited forms and there is no OnClick etc. event involved there.

    I must experiment.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  9. #9
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    It's there allright.

    In the object combo select (Overrides)
    In the event combo you should have several OnWhatEver events.

    Attached Images Attached Images  
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by pax
    Hi.

    It's there allright.

    In the object combo select (Overrides)
    In the event combo you should have several OnWhatEver events.

    Thanks,

    I've never looked in the Overrides section
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  11. #11
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Your welcome

    These are very usefull when creating controls.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

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