void vbar_OnChangeVolume(object sender, EventArgs e) { if (myBasicAudio != null) { float volume = (float)vbar.Volume; volume = volume / ((float)vbar.ContentRectangle.Width / 2500); int value = -(2500 - (int)volume); if (value < -2500) value = -2500; if (value > 0) value = 0; SetImageForValue(value); myBasicAudio.Volume = value; } }
private void InitControl() { layout = new GraphicLayout(); plearList = new PlayerList(); Owner.Disposed += Owner_Disposed; Owner.Resize += Owner_Resize; layout.BackColor = Color.Transparent; layout.Dock = DockStyle.Top; layout.TabIndex = 0; layout.Padding = new System.Windows.Forms.Padding(5); layout.Size = new System.Drawing.Size(373, 101); plearList.Dock = DockStyle.Fill; plearList.PlayIndex = -1; plearList.BackColor = System.Drawing.Color.Transparent; plearList.Size = new Size(1, 1); plearList.Location = new Point(1, 1); plearList.TabIndex = 1; try { plearList.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); } catch { } playTimer.Interval = 100; playTimer.Elapsed += playTimer_Tick; addPointStr.Interval = 200; addPointStr.Elapsed += addPointStr_Tick; Owner.Controls.Add(plearList); Owner.Controls.Add(layout); nowPlayMusic = new GraphicLabelScroll { ContentRectangle = new Rectangle(8, 5, Owner.Width - 16, 20), Text = "当前没有播放音乐!", TextAlign = GraphicTextAlign.LeftTop, Font = plearList.Font, ForeColor = Owner.ForeColor }; playerControl = new PlayerBar { ContentRectangle = new Rectangle(12, 25, Owner.Width - 60, 45) }; nowTimer = new GraphicLabelPlus { ContentRectangle = new Rectangle(12, 25, Owner.Width - 16, 45), TextAlign = GraphicTextAlign.MiddleRight, AutoSize = false, ForeColor = Owner.ForeColor, Font = plearList.Font, Text = "00:00" }; GradientButton stopMusic = new GradientButton { ContentRectangle = new Rectangle(8, 58, 35, 35), Image = manager.Stop, IsShowBorder = false }; stopMusic.OnClick += stopMusic_OnClick; GradientButton upMusic = new GradientButton { ContentRectangle = new Rectangle(8 + 40, 58, 35, 35), Image = manager.UpMusic, IsShowBorder = false }; upMusic.OnClick += upMusic_OnClick; playPause = new GradientButton { ContentRectangle = new Rectangle(8 + (40 * 2), 58, 35, 35), Image = manager.Play, IsShowBorder = false }; playPause.OnClick += playPause_OnClick; GradientButton nextMusic = new GradientButton { ContentRectangle = new Rectangle(8 + (40 * 3), 58, 35, 35), Image = manager.NextMusic, IsShowBorder = false }; nextMusic.OnClick += nextMusic_OnClick; volume = new GradientButton { ContentRectangle = new Rectangle(8 + (40 * 4), 58, 35, 35), Image = manager.VMiddle, IsShowBorder = false }; volume.OnClick += volume_OnClick; loopmode = new GradientButton { ContentRectangle = new Rectangle(layout.Left + layout.Width - 40, 58, 35, 35), Image = manager.LoopList, IsShowBorder = false }; loopmode.OnClick += loopmode_OnClick; downloadButton = new GradientButton { ContentRectangle = new Rectangle(layout.Left + layout.Width - 40 * 2, 58, 35, 35), Image = manager.Download, IsShowBorder = false }; downloadButton.OnClick += downloadButton_OnClick; vbar = new VolumeBar { ContentRectangle = new Rectangle(8 + (40 * 5) + 5, 58, 70, 35) }; vbar.OnChangeVolume += vbar_OnChangeVolume; vbar.Volume = 70f; SetImageForValue((int)vbar.Volume); playerControl.OnChangePlayPos += playerControl_OnChangePlayPos; playerControl.SetOk += playerControl_SetOk; layout.GraphicControls.Add(nowPlayMusic); layout.GraphicControls.Add(playerControl); layout.GraphicControls.Add(nowTimer); layout.GraphicControls.Add(stopMusic); layout.GraphicControls.Add(upMusic); layout.GraphicControls.Add(playPause); layout.GraphicControls.Add(nextMusic); layout.GraphicControls.Add(volume); layout.GraphicControls.Add(loopmode); layout.GraphicControls.Add(vbar); layout.GraphicControls.Add(downloadButton); plearList.OnItemDoubleClick += playerList1_OnItemDoubleClick; plearList.OnNumber += playerList1_OnNumber; }