首页 \ 问答 \ 将最大最大值添加到自定义控制范围栏[关闭](Adding min max to custom contol range bar [closed])

将最大最大值添加到自定义控制范围栏[关闭](Adding min max to custom contol range bar [closed])

我在c#中编写了一个自定义范围滑块。 到目前为止,我有3个属性'Min,Max和Value'。 根据建议,我需要执行以下操作:1。调整Value属性以检查它是否保持在Min和Max之间。 2.更改百分比变量的名称,因为它不再存储百分比。 3.使用任何浮点数或整数值作为值,不要混合它们因为你可能会失去精度。 4.创建一个方法来通过鼠标更新值并从事件处理程序中调用它。

我不确定实施这些更改的最佳方法。 我希望得到一些帮助。

namespace jmRangeSlider
{
    public partial class rangeSlider : UserControl
    {
        public rangeSlider()
        {
            InitializeComponent();
            label1.ForeColor = Color.Black;
            this.ForeColor = SystemColors.Highlight; // set the default color the RangeSlider
        }

        protected float percent = 0.0f; // Protected because we don't want this to be accessed from the outside

        // Create a Value property for the RangeSlider
        public float Value
        {
            get
            {
                return percent;
            }
            set
            {
                // Maintain the value between 0 and 100
                if (value < 0) value = 0;
                else if (value > 100) value = 100;
                percent = value;
                label1.Text = value.ToString();
                //redraw the RangeSlider every time the value changes
                this.Invalidate();
            }
        }

        int minValue = 0;
        public int MinValue
        {
            get
            {
                return this.minValue;
            }

            set
            {
                this.minValue = value;
            }
        }

        int maxValue = 100;
        public int MaxValue
        {
            get
            {
                return this.maxValue;
            }

            set
            {
                this.maxValue = value;
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Brush b = new SolidBrush(this.ForeColor); //create brush that will draw the background of the range bar
            // create a linear gradient that will be drawn over the background. FromArgb means you can use the Alpha value which is the transparency
            LinearGradientBrush lb = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.FromArgb(50, Color.White), Color.FromArgb(0, Color.White), LinearGradientMode.Vertical);

            // calculate how much has the RangeSlider to be filled for 'x' %
            int width = (int)((percent / 100) * this.Width);
            e.Graphics.FillRectangle(b, 0, 0, width, this.Height);
            e.Graphics.FillRectangle(lb, 0, 0, width, this.Height);
            b.Dispose(); lb.Dispose();
        }

        private void rangeSlider_SizeChanged(object sender, EventArgs e)
        {
            // maintain the label in the center of the RangeSlider
            label1.Location = new Point(this.Width / 2 - 21 / 2 - 4, this.Height / 2 - 15 / 2);
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;

            int val = (x * 100) / this.Width; //when click get value within progress bar
            int screenX = Cursor.Position.X;

            label1.Text = screenX.ToString();
            this.Value = val;
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //this.Value += 1;
                int x = e.X;
                int val = (x * 100) / this.Width; //when click get value within progress bar
                label1.Text = val.ToString();
                this.Value = val;
            }
        }

    }
}

I've written a custom range slider in c#. So far I have 3 properties 'Min, Max, and Value'. As suggested I need to do the following: 1. Adjust the Value property to check it stays between Min and Max. 2.Change the name of the percent variable since it no longer stores the percentage. 3.Use either floats or ints everywhere for the value, don't mix them because you could lose precision. 4.Create a method to update the value by mouse and call that from the event handlers.

I am not sure the best way to implement these changes. I was hoping for some help.

namespace jmRangeSlider
{
    public partial class rangeSlider : UserControl
    {
        public rangeSlider()
        {
            InitializeComponent();
            label1.ForeColor = Color.Black;
            this.ForeColor = SystemColors.Highlight; // set the default color the RangeSlider
        }

        protected float percent = 0.0f; // Protected because we don't want this to be accessed from the outside

        // Create a Value property for the RangeSlider
        public float Value
        {
            get
            {
                return percent;
            }
            set
            {
                // Maintain the value between 0 and 100
                if (value < 0) value = 0;
                else if (value > 100) value = 100;
                percent = value;
                label1.Text = value.ToString();
                //redraw the RangeSlider every time the value changes
                this.Invalidate();
            }
        }

        int minValue = 0;
        public int MinValue
        {
            get
            {
                return this.minValue;
            }

            set
            {
                this.minValue = value;
            }
        }

        int maxValue = 100;
        public int MaxValue
        {
            get
            {
                return this.maxValue;
            }

            set
            {
                this.maxValue = value;
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Brush b = new SolidBrush(this.ForeColor); //create brush that will draw the background of the range bar
            // create a linear gradient that will be drawn over the background. FromArgb means you can use the Alpha value which is the transparency
            LinearGradientBrush lb = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.FromArgb(50, Color.White), Color.FromArgb(0, Color.White), LinearGradientMode.Vertical);

            // calculate how much has the RangeSlider to be filled for 'x' %
            int width = (int)((percent / 100) * this.Width);
            e.Graphics.FillRectangle(b, 0, 0, width, this.Height);
            e.Graphics.FillRectangle(lb, 0, 0, width, this.Height);
            b.Dispose(); lb.Dispose();
        }

        private void rangeSlider_SizeChanged(object sender, EventArgs e)
        {
            // maintain the label in the center of the RangeSlider
            label1.Location = new Point(this.Width / 2 - 21 / 2 - 4, this.Height / 2 - 15 / 2);
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;

            int val = (x * 100) / this.Width; //when click get value within progress bar
            int screenX = Cursor.Position.X;

            label1.Text = screenX.ToString();
            this.Value = val;
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //this.Value += 1;
                int x = e.X;
                int val = (x * 100) / this.Width; //when click get value within progress bar
                label1.Text = val.ToString();
                this.Value = val;
            }
        }

    }
}

原文:
更新时间:2021-12-09 15:12

最满意答案

正如你在这一点上意识到的那样,这是糟糕的设计,但你可以使用辅助函数:

Public Function GetNs(ByVal MasterIds As String) As Variant

    Dim MasterValues As Variant
    Dim Item As Integer

    MasterValues = Split(MasterIds, ",")
    ' Lookup Name one by one.
    For Item = LBound(MasterValues) To UBound(MasterValues)
        MasterValues(Item) = DLookup("[Name]", "[Table 1]", "ID = " & MasterValues(Item) & "")
    Next

    GetNs = Join(MasterValues, ",")

End Function

当然,对于大型表1,您可以将其作为记录集打开并查找值。


As you realize at this point, it is bad design, but you can use a helper function:

Public Function GetNs(ByVal MasterIds As String) As Variant

    Dim MasterValues As Variant
    Dim Item As Integer

    MasterValues = Split(MasterIds, ",")
    ' Lookup Name one by one.
    For Item = LBound(MasterValues) To UBound(MasterValues)
        MasterValues(Item) = DLookup("[Name]", "[Table 1]", "ID = " & MasterValues(Item) & "")
    Next

    GetNs = Join(MasterValues, ",")

End Function

Of course, for a large Table 1, you would open it as a recordset and find the values.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。