By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,569 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Abt. extending windows form control

P: n/a
how to extend existing windows forms control like if i
want to add new add method to combo box ,how to go abt. it?
can anyone help me abt. this
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi, first off, you need to create a class. Then that class inherits from
what you wish to extend. You add your extra methods/properties and compile
your assembly. You can then add your assembly to your toolbox, and see your
new control:

'///
Public Class MyComboBox
Inherits System.Windows.Forms.ComboBox

Public Sub New()
MyBase.New()
End Sub

Public Sub MyCustomMethod()
MsgBox("Hello, World.")
End Sub
End Class
'///

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"rajendra" <ra***************@rediffmail.com> wrote in message
news:35****************************@phx.gbl...
how to extend existing windows forms control like if i
want to add new add method to combo box ,how to go abt. it?
can anyone help me abt. this

Nov 20 '05 #2

P: n/a
Hi Rajendra,

It's in fact very easy to do:

Here's the article in MSDN. Note that the URL is split. You'll have to
join the two lines to follow the link.

http://msdn.microsoft.com/library/de.../vbcon/html/vb
conwalkthroughcreatingcompositewfccontrol.asp

I've copied part of the page for you to read here.

If you want to extend the functionality of an existing control, you can
create a control derived from an existing control through inheritance. When
inheriting from an existing control, you inherit all of the functionality and
visual properties of that control.

For instance, if you were creating a control that inherited from Button,
your new control would look and act exactly like a standard Button control.
You could then extend or modify the functionality of your new control through
the implementation of custom methods and properties.

In some controls, you can also change the visual appearance of your
inherited control by overriding its OnPaint method.

To create an inherited control

1]. Create a new Windows project.
This project can be of any type, such as a Windows Application project or a
Windows Control Library project. If you choose a Windows Control Library, you
may use the blank control provided and skip steps 2 and 3.

2]. From the Project menu, choose Add Inherited Control.
The Add New Item dialog box appears.

3]. In the Add New Item dialog box, double-click Custom Control.
A new custom control is added to your project.

4]. In the Code Editor, locate the line that specifies Control as the base
class to inherit from. Change the name of the base class to the name of the
control from which you want to inherit.

For example, if you want to inherit from Button, the line would read:
Inherits System.Windows.Forms.Button

Regards,
Fergus
Nov 20 '05 #3

P: n/a
Hello,

"rajendra" <ra***************@rediffmail.com> schrieb:
how to extend existing windows forms control like if i
want to add new add method to combo box ,how to go abt. it?
can anyone help me abt. this


http://msdn.microsoft.com/library/en...fccontrols.asp

--
Herfried K. Wagner
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 20 '05 #4

P: n/a
Hi Rajendra,

Right article but wrong link. I copied in the link to the page I was on
beforehand.

Herfried has given the correct link in the post below mine.

Regards,
Fergus
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.