-
Feb 23rd, 2009, 02:09 AM
#1
Thread Starter
Addicted Member
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
-
Feb 26th, 2009, 04:12 PM
#2
Re: How to override a function in VB.NET
In your toolstrip user control declare the function as Overridable
e.g.
vb.net Code:
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:
Public Overrides Sub AddButtonClick()
-
Feb 26th, 2009, 04:36 PM
#3
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 -
-
Feb 26th, 2009, 08:12 PM
#4
Frenzied Member
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.
-
Feb 26th, 2009, 08:22 PM
#5
Frenzied Member
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.
-
Feb 28th, 2009, 01:09 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|