Visual Studio
(1)
MissingMethodException
(1)
UserControl
(1)
IDesigner
(1)
VB
(1)
Control
(1)
IDictionary
(1)
Compile
(1)

inherits class.

Asked By Mr. X.
19-Mar-10 06:54 AM
Hello.
I want to create a new class (VB 2008).

What I did :
add new class.
and wrote :

Public Class MenuButton
Inherits Panel
...

The code is not compiled :
Error	1	Base class 'System.Windows.Forms.Panel' specified for class
'MenuButton' cannot be different from the base class
'System.Windows.Forms.UserControl' of one of its other partial types.

I need little sample code, so I can go on ..., please.

Thanks :)

Am 19.03.2010 11:54, schrieb Mr. X.

Armin Zingler replied to Mr. X.
19-Mar-10 07:16 AM
Am 19.03.2010 11:54, schrieb Mr. X.:

You've (also) created a UserControl with the name "MenuButton", did not you?


--
Armin

Sorry.What I did : add new item - > user control.

Mr. X. replied to Armin Zingler
19-Mar-10 07:42 AM
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.

Thanks :)

"Mr. X.

Family Tree Mike replied to Mr. X.
19-Mar-10 08:31 AM
In the solution explorer, there is a button that says "Show All Files" when
you hover over it.  Your user control has a second .designer file that is
associated with your code file.  You changed the inheritance in one file, but
not the other, thus the confusion.

It is actually a lot easier in the long run to not do what you did.  You
should just add a class as normal, so you do not get the designer file.  Then
you do not run into this issue when you add the inherit statement.

Mike
Am 19.03.2010 12:42, schrieb Mr. X.
Armin Zingler replied to Mr. X.
19-Mar-10 09:00 AM
Am 19.03.2010 12:42, schrieb Mr. X.:

Do you want to derive your class from Usercontrol or from Panel?

If you have created a Usercontrol as you have 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
Yes.
Mr. X. replied to Armin Zingler
19-Mar-10 12:15 PM
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 :)
OK.
Mr. X. replied to Mr. X.
19-Mar-10 01:03 PM
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 :)
Am 19.03.2010 17:15, schrieb Mr. X.
Armin Zingler replied to Mr. X.
19-Mar-10 01:06 PM
Am 19.03.2010 17:15, schrieb Mr. X.:

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
Mr. X - it sounds like you are tryign to create a custom container control?
Tom Shelton replied to Mr. X.
19-Mar-10 01:27 PM
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

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
OK.Thanks.
Mr. X. replied to Tom Shelton
19-Mar-10 02:27 PM
OK.
Thanks.

I put the code you gave me,
and with or without it step 4 does not 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 did not 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 :)
I copied and pasted that out of a working project.
Tom Shelton replied to Mr. X.
19-Mar-10 02:34 PM
I copied and pasted that out of a working project.  So, if something is not
working then you have something else going on.


You grab it in the toolbox and drop it on the form :)


To work in the designer, you control MUST have a default constructor...

Public Sub New()
InitializeComponent()
End Sub

You can add additional constructors, but they will not be called by the
designer.  They are usually only useful for dynamically created controls.

Your probably better off not having a custom constructor and then making the
imagefile and text parameters correspond to properties that can be set in the
designer.


--
Tom Shelton
Thanks a lot.That's solved the problem (of the exception).
Mr. X. replied to Tom Shelton
19-Mar-10 05:35 PM
Thanks a lot.

That's solved the problem (of the exception).

Now :
I want that the user-control, should be an external one, so I can load it to
some projects.
How can I do so ?
With some property editors, and component editors, etc....

Thanks :)
Then you create a Windows Forms Control library project, and make it a
Tom Shelton replied to Mr. X.
19-Mar-10 05:48 PM
Then you create a Windows Forms Control library project, and make it a public
control.  The other stuff...  Well, your asking a lot for one post :)  But, I
do have an example of a component that does some of that on my blog:

http://tom-shelton.net/index.php/2009/10/07/creating-a-simple-hotkey-component-using-registerhotkey/


--
Tom Shelton
Post Question To EggHeadCafe