• 大小: 297KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: C#
  • 标签: C#  

资源简介

C#中TrackBar默认只有一个滑块,目前这个可以有2个滑块,能够实现取2个值的TrackBar.可以运用图像二值化阀值的设置。

资源截图

代码片段和文件信息

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

namespace UI
{

    public partial class Track2Bar : UserControl
    {
        public delegate void ChageValue(object sender EventArgs e);
        public event ChageValue OnChageValue;
        bool startMove = false;
        int clickX = 0;  //记录上次点击的鼠标位置
        int clickY = 0;


        double setp;
        private int minvalue = 0;
        private int maxvalue = 255;
        public int MinValue
        {
            get
            {
                if (minvalue >= 255)
                {

                    return 255;
                }
                else if (minvalue <= 0)
                {

                    return 0;
                }

                else
                {

                    return minvalue;
                }
            }
            set
            {
               
                value = minvalue;
            }

        }
        public int MaxValue
        {
            get
            {
                if (maxvalue >= 255)
                {
                    textBox2.Text = “255“;
                    return 255;
                }
                else if (maxvalue <= 0)
                {
                    textBox2.Text = “0“;
                    return 0;
                }

                else
                {
                    textBox2.Text = maxvalue.ToString();
                    return maxvalue;
                }


            }

            set
            {
               
                
                value = maxvalue;
            }


        }
        public Track2Bar()
        {
            InitializeComponent();
            setp = 255 / progressBar1.Width+0.00001;
        }

        private void button1_MouseDown(object sender MouseEventArgs e)
        {
            //鼠标按下事件
            clickX = e.X;
            clickY = e.Y;
            startMove = true;
        }

        private void button1_MouseMove(object sender MouseEventArgs e)
        {
       
            if (startMove)
            {
                // e.X 是正负数表示移动的方向
                int x = button1.Location.X + e.X - clickX;   //还要减去上次鼠标点击的位置
                int y = button1.Location.Y;
                button1.Location = new Point(x y);
                minvalue = Convert.ToInt32((button1.Left - progressBar1.Left) * setp);
                progressBar1.Step = 1;

                if (button1.Left < progressBar1.Left)
                {
                    button1.Left = progressBar1.Left;
                    // textBox1.Text = “0“;
                    minvalue = 0;
                }
                if (button1.Right > progressBar1.Right)
                {

                    button1.Left = progress

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        196  2019-07-28 13:51  双滑块控件\UI\.vs\UI\DesignTimeBuild\.dtbcache

    ..A..H.     63488  2019-07-28 13:51  双滑块控件\UI\.vs\UI\v15\.suo

     文件          0  2019-07-28 13:45  双滑块控件\UI\.vs\UI\v15\Server\sqlite3\db.lock

     文件     671744  2019-07-28 13:23  双滑块控件\UI\.vs\UI\v15\Server\sqlite3\storage.ide

     文件      32768  2019-07-28 13:45  双滑块控件\UI\.vs\UI\v15\Server\sqlite3\storage.ide-shm

     文件    4136512  2019-07-28 13:51  双滑块控件\UI\.vs\UI\v15\Server\sqlite3\storage.ide-wal

     文件      10752  2019-07-28 13:49  双滑块控件\UI\UI\bin\Debug\UI.dll

     文件      17920  2019-07-28 13:49  双滑块控件\UI\UI\bin\Debug\UI.pdb

     文件        677  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6992  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件         42  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\UI.csproj.CoreCompileInputs.cache

     文件        370  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\UI.csproj.FileListAbsolute.txt

     文件        943  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\UI.csproj.GenerateResource.cache

     文件      10752  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\UI.dll

     文件      17920  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\UI.pdb

     文件        180  2019-07-28 13:49  双滑块控件\UI\UI\obj\Debug\UI.Track2Bar.resources

     文件       1311  2019-07-28 05:57  双滑块控件\UI\UI\Properties\AssemblyInfo.cs

     文件       7931  2019-07-28 13:49  双滑块控件\UI\UI\Track2Bar.cs

     文件       5565  2019-07-28 13:18  双滑块控件\UI\UI\Track2Bar.Designer.cs

     文件       5817  2019-07-28 13:49  双滑块控件\UI\UI\Track2Bar.resx

     文件       2606  2019-07-28 13:49  双滑块控件\UI\UI\UI.csproj

     文件       1607  2019-07-28 06:34  双滑块控件\UI\UI.sln

     文件        189  2019-07-28 06:33  双滑块控件\UI\WindowsFormsApp1\App.config

     文件      10752  2019-07-28 13:49  双滑块控件\UI\WindowsFormsApp1\bin\Debug\UI.dll

     文件      17920  2019-07-28 13:49  双滑块控件\UI\WindowsFormsApp1\bin\Debug\UI.pdb

     文件       9728  2019-07-28 13:49  双滑块控件\UI\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe

     文件        189  2019-07-28 06:33  双滑块控件\UI\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe.config

............此处省略49个文件信息

评论

共有 条评论