Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In .NET, how do you make a customized control that does not display on the windows form?

How do you make a customized control that does not display on the windows form, like the SerialPort or the BackgroundWorker or ImageList control?

like image 851
LEMUEL ADANE Avatar asked Dec 22 '22 15:12

LEMUEL ADANE


2 Answers

Inherit from Component rather than Control.

like image 97
Joel Coehoorn Avatar answered Mar 08 '23 00:03

Joel Coehoorn


Add a new class to your project and paste the code shown below. Compile. Drop the new component from the top of the toolbox onto the form. Embellish as desired.

using System;
using System.ComponentModel;

[DefaultProperty("Aardvark")]
class MyFoo : Component {
    public MyFoo() { }
    public MyFoo(IContainer container) { container.Add(this); }

    [DefaultValue(0)]
    public int Aardvark { get; set; }
}
like image 32
Hans Passant Avatar answered Mar 08 '23 01:03

Hans Passant