Panel
이 수행하는 방식 (이것이 실제 올바른 방법임을 나타냄)은 DesignerAttribute
입니다. 이 속성은 Control
구성 요소와 비 제어 구성 요소 (예 : Timer
)에 대한 설계 시간 추가에 사용할 수 있습니다.
DesignerAttribute
을 사용할 때 IDesigner
에서 파생 된 클래스를 지정해야합니다. 특히 Control
디자이너의 경우 ControlDesigner
에서 파생되어야합니다.
ControlDesigner
의 특정 구현에서는 OnPaintAdornment
을 무시하고 싶습니다. 이 메서드의 목적은 특히 테두리와 같이 컨트롤 위에 디자이너 힌트를 그리는 것입니다.
Panel
이 사용하는 구현은 다음과 같습니다. 복사하여 제어를 위해 사용할 수는 있지만, 구체적으로 Panel
클래스를 참조하는 부분을 조정해야합니다.
internal class PanelDesigner : ScrollableControlDesigner
{
protected Pen BorderPen
{
get
{
Color color = ((double)this.Control.BackColor.GetBrightness() < 0.5) ? ControlPaint.Light(this.Control.BackColor) : ControlPaint.Dark(this.Control.BackColor);
return new Pen(color)
{
DashStyle = DashStyle.Dash
};
}
}
public PanelDesigner()
{
base.AutoResizeHandles = true;
}
protected virtual void DrawBorder(Graphics graphics)
{
Panel panel = (Panel)base.Component;
if (panel == null || !panel.Visible)
{
return;
}
Pen borderPen = this.BorderPen;
Rectangle clientRectangle = this.Control.ClientRectangle;
int num = clientRectangle.Width;
clientRectangle.Width = num - 1;
num = clientRectangle.Height;
clientRectangle.Height = num - 1;
graphics.DrawRectangle(borderPen, clientRectangle);
borderPen.Dispose();
}
protected override void OnPaintAdornments(PaintEventArgs pe)
{
Panel panel = (Panel)base.Component;
if (panel.BorderStyle == BorderStyle.None)
{
this.DrawBorder(pe.Graphics);
}
base.OnPaintAdornments(pe);
}
}
ScrollableControlDesigner
당신이 또는 특정 디자이너 구현을위한 기지로 사용하지 않을 수있다 공공 클래스입니다.