This article mainly for you in detail the C # Custom music player progress bar effect, with a certain reference value, interested in small partners can refer to
Sometimes the program we do requires a progress bar, and VS provides a control that is not what we want. Look first:
Progress bar flashing animation, of course background can be set to transparent
If you want to draw the progress bar before, the result will blink when the control is run, so the Panel control is used directly
Source:
[DefaultEvent ("Progressclick")] [ToolboxBitmap (typeof (TrackBar))] public partial class Processbar:usercontrol {public Processbar () {//ini Tializecomponent (); This. SetStyle (Controlstyles.userpaint, true); This. SetStyle (Controlstyles.allpaintinginwmpaint, true); This. SetStyle (Controlstyles.doublebuffer, true); } private int locationx=0; [Description ("x's coordinates when clicked")] public int Locationx {get {return locationx;} } private int current = 0; [Description ("Current Progress")] public int Current {get {return present;} 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 ("Play")] public bool Isplay {get {return isplay;} set {isplay = value; tmrcurrent.enabled = Isplay; Invalidate (); } public delegate void Mousehandle (Object Sender,eventargs e); [Description ("Mouse Down")] 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; Build GraphicsPath, give us the bitmap path calculation using 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; Record top left corner 0, 0 coordinates color value p0 = p[0]; P1 = p[1]; P2 = p[2]; int start =-1; Row coordinates (Y col) for (int y = 0; Y < height; y++) {//column coordinates (x row) for (int x = 0; X < width; X + +) {if (start = 1 && (p[0]! = P0 | | p[1]! = P1 | | p[2]! = p2)//If the previous point is not opaque and opaque {start = X; Record this point} else if (Start >-1 && (p[0] = = P0 && p[1] = P1 && p[2] = = p2)) If the previous point is opaque and transparent {g.addrectangle (start, Y, X-start, 1)); Add the previous rectangle to start =-1; } if (X = = width-1 && Start >-1)//If the previous point is opaque and is the last point {g.addrectangle (NE W Rectangle (Start, Y, X-start + 1, 1)); Add the previous rectangle to start =-1; } p + = 3; //Next memory address} p + = offset; } bitmap. Unlockbits (Bmdata); Bitmap. Dispose (); Returns the computed opaque image path 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); } } }
The material used:
Directly right-click to save as a picture, the reason for the black background is because the picture is white, not to say more.
Tip: The unsafe keyword is used here, you need to set the project's properties-----allow unsafe code to run, not set the classmate do not think the program is wrong