Abt. extending windows form control

  • Thread starter Thread starter rajendra
  • Start date Start date
R

rajendra

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
 
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'"
 
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/default.asp?url=/library/en-us/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
 
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
 
Back
Top