From: Mr. X. on
Yes.
But when I create a class, and inherits Panel - I cannot see it as a
component, which I can put buttons, etc.
How can I make my class, that is inherited the Panel, and it could be seen,
with property editor, and component editor, and put some elements on it,
like the userControl ?

Thanks :)

"Armin Zingler" <az.nospam(a)freenet.de> wrote in message
news:#IPEvQ2xKHA.3560(a)TK2MSFTNGP02.phx.gbl...
> Am 19.03.2010 12:42, schrieb Mr. X.:
>> Sorry.
>> What I did : add new item - > user control.
>> On the new class/control (menuButton.vb) I wrote :
>> Public Class MenuButton
>> Inherits Panel
>>
>> That's all.
>
> Do you want to derive your class from Usercontrol or from Panel?
>
> If you've created a Usercontrol as you've desribed, you can
> not inherit from Panel.
>
> If you want to inherit from Panel, you must not create a Usercontrol
> as described. Instead just add a new class (add new item -> class).
>
>
> --
> Armin

From: Mr. X. on
OK.
Now I see that when I declare my new class as a class (and not userControl)
Public Class MenuButton
Inherits Panel
....

I can right click, and choose : "View designer".

A little problem is, when I put a button component on it (from toolbox) - I
cannot control the behavior of the button (size, color, etc.)

Is there anything else I should declare ?

Thanks :)



From: Armin Zingler on
Am 19.03.2010 17:15, schrieb Mr. X.:
> Yes.
> But when I create a class, and inherits Panel - I cannot see it as a
> component, which I can put buttons, etc.
> How can I make my class, that is inherited the Panel, and it could be seen,
> with property editor, and component editor, and put some elements on it,
> like the userControl ?

The Visual Studio IDE has designers for Forms and UserControls, and for Components.
A Panel is none of these. Therefore, you must create a Usercontrol if you
want to use a designer. Is there something special about a Panel that a Usercontrol
can not do?

Panel inherits from ScrollableControl.
Usercontrol inherits from ContainerControl that again inherits from ScrollableControl.


--
Armin
From: Tom Shelton on
On 2010-03-19, Mr. X. <nospam(a)nospam_please.com> wrote:
> Yes.
> But when I create a class, and inherits Panel - I cannot see it as a
> component, which I can put buttons, etc.
> How can I make my class, that is inherited the Panel, and it could be seen,
> with property editor, and component editor, and put some elements on it,
> like the userControl ?
>
> Thanks :)

Mr. X - it sounds like you are tryign to create a custom container control?
Basically, a user control that when you add it to a form at design time you
can add stuff to it?

Step 1:

Add a new user control to your project (or library)

Step 2:
Add the following attribute to your user control:

Option Explicit On
Option Strict On

Imports System.ComponentModel
Imports System.ComponentModel.Design

<Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", GetType(IDesigner))> _
Public Class UserControl1


End Class

Step 3:
Compile

Step 4: drag the control to your form - you can now add other controls to it
at design time.

--
Tom Shelton
From: Mr. X. on
OK.
Thanks.

I put the code you gave me,
and with or without it step 4 doesn't work :
Maybe I need a code sample, of how to create simple user-control and put it
on my form.

I saw the user-control of mine on the toolbox, and just did : drag & drop.
What I get is an exception.
Too long, so I can give it on brief :
Failed to create component 'MenuButton'. The error message follows :
'System.MissingMethodException : Constructor on type 'myApp.MenuButton' not
found at
System.RuntimeType.CreateInstanceImp(BindingFlag ...) ...
at ...
at ...
at ...
at System.Drawing.Design.ToolboxItem.CreateComponentsCore(IDesigner Host
host, IDictionary defaultValues) at Sy ...

****
I cannot see the whole exception, but it seems I didn't declare the
constructor as I should do.
What I have written in code :
-------------------------------------
Public Sub New(ByVal aImageFile As String, ByVal aText As String)
InitializeComponent()
End sub

I need sample code, or tutorial to create a simple user-control, please.

Thanks :)