C\#음악 재생 기 진도 바 사용자 정의
진도 바 반 짝 임 애니메이션,물론 배경 은 Transparent 로 설정 할 수 있 습 니 다.
진행 라인 을 손 으로 그 리 려 고 했 는데 컨트롤 이 실 행 될 때 반 짝 거 려 서 패 널 컨트롤 을 직접 사 용 했 습 니 다.
원본 코드:
[DefaultEvent("ProgressClick")]
[ToolboxBitmap(typeof(TrackBar))]
public partial class ProcessBar : UserControl
{
public ProcessBar()
{
//InitializeComponent();
//this.SetStyle(ControlStyles.UserPaint, true);
//this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
//this.SetStyle(ControlStyles.DoubleBuffer, true);
}
private int locationX=0;
[Description(" X ")]
public int LocationX
{
get { return locationX; }
}
private int current = 0;
[Description(" ")]
public int Current
{
get { return current; }
set
{
if (value > 232 || value < 0)
return;
current = value;
panelCurrent.Size = new Size(value, 1);
picture.Location = new Point(value - 4, -3);
Invalidate();
}
}
private bool isPlay = false;
[Description(" ")]
public bool IsPlay
{
get { return isPlay; }
set { isPlay = value; tmrCurrent.Enabled = isPlay; Invalidate(); }
}
public delegate void MouseHandle(object sender,EventArgs e);
[Description(" ")]
public event MouseHandle BarMouseDown;
int picturetype = 0;
private void tmrCurrent_Tick(object sender, EventArgs e)
{
if (picturetype == 0)
{ picture.Image = Properties.Resources.play_slider_thumb; picturetype = 1; }
else
{ picture.Image = Properties.Resources.play_slider_thumb_animate; picturetype = 0; }
GraphicsPath g = subGraphicsPath(picture.Image);
if (g == null) return;
picture.Region = new Region(g);
}
private unsafe static GraphicsPath subGraphicsPath(Image img)
{
if (img == null) return null;
// GraphicsPath,
GraphicsPath g = new GraphicsPath(FillMode.Alternate);
Bitmap bitmap = new Bitmap(img);
int width = bitmap.Width;
int height = bitmap.Height;
BitmapData bmData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
byte* p = (byte*)bmData.Scan0;
int offset = bmData.Stride - width * 3;
int p0, p1, p2; // 0,0
p0 = p[0];
p1 = p[1];
p2 = p[2];
int start = -1;
// ( Y col )
for (int Y = 0; Y < height; Y++)
{
// ( X row )
for (int X = 0; X < width; X++)
{
if (start == -1 && (p[0] != p0 || p[1] != p1 || p[2] != p2)) //
{
start = X; //
}
else if (start > -1 && (p[0] == p0 && p[1] == p1 && p[2] == p2)) //
{
g.AddRectangle(new Rectangle(start, Y, X - start, 1)); //
start = -1;
}
if (X == width - 1 && start > -1) //
{
g.AddRectangle(new Rectangle(start, Y, X - start + 1, 1)); //
start = -1;
}
p += 3; //
}
p += offset;
} bitmap.UnlockBits(bmData);
bitmap.Dispose();
//
return g;
}
private void panelTotal_MouseDown(object sender, MouseEventArgs e)
{
Current = e.Location.X;
locationX = e.Location.X;
if (BarMouseDown != null)
{
BarMouseDown.Invoke(sender, e);
}
}
private void panelCurrent_MouseDown(object sender, MouseEventArgs e)
{
Current = e.Location.X;
locationX = e.Location.X;
if (BarMouseDown != null)
{
BarMouseDown.Invoke(sender, e);
}
}
}
사용 한 소재:직접 오른쪽 단 추 를 누 르 면 그림 으로 저 장 됩 니 다.검은색 배경 을 사용 하 는 이 유 는 그림 이 흰색 이기 때문에 보이 지 않 기 때 문 입 니 다.더 말 할 필요 가 없습니다.
알림:unsafe 키 워드 를 사 용 했 습 니 다.항목 의 속성 을 설정 해 야 합 니 다.안전 하지 않 은 코드 를 실행 할 수 있 습 니 다.설정 되 지 않 은 학생 들 은 프로그램 이 틀 렸 다 고 생각 하지 마 십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.