将最大最大值添加到自定义控制范围栏[关闭](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; } } } }
原文:
最满意答案
正如你在这一点上意识到的那样,这是糟糕的设计,但你可以使用辅助函数:
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.
相关问答
更多-
MS-ACCESS 3表连接(MS-ACCESS 3 table join)[2022-10-15]
MS Access具有非常特定的连接语法,包括特定关键字和括号。 试试这个: SELECT Appeals.*, Users.Firstname, Users.LastName FROM (Users INNER JOIN Appeals ON Appeals.SubmittedByUserID = Users.UserID ) INNER JOIN AppealsCategories ON Appeals.CategoryID = AppealsCat ... -
如何设置不与列内容混淆的分隔符?(How can I put delimiter character which is not confuse with column's content?)[2022-03-19]
我总是使用烟斗| 作为分隔符,因此在大多数情况下不会与内容冲突。 I always use pipe |as delimiter, so in most cases there is not conflict with content. -
使用拆分作为分隔符(Use split in as delimiter)[2022-08-07]
更改 $items = $_.split("|") 至: $items = ([string]$_).split("|") 匹配的内容作为数组返回,并且没有split方法。 将它转换为字符串将为您提供split方法。 更新:要打印文件名,您必须稍微更改脚本,因为Select-String的当前输入是一个数组,因此您将丢失文件名: Select-String -Pattern "3-nines" -Path "*.txt" | foreach { $items = ([string]$_).spl ... -
因此,您的第一个问题是将一个变量分配给一个列,就像在表中一样,只会从表中的该列中拉出一行。 如果你想像你当前那样循环遍历列中的每一行,你需要使用CURSOR或类似的变量来遍历每一行。 您遇到的第二个问题是您的while语句不正确。 您丢失了它的最后一个值,因为当数据字符串中没有逗号时停止。 最后一个值没有逗号,因此它会跳过最后一个值。 使用当前的方法可以解决这个问题,但我建议使用另一种方法来拆分字符串。 DECLARE @myTable TABLE (datastring VARCHAR(4000)); I ...
-
MS-Access:表条目可以根据其类型具有不同的属性(MS-Access: Table entry can have different properties based on it's type)[2023-02-23]
以下表结构怎么样? Assets -------- AssetID (PK) EquipmentTypeID (other fields common to all assets Workstation ----------- AssetID (PK, one-to-one join to Assets.AssetID) (workstation-specific fields) 并重复Hardware和Software表。 我认为这对于大多数情况来说已经足够了,因为您不能在单个表中的两个记录上使用相同 ... -
SQL拆分列基于1个或多个可能的分隔符并插入到新表中(SQL Split column based on 1 or more possible delimiter and insert in new table)[2022-08-31]
要分割并获取特定的值,我更愿意使用用户定义的函数。 Public Function SplitString(str As String, delimiter As String, count As Integer) As String Dim strArr() As String strArr = Split(str, delimiter, count + 1) count = count - 1 'zero-based If UBound(strArr) >= count ... -
下面的查询是从两个带有SQL剪切的MS Access查询创建的,并粘贴到派生表中。 这两个查询选择具有当前培训的员工(#1)和具有所需培训的员工(#2)。 它不可更新,但易于创建。 您可以通过在末尾添加一行来仅显示缺少的培训: WHERE et.TrainingName Is Null 要选择单个员工,您可以添加一行: WHERE rt.EMPID=1 AND et.TrainingName Is Null 但是,您提到了一个子表单,因此我希望您希望使用链接子字段和主字段来限制员工。 SQL SELEC ...
-
分割字符串时,避免极端情况的最简单方法是将分隔符附加到字符串,当您知道字符串不能以分隔符结束时: str = "a,b,c,d,e,f,g" str = str .. ',' for w in str:gmatch("(.-),") do print(w) end 或者,您可以使用带有可选分隔符的模式: str = "a,b,c,d,e,f,g" for w in str:gmatch("([^,]+),?") do print(w) end 实际上,我们不需要可选的分隔符,因为我们正在捕获非分隔符: ...
-
你可以使用re.split和前瞻: import re re.split('\s(?=\d\s)',content) 导致: ['This', '1 string is very big', '2 i need to split it', '3 into paragraph wise.', '4 But this string', '5 not a formated string.'] 这会分隔空格 - 但只有那些紧跟一个数字然后是另一个空格的空格。 You could use re.split wit ...
-
MS-Access:在分隔符上拆分内容并与其他表连接(MS-Access: Split content on delimiter and join with other table)[2023-07-13]
正如你在这一点上意识到的那样,这是糟糕的设计,但你可以使用辅助函数: 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(MasterValu ...