After opening a custom control, you can drag the control on the toolbar to the custom control. After observing the pannel control, it seems very simple.
Inherited from scrollablecontrol, while scrollablecontrol inherited from control. Both classes do not overwrite the painting, but add some attributes and override some attribute values. Control has a set attribute of controls. It seems that most of the work has been done.
I tried to add a button directly to Control. controls.
Code public class trackpannel: Control
{
//...
Private void drawtrack (Graphics GC, rectangle rect)
{
Int ibottony = rect. Y + rect. height;
Int icur = 0;
// Int iindex = 0;
While (icur <rect. width)
{
// Iindex ++;
Icur = icur + this. tackspacing;
GC. drawline (pens. Black, icur, 2, icur, ibottony );
}
Button BTN = new button ();
BTN. Click + = new eventhandler (btn_click );
This. Controls. Add (BTN );
}
//
The button is displayed normally and receives a click event. Prove that I am right. Take a closer look at scrollablecontrol. Two steps are required.
1. Set controlstyles. containercontrol
2. Set Designer
The modified code is as follows.
Code [designer ("system. Windows. Forms. Design. parentcontroldesigner, system. Design ",
Typeof (system. componentmodel. Design. idesigner)]
Public class trackpannel: Control
{
/// <Summary>
/// Constructor
/// </Summary>
Public trackpannel ()
{
Base. setstyle (controlstyles. userpaint, true );
Base. setstyle (controlstyles. containercontrol, true );
}
//...
"Base. setstyle (controlstyles. userpaint, true);" indicates the onpaint that the program uses to override by the control. It cannot be rewritten. You have to set this parameter! At half past one, it's really hard to touch.