How to override a function in VB.NET-VBForums
Results 1 to 6 of 6

Thread: How to override a function in VB.NET

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    165

    How to override a function in VB.NET

    Hello,

    I've created a user control with a toolstrip having 3 buttons Add\Edit\Delete, and implemeted a generic toolstrip.
    in some cases, i want to add this menu to a form but only use the delete of this toolstrip and implement a special Add\Edit for that form. so how can i tell the form that when the user clicks on add not to do the default add of the toolstrip user control and do the one on the form, in other words i want to override the Add function of the Add button toolstrip.

    Thank you

    Hiba

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,531

    Re: How to override a function in VB.NET

    In your toolstrip user control declare the function as Overridable
    e.g.

    vb.net Code:
    1. Public Overridable Sub AddButtonClick()
    Now in the class where you want to override the default functionality of this procedure, you can override it like this:

    vb.net Code:
    1. Public Overrides Sub AddButtonClick()
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game


    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,237

    Re: How to override a function in VB.NET

    To clarify what Pradeep said, you have to create a new class that inherits the original class. In this derived class you can then override any overridable methods in the original class.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: How to override a function in VB.NET

    Or depending on how you want to use your control:

    Just add Events to your control:

    AddClicked
    EditClicked
    DeleteClicked

    That way some events (you choose them) will be available to the using code.
    You handle the click event in some cases and in other cases ignore the event.
    But the using code will have to implement all the actions desired when the desired event is captured by the listening code.

  5. #5
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: How to override a function in VB.NET

    Actually, I don't think that's what you want.

    You could just Add three new properties to your control:

    CanAdd
    CanDelete
    CanEdit

    That will allow you to shut down the default handling entirely.

    If you Override, you will need to make a new control for the situation.

    If you want you could add the events as suggested before and direct the event handler's code to handle the event as if the Form's Add, Delete and Edit had been used.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    165

    Re: How to override a function in VB.NET

    Hello,

    My question is: I have a windows form where I've added a usercontrol containing a toolstrip menu, i want to be able inside the windows form to inherit for example the Add function of the toolstrip button. is this possible? and if so how can i do this?

    I know that a user control can inherit from another usercontrol.

    Thanks.

    Hiba

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.