Create a Custom Control (not a User Control, AFAIK) 
Author Message
 Create a Custom Control (not a User Control, AFAIK)

I am wanting to inherit from the standard Button and
override the background color property; assigning the
new Button the name MyButton, as below:

------------------------------------------------------
   Imports System.WinForms

   Public Class MyButton : System.WinForms.Button  
      Me.BackColor = Color.LightGray
   End Class
------------------------------------------------------

I get the error:

   Expected variable, constant, Enum, Type, or procedural
   declaration.

under 'system'.

Can anyone show a 'tested' and 'proven' means, in VB,
to simply inherit from a standard control and override a
default property such as background color.  This should
be simple, but I have been unable to find a sample in
the SDK's.

MyButton needs to also appear, and be persistent, on the
ToolBox.

Thanks,  

Jim Holloman



Mon, 16 Jun 2003 07:56:27 GMT  
 Create a Custom Control (not a User Control, AFAIK)

Quote:

> I am wanting to inherit from the standard Button and
> override the background color property; assigning the
> new Button the name MyButton, as below:

> ------------------------------------------------------
>    Imports System.WinForms

>    Public Class MyButton : System.WinForms.Button  
>       Me.BackColor = Color.LightGray
>    End Class
> ------------------------------------------------------

You need the keyword "Inherits",

Public Class MyButton : Inherits System.WinForms.Button

Or more commonly,

Public Class MyButton
        Inherits System.WinForms.Button

--
Patrick Steele

Microsoft MCP



Mon, 16 Jun 2003 05:05:27 GMT  
 Create a Custom Control (not a User Control, AFAIK)
This will work. The easiest way is to
1. create a user control
2. edit the code to have it inherit from Button instead of usercontrol
3. compile, and the MyButton will be available on the toolbox and
usable from the IDE designer,
------------------------------------------------------
   Imports System.WinForms

   Public Class MyButton
            Inherits System.WinForms.Button
      Me.BackColor = Color.LightGray
   End Class
------------------------------------------------------



Mon, 16 Jun 2003 06:19:53 GMT  
 Create a Custom Control (not a User Control, AFAIK)

I am wanting to inherit from the standard Button and
override the background color property; assigning the
new Button the name MyButton, as below:

------------------------------------------------------
   Imports System.WinForms

   Public Class MyButton : System.WinForms.Button  
      Me.BackColor = Color.LightGray
   End Class
------------------------------------------------------

I get the error:

   Expected variable, constant, Enum, Type, or procedural
   declaration.

under 'system'.

Can anyone show a 'tested' and 'proven' means, in VB,
to simply inherit from a standard control and override a
default property such as background color.  This should
be simple, but I have been unable to find a sample in
the SDK's.

MyButton needs to also appear, and be persistent, on the
ToolBox.

Thanks,  

Jim Holloman



Mon, 16 Jun 2003 08:36:17 GMT  
 Create a Custom Control (not a User Control, AFAIK)
Thanks, J. W.  I like your approach of letting the
IDE generate the skeleton code.

I apparently managed to create the desired control,
but have been unable to get it to appear on the
toolbox.  Please see my followup post of 12-27-2K,
5:45a under "Creating Custom Controls...".

Quote:
> This will work. The easiest way is to
> 1. create a user control
> 2. edit the code to have it inherit from Button instead of usercontrol
> 3. compile, and the MyButton will be available on the toolbox and
> usable from the IDE designer,
> ------------------------------------------------------
>    Imports System.WinForms

>    Public Class MyButton
>             Inherits System.WinForms.Button
>       Me.BackColor = Color.LightGray
>    End Class
> ------------------------------------------------------



Mon, 16 Jun 2003 21:47:28 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Creating Custom Controls in VBNet (not User Control, AFAIK)

2. Custom user controls Not being added to ToolBox

3. Custom Control window could not be created in EXE

4. user controls and custom controls

5. Creating custom methods for a custom control

6. Create User Control as Data Source Using ADO Data Control

7. User Control - User-defined type not defined

8. Creating App for user to create Forms and Controls with VB

9. Enum problem in Custom User Control

10. User control or inherit to make custom button?

11. Trapping the right click event in a custom user control

12. User Control in User Control

 

 
Powered by phpBB® Forum Software