단색 배경색, 그라디언트 배경색 또는 그림을 표시 할 수 있도록 설계된 사용자 지정 패널이 있습니다.패널에서 파생 된 사용자 정의 컨트롤로 OnPaint 루프에 고정 된 경우
내가 지금처럼 BackgroundImage 속성과 OnPaint 메서드를 모두 무시했습니다
protected override void OnPaint(PaintEventArgs pe){
Rectangle rc = new Rectangle(0, 0, this.Width, this.Height);
if (this.DrawStyle != DrawStyle.Picture){
base.BackgroundImage = null;
if (this.DrawStyle == DrawStyle.Solid){
using (SolidBrush brush = new SolidBrush(this.PrimaryColor))
pe.Graphics.FillRectangle(brush, rc);
}
else if (this.DrawStyle == DrawStyle.Gradient){
using (LinearGradientBrush brush =
new LinearGradientBrush(
rc, this.PrimaryColor, this.SecondaryColor, this.Angle))
pe.Graphics.FillRectangle(brush, rc);
}
}
else if (this._BGImage != null)
base.BackgroundImage = this._BGImage;
}
public override Image BackgroundImage{
get { return this._BGImage; }
set { this._BGImage = value; }
}
존재가 컨트롤이시의 배경 형식 (단색, 그라데이션 또는 그림)을 변경할 수있을만큼 유연해야한다는 것입니다 이유 실행 시간이므로 컨트롤이 설정된 배경 이미지를 유지하고 필요할 때 표시합니다.
그러나 문제가 있습니다.
배경 이미지를 설정하지 않으면 문제가 없습니다. OnPaint는 약 5 번 호출 된 다음 잘됩니다.
그러나 배경 이미지를 설정하면 OnPaint를 계속해서 반복해서 호출하는 것이 좋지 않은 것처럼 보입니다.
이것은 분명히 배경 이미지를 덮어 쓰는 것과 관련이 있습니다. 끊어지기 때문에 문제가됩니다. 패널 모양을 바꿀 때까지 패널의 아무 것도 업데이트되지 않습니다.
내가 가지고있는 질문은 배경 이미지를 설정할 때 왜이 OnPaint 루프에서 멈추는 것일까 요? 이 밖에
최신 업데이트가 실제 질문을 삭제했기 때문에 나는 원래 질문으로 포스트를 굴렸다. – LarsTech