.NET Framework - 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 :)
Visual Studio
(1)
MissingMethodException
(1)
UserControl
(1)
IDesigner
(1)
VB
(1)
Control
(1)
IDictionary
(1)
Compile
(1)
Armin Zingler replied to Mr. X.
Am 19.03.2010 11:54, schrieb Mr. X.:
You've (also) created a UserControl with the name "MenuButton", did not you?
--
Armin
Mr. X. replied to Armin Zingler
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 :)
Family Tree Mike replied to Mr. X.
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
Armin Zingler replied to Mr. X.
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
Mr. X. replied to Armin Zingler
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. replied to Mr. X.
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 :)
Armin Zingler replied to Mr. X.
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
Tom Shelton replied to Mr. X.
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
Mr. X. replied to Tom Shelton

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 :)
Tom Shelton replied to Mr. X.
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
Mr. X. replied to Tom Shelton
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 :)
Tom Shelton replied to Mr. X.
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
do this? Thanks in advance Francesco .NET Compact Framework Discussions GetFunctionPointerForDelegate (1) Compact Framework (1) Visual Studio (1) MissingMethodException (1) PtrToStringUni (1) ArrayOfSizesOfThisFont (1) LpEnumFontFamExProc (1) MyComboBoxFontList (1) I've found this example. . . it could be usefull for me if it will run. But an error occurs: MissingMethodException at FontList_Create() Please help me!! ' YaoDurant.Drawing.FontCollection.vb - Font enumeration ' wrapper class for FONTLIST I've downloaded your project: my .net 2003 says "project created with newer version of Visual Studio". Ok. . . I've opened each file instead the project. . . code is C#. . . I haven't
MissingMethodException auf vereinzelten Rechnern, . . . .NET Framework Hallo, ich habe da so eine Frage, die ich mir mal nicht beantworten kann, oder erst mal konnte. Auf vereinzelten Rechnern, bekomme ich die Fehlermeldung "MissingMethodException" für System.Drawing.SystemIcons.Shield.ToBitmap(). Laut der WINUSER.h in dem DDK / SDK ist German Discussions System.Drawing.SystemIcons.Shield.ToBitmap (1) Windows XP (1) System.Console.WriteLine (1) Visual Studio (1) MissingMethodException (1) Vista (1) SystemIcons.Shield (1) SystemIcons (1) Hallo Kerem, Ist ja nur in: 3 Neben dem was bereits gesagt wurde: Bitte beachte auch, dass der Aufruf NICHT für die MissingMethodException verantwortlich ist, sondern die Kompilierung (normalerweise) über den JIT-Kompiler. Es ist somit irrelevant, ob this if VS is not installed in C: \ Program Files! call "C: \ Program Files \ Microsoft Visual Studio 8 \ VC \ vcvarsall.bat" echo public class Lib { > lib.cs echo public static void Function
function, I get the following errors on my desktop (I am debugging the code from Visual Studio): = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = An unhandled exception of type 'System.MissingMethodException' occurred in System.Windows.Forms.dll Additional information: File or assembly name 'OpenNETCF.Windows.Forms crash, it just does not do anything! Thanks for your help! - - Smart Phone Developer Discussions Visual Studio (1) OpenNETCF (1) DateTimePicker (1) PublicKeyToken (1) SmartPhone (1) SendKeys (1) SenkKeys (1) Einstein (1
the memory will be totally freed. As I can see there is a bug in Visual Studio 2005. The object ‘components‘ is created, but never used by the designer. The overridden best regards Chris .NET Compact Framework Discussions System.GC.GetTotalMemory (1) System.ComponentModel.Container (1) Visual Studio 2005 (1) MissingMethodException (1) OpenNETCF (1) GetTotalMemory (1) XP (1) ShowDialog (1) Yes, we have applications that run 24 / 7 with CF 2.0 (written in Studio 05, but I don't think that matters) and have not seen any leak. I from about 2.7MB to ~19MB when I finally see an OutOfMemory exception and sometimes MissingMethodException (presumably becuase there's no memory to place JITted code that has been pitched!). Thanks