From: Tom Shelton on
On 2010-03-19, Mr. X. <nospam(a)nospam_please.com> wrote:
> OK.
> Thanks.
>
> I put the code you gave me,
> and with or without it step 4 doesn't work :

I copied and pasted that out of a working project. So, if something isn't
working then you have something else going on.

> Maybe I need a code sample, of how to create simple user-control and put it
> on my form.
>

You grab it in the toolbox and drop it on the 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.
>

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
From: Mr. X. on
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 :)

From: Tom Shelton on
On 2010-03-19, Mr. X. <nospam(a)nospam_please.com> wrote:
> 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 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