• 大小: 0.04M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-05-01
  • 语言: C#
  • 标签:

资源简介

演示如何自制类似TrackBar控件,效果好看,编码简单,无须自定义控件,也无须重绘,一看就会,滑块样式万能,随心所欲,图片随便换,只有想不到,没有做不到。有什么意见欢迎回复评价,共同交流提高。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VolControl
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

      
    
        
        int p3y = 45 p2y = 77; 
        
        Point pClicked;
        int xPos;
        int yPos;
        bool MoveFlag;


        private void Form1_Load(object sender EventArgs e)
        {

            pictureBox2.Parent = panel1;
            pictureBox3.Parent = panel1;
        }

        private void pictureBox3_MouseDown(object sender MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MoveFlag = true;//已经按下.
                xPos = e.X;//当前x坐标.
                yPos = e.Y;//当前y坐标.

            }
        }

        private void pictureBox3_MouseMove(object sender MouseEventArgs e)
        {
            if (MoveFlag)
            {
                pClicked.X+= Convert.ToInt16(e.X - xPos);//设置x坐标.
                if (pClicked.X > 212)
                    pClicked.X = 212;
                if (pClicked.X < 89)
                    pClicked.X = 89;
                pClicked.Y = p3y;
                pictureBox3.Location = pClicked;

              decimal ss = (pClicked.X - 89)*100 / (212 - 89);

              label1.Text = pClicked.X.ToString() + ““+p3y.ToString()+“  “ + ss.ToString() + “%“;
            }
         
        }

        private void pictureBox3_MouseUp(object sender MouseEventArgs e)
        {
            MoveFlag = false;
        }

        private void button1_Click(object sender EventArgs e)
        {
            pClicked.X = pictureBox3.Location.X;
            pClicked.Y = p3y;
;
            if (pClicked.X <= 212)
            {
                
                pClicked.X = pClicked.X + 5;
                pictureBox3.Location = pClicked;
            }
        }

        private void pictureBox2_MouseDown(object sender MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MoveFlag = true;//已经按下.
                xPos = e.X;//当前x坐标.
                yPos = e.Y;//当前y坐标.

            }
        }

        private void pictureBox2_MouseMove(object sender MouseEventArgs e)
        {
            if (MoveFlag)
            {
                pClicked.X += Convert.ToInt16(e.X - xPos);//设置x坐标.
                if (pClicked.X > 212)
                    pClicked.X = 212;
                if (pClicked.X < 89)
                    pClicked.X = 89;
                pClicked.Y = p2y;
                pictureBox2.Location = pClicked;

                decimal ss = (pClicked.X - 89) * 100 / (212 - 89);

                label2.Text = pClicked.X.ToString() + ““ + p2y.ToString() + “  “ + ss.ToString

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-09-08 09:05  SetVolControl\
     文件         920  2020-08-30 21:21  SetVolControl\SetVolControl.sln
     文件       16896  2020-09-08 09:05  SetVolControl\SetVolControl.suo
     目录           0  2020-09-08 09:06  SetVolControl\VolControl\
     文件        6185  2020-09-08 09:04  SetVolControl\VolControl\Form1.Designer.cs
     文件        3244  2020-09-08 09:04  SetVolControl\VolControl\Form1.cs
     文件       25630  2020-09-08 09:04  SetVolControl\VolControl\Form1.resx
     文件         491  2011-11-12 00:26  SetVolControl\VolControl\Program.cs
     目录           0  2020-08-30 21:20  SetVolControl\VolControl\Properties\
     文件        1376  2011-11-12 00:26  SetVolControl\VolControl\Properties\AssemblyInfo.cs
     文件        2860  2020-08-30 21:21  SetVolControl\VolControl\Properties\Resources.Designer.cs
     文件        5612  2011-11-12 00:26  SetVolControl\VolControl\Properties\Resources.resx
     文件        1110  2020-08-30 21:21  SetVolControl\VolControl\Properties\Settings.Designer.cs
     文件         249  2011-11-12 00:26  SetVolControl\VolControl\Properties\Settings.settings
     文件        5429  2020-08-30 23:05  SetVolControl\VolControl\VolControl.csproj
     文件         452  2020-08-30 22:42  SetVolControl\VolControl\VolControl.csproj.user
     目录           0  2020-08-30 21:21  SetVolControl\VolControl\bin\
     目录           0  2020-09-08 09:05  SetVolControl\VolControl\bin\Debug\
     文件       25088  2020-09-08 09:05  SetVolControl\VolControl\bin\Debug\VolControl.exe
     文件       24064  2020-09-08 09:05  SetVolControl\VolControl\bin\Debug\VolControl.pdb
     文件       11608  2020-09-08 09:05  SetVolControl\VolControl\bin\Debug\VolControl.vshost.exe
     文件         490  2010-03-17 22:39  SetVolControl\VolControl\bin\Debug\VolControl.vshost.exe.manifest
     目录           0  2020-09-08 09:07  SetVolControl\VolControl\bin\Release\

评论

共有 条评论

相关资源