이 그림에서 ... ... 각 "선 색"레이블 옆에 색칠 된 원이 있습니다.UserControl의 사용자 지정 컨트롤이 올바르게 렌더링되지 않습니다.
색이 지정된 원은 내 프로젝트에서 견본입니다.
public class Swatch : System.Windows.Forms.Panel
{
/*private int _Radius = 20;
[System.ComponentModel.Category("Layout")]
public int Radius
{
get { return _Radius; }
set { _Radius = value; }
} */
private System.Drawing.Color _BorderColor = System.Drawing.Color.Transparent;
[System.ComponentModel.Category("Appearance")]
public System.Drawing.Color BorderColor
{
get { return _BorderColor; }
set { _BorderColor = value; }
}
private System.Drawing.Color _FillColor = System.Drawing.Color.Blue;
[System.ComponentModel.Category("Appearance")]
public System.Drawing.Color FillColor
{
get { return _FillColor; }
set { _FillColor = value; }
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
System.Drawing.Rectangle RealRect = new System.Drawing.Rectangle(e.ClipRectangle.Location, e.ClipRectangle.Size);
RealRect.Inflate(-1, -1);
int Radius = Math.Min(RealRect.Size.Height, RealRect.Size.Width);
System.Drawing.Rectangle SqRect = new System.Drawing.Rectangle();
SqRect.Location = RealRect.Location;
SqRect.Size = new System.Drawing.Size(Radius, Radius);
System.Drawing.Drawing2D.CompositingQuality PrevQual = e.Graphics.CompositingQuality;
using (System.Drawing.SolidBrush Back = new System.Drawing.SolidBrush(this.FillColor))
{
using (System.Drawing.Pen Pen = new System.Drawing.Pen(new System.Drawing.SolidBrush(this.BorderColor)))
{
//e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
e.Graphics.FillEllipse(Back, SqRect);
e.Graphics.DrawEllipse(Pen, SqRect);
}
}
e.Graphics.CompositingQuality = PrevQual;
}
public Swatch()
{
this.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);
this.SetStyle(System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(System.Windows.Forms.ControlStyles.ResizeRedraw, true);
this.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true);
this.DoubleBuffered = true;
}
}
각 행은 TableLayoutPanel, 라벨, 견본 제어 및 NumericUpDown 상자로 구성되어 UserControl이 있습니다 : 여기에 견본에 대한 전체 코드 파일입니다.
약 10 개의 행이 TabLayoutPanel에 배치되며 TabLayoutPanel은 탭 컨트롤의 TabPage 안에 위치합니다. 탭 페이지가 AutoScroll
이 true
으로 설정되어 오버플로로 인해 탭 페이지가 스크롤됩니다.
문제 내가 응용 프로그램을 실행하고 위아래로 스크롤 할 때마다 위의 그림에서 볼 수 있듯이 견본 (컬러 원) 눈물과는 유물의 모든 종류를 보여줄 것입니다. 렌더링 유물이없는 깨끗한 스크롤을하고 싶습니다.
나는 (Painting problem in windows form에서 제안한대로) SetStyle
을 사용해 보았지만 효과가 없었습니다.
UserControl (각 행)은 DoubleBuffered
이 true
으로 설정되어 있으며 아무런 영향도 미치지 않았습니다.
나는 두려운 것이 다소 분명한 사실을 알고있다.
대단히 감사합니다! 이것은 효과가있다! – kevin628