UserControl
에 button
이 있습니다. UserControl
OnPaint
이벤트에서 둥근 모서리 경계선 (또는 반지름이 0 인 경우 간단한 직사각형)을 그린 다음 전체 컨트롤을 채 웁니다. 이러한 조작 후 내 Button
(btnClose
) 사라집니다. button
을 다시 표시하려면 어떻게해야합니까?UserControl OnRepaint 이벤트 후 부모 UserControl 컨트롤이 사라집니다.
protected override void OnPaint(PaintEventArgs pe)
{
using (System.Drawing.Pen p = new Pen(new SolidBrush(this.BorderColor)))
{
if (borderRadius > 0)
{
DrawRoundRect(pe.Graphics, p, 0, 0, this.Width - 1, this.Height - 1, borderRadius, this.FillColor);
}
else
{
this.BackColor = this.FillColor;
pe.Graphics.DrawRectangle(p, 0, 0, this.Width - 1, this.Height - 1);
}
btnClose.Location = new Point(this.Width - btnClose.Width - BTN_MARGIN_DELTA, BTN_MARGIN_DELTA);
}
base.OnPaint(pe);
}
그냥 경우, 것은 drawRoundRect 기능 : 페인트 이벤트에 컨트롤을 이동
protected override void OnResize(EventArgs e) {
btnClose.Location = new Point(this.Width - btnClose.Width - BTN_MARGIN_DELTA, BTN_MARGIN_DELTA);
}
는에 재귀 호출이 발생할 수 :
void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius, Color _fillColor)
{
using (GraphicsPath gp = new GraphicsPath())
{
gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);
gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);
gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));
gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);
gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);
gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);
gp.CloseFigure();
using (SolidBrush brush = new SolidBrush(_fillColor))
{
g.FillPath(brush, gp);
g.DrawPath(p, gp);
}
}
}
글쎄, 내 실수 였어. UserControl에서 모든 컨트롤을 삭제하는 함수였습니다. 코드는 아래에 제공됩니다. 어쨌든, OnResize는 버튼의 올바른 위치를 확립하는 데 도움이되었습니다. – kirpi4