From 3735a56334c6938d2d44a0f7b422485fffe8cb5a Mon Sep 17 00:00:00 2001 From: H Date: Sun, 16 Aug 2020 21:06:22 +0800 Subject: [PATCH] =?UTF-8?q?listbox=E6=BB=9A=E5=8A=A8=E6=9D=A1=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D1=E3=80=81=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=88=87=E6=8D=A2=EF=BC=8C=E6=BB=9A=E5=8A=A8=E6=9D=A1max?= =?UTF-8?q?=E5=80=BC=E9=94=99=E8=AF=AF=EF=BC=9B2=E3=80=81=E6=BB=9A?= =?UTF-8?q?=E8=BD=AE=E6=BB=9A=E5=8A=A8=EF=BC=8C=E6=BB=9A=E5=8A=A8=E6=9D=A1?= =?UTF-8?q?value=E8=B7=B3=E5=8A=A8=EF=BC=9B3=E3=80=81=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E6=85=A2=E9=80=9F=E6=8B=96=E5=8A=A8=E6=BB=9A=E5=8A=A8=E6=9D=A1?= =?UTF-8?q?=EF=BC=8Citemselect=E9=A1=B9=E7=9B=AE=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E9=97=AA=E7=83=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI.Demo/Controls/FListBox.Designer.cs | 34 ++++++--------- SunnyUI.Demo/Controls/FListBox.cs | 10 ++++- SunnyUI/Controls/UIListBox.cs | 50 +++++++++++++--------- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/SunnyUI.Demo/Controls/FListBox.Designer.cs b/SunnyUI.Demo/Controls/FListBox.Designer.cs index 26306f86..ee41e37e 100644 --- a/SunnyUI.Demo/Controls/FListBox.Designer.cs +++ b/SunnyUI.Demo/Controls/FListBox.Designer.cs @@ -33,11 +33,13 @@ this.uiLine2 = new Sunny.UI.UILine(); this.uiListBox1 = new Sunny.UI.UIListBox(); this.uiCheckBox1 = new Sunny.UI.UICheckBox(); + this.uiButton1 = new Sunny.UI.UIButton(); this.PagePanel.SuspendLayout(); this.SuspendLayout(); // // PagePanel // + this.PagePanel.Controls.Add(this.uiButton1); this.PagePanel.Controls.Add(this.uiCheckBox1); this.PagePanel.Controls.Add(this.uiListBox1); this.PagePanel.Controls.Add(this.uiLine2); @@ -84,26 +86,6 @@ // uiListBox1 // this.uiListBox1.Font = new System.Drawing.Font("微软雅黑", 12F); - this.uiListBox1.Items.AddRange(new object[] { - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", - "11", - "12", - "13", - "14", - "15", - "16", - "17", - "18"}); this.uiListBox1.ItemSelectForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255))))); this.uiListBox1.Location = new System.Drawing.Point(33, 48); this.uiListBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); @@ -127,6 +109,17 @@ this.uiCheckBox1.Text = "ShowDescription"; this.uiCheckBox1.ValueChanged += new Sunny.UI.UICheckBox.OnValueChanged(this.uiCheckBox1_ValueChanged); // + // uiButton1 + // + this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand; + this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F); + this.uiButton1.Location = new System.Drawing.Point(33, 400); + this.uiButton1.Name = "uiButton1"; + this.uiButton1.Size = new System.Drawing.Size(100, 35); + this.uiButton1.TabIndex = 23; + this.uiButton1.Text = "Add Item"; + this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click); + // // FListBox // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F); @@ -146,5 +139,6 @@ private UILine uiLine1; private UIListBox uiListBox1; private UICheckBox uiCheckBox1; + private UIButton uiButton1; } } \ No newline at end of file diff --git a/SunnyUI.Demo/Controls/FListBox.cs b/SunnyUI.Demo/Controls/FListBox.cs index 13d30f2c..b84ea93b 100644 --- a/SunnyUI.Demo/Controls/FListBox.cs +++ b/SunnyUI.Demo/Controls/FListBox.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; namespace Sunny.UI.Demo { @@ -41,5 +42,12 @@ namespace Sunny.UI.Demo { this.ShowInfoDialog(uiListBox1.SelectedItem.ToString()); } + + private int num = 0; + private void uiButton1_Click(object sender, System.EventArgs e) + { + uiListBox1.Items.Add(DateTime.Now.ToString("yyyyMMdd") + "_" + num); + num++; + } } } \ No newline at end of file diff --git a/SunnyUI/Controls/UIListBox.cs b/SunnyUI/Controls/UIListBox.cs index 49fd3203..63b57ced 100644 --- a/SunnyUI/Controls/UIListBox.cs +++ b/SunnyUI/Controls/UIListBox.cs @@ -171,11 +171,17 @@ namespace Sunny.UI private int LastCount; + private int lastBarValue = -1; + private void Bar_ValueChanged(object sender, EventArgs e) { if (listbox != null) { - ScrollBarInfo.SetScrollValue(listbox.Handle, bar.Value); + if (bar.Value != lastBarValue) + { + ScrollBarInfo.SetScrollValue(listbox.Handle, bar.Value); + lastBarValue = bar.Value; + } } } @@ -306,7 +312,14 @@ namespace Sunny.UI protected override void OnSizeChanged(EventArgs e) { - SetScrollInfo(); + if (Bar != null && Bar.Visible) + { + if (Bar.Value != 0) + { + ScrollBarInfo.SetScrollValue(Handle, Bar.Value); + } + } + //SetScrollInfo(); } public void SetScrollInfo() @@ -377,25 +390,20 @@ namespace Sunny.UI protected override void OnMouseWheel(MouseEventArgs e) { - /* base.OnMouseWheel(e); - if (Bar.Visible) - { - var si = ScrollBarInfo.GetInfo(Handle); - if (e.Delta > 10) - { - if (si.nPos > 0) - { - ScrollBarInfo.ScrollUp(Handle); - } - } - else if (e.Delta < -10) - { - if (si.nPos < si.ScrollMax) - { - ScrollBarInfo.ScrollDown(Handle); - } - } - }*/ + base.OnMouseWheel(e); + + if (Bar != null && Bar.Visible) + { + var si = ScrollBarInfo.GetInfo(Handle); + if (e.Delta > 10) + { + ScrollBarInfo.SetScrollValue(Handle, (si.nPos - SystemInformation.MouseWheelScrollLines) >= si.nMin ? si.nPos - SystemInformation.MouseWheelScrollLines : 0); + } + else if (e.Delta < -10) + { + ScrollBarInfo.SetScrollValue(Handle, (si.nPos + SystemInformation.MouseWheelScrollLines) <= si.nMax ? (si.nPos + SystemInformation.MouseWheelScrollLines) : si.nMax); + } + } SetScrollInfo(); }