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(); }