저는 비디오 사용을위한 타임 라인 사용자 정의 컨트롤을 개발 중입니다. 여기 내 일의 사진입니다 : 은 사용자 정의 컨트롤의 일부만 업데이트합니다.
여기에 문제가 있습니다. currentTime이 변경되면 UI를 업데이트해야합니다. 하지만 내가 this.Invalidate()를 사용할 때; 전체 컨트롤을 새로 고칩니다. 하지만 포인터 (회색 배경의 흰색 선)를 업데이트하고 싶습니다. 매우 작은 시간이 지나면 컨트롤이 계속 깜박 거립니다. 포인터를 업데이트하는 방법은 무엇입니까? 여기 내 OnPaint를 방법
private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int width = this.Width;
int height = this.Height;
int Floor = height - FloorDistance;
Pen SecPen = new Pen(SecColor);
Pen MinPen = new Pen(MinColor);
SolidBrush TimeLineBrush = new SolidBrush(Color.Gray);
StringFormat stringFormat = new StringFormat();
SolidBrush TimesolidBrush = new SolidBrush(TimeColor);
SolidBrush BackBrush = new SolidBrush(TimlineBackColor);
SolidBrush PointerBrush = new SolidBrush(PointerColor);
stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
switch (Zoom)
{
case ZoomLEvel.Quarter:
width = (int)Math.Ceiling((TotalDuration/900)) * ThickDistance;
break;
case ZoomLEvel.Minute:
width = (int)Math.Ceiling((TotalDuration/60)) * ThickDistance;
break;
case ZoomLEvel.Secound:
width = (int)Math.Ceiling(TotalDuration) * ThickDistance;
break;
case ZoomLEvel.MiliSecound:
width = (int)Math.Ceiling(TotalDuration * 10) * ThickDistance;
break;
}
width += 11;
this.Width = width;
e.Graphics.FillRectangle(TimeLineBrush, 0, Floor, width, 3);
e.Graphics.FillRectangle(BackBrush, 0, 0, width, height - FloorDistance);
int x = ThickDistance;
int step = 0;
while (x <= width - ThickDistance)
{
if (step % 5 == 0)
{
e.Graphics.DrawLine(MinPen, x, Floor, x, Floor - _MinHeight);
// print time
string time = "";
double totalSecounds = 0;
PointF pointF = new PointF(x - 8, Floor + 5);
switch (Zoom)
{
case ZoomLEvel.Quarter:
totalSecounds = step * 900;
break;
case ZoomLEvel.Minute:
totalSecounds = step * 60;
break;
case ZoomLEvel.Secound:
totalSecounds = step;
break;
case ZoomLEvel.MiliSecound:
totalSecounds = step/10d;
break;
}
time = (new TimeSpan(0, 0, 0, (int)totalSecounds, (int)(step % 10) * 100)).ToString(@"hh\:mm\:ss\:fff");
e.Graphics.DrawString(time, this.Font, TimesolidBrush, pointF, stringFormat);
}
else
e.Graphics.DrawLine(SecPen, x, Floor, x, Floor - _SecHeight);
x += ThickDistance;
step++;
}
int PointerTime = 0;//(int)Math.Floor(CurrentTime);
int pointerX = 0;
switch (Zoom)
{
case ZoomLEvel.Quarter:
PointerTime = (int)Math.Floor(CurrentTime/900);
pointerX = PointerTime * ThickDistance;
break;
case ZoomLEvel.Minute:
PointerTime = (int)Math.Floor(CurrentTime/60);
pointerX = PointerTime * ThickDistance;
break;
case ZoomLEvel.Secound:
PointerTime = (int)Math.Floor(CurrentTime);
pointerX = PointerTime * ThickDistance;
break;
case ZoomLEvel.MiliSecound:
PointerTime = (int)Math.Floor(CurrentTime * 10);
pointerX = PointerTime * ThickDistance;
break;
}
pointerX += 5;
e.Graphics.FillRectangle(PointerBrush, pointerX, 0, 2, height - FloorDistance);
}
감사합니다. 나는 그것을 시도하고 돌아올거야 –
DoubleBuffered = 사실; 나를 위해 일했다. 감사 –