Commit 098cffbf kwwwvagaa

优化滚动条,支持Panel、treeview、textbox

1 个父辈 859c6bcd
...@@ -48,6 +48,13 @@ namespace HZH_Controls.Controls ...@@ -48,6 +48,13 @@ namespace HZH_Controls.Controls
return true; return true;
} }
} }
else if (extendee is RichTextBox)
{
// RichTextBox control = (RichTextBox)extendee;
return true;
}
return false; return false;
} }
...@@ -64,29 +71,63 @@ namespace HZH_Controls.Controls ...@@ -64,29 +71,63 @@ namespace HZH_Controls.Controls
m_controlCache[control] = blnUserCustomScrollbar; m_controlCache[control] = blnUserCustomScrollbar;
if (!blnUserCustomScrollbar) if (!blnUserCustomScrollbar)
return; return;
control_SizeChanged(control, null);
control.VisibleChanged += control_VisibleChanged; control.VisibleChanged += control_VisibleChanged;
control.SizeChanged += control_SizeChanged; control.SizeChanged += control_SizeChanged;
control.LocationChanged += control_LocationChanged; control.LocationChanged += control_LocationChanged;
control.Disposed += control_Disposed; control.Disposed += control_Disposed;
control.MouseWheel += Control_MouseWheel;
if (control is TreeView) if (control is TreeView)
{ {
TreeView tv = (TreeView)control; TreeView tv = (TreeView)control;
tv.MouseWheel += tv_MouseWheel; //tv.MouseWheel += tv_MouseWheel;
tv.AfterSelect += tv_AfterSelect; //tv.AfterSelect += tv_AfterSelect;
tv.AfterExpand += tv_AfterExpand; tv.AfterExpand += tv_AfterExpand;
tv.AfterCollapse += tv_AfterCollapse; tv.AfterCollapse += tv_AfterCollapse;
} }
else if (control is TextBox) else if (control is TextBox)
{ {
TextBox txt = (TextBox)control; TextBox txt = (TextBox)control;
txt.MouseWheel += txt_MouseWheel; //txt.MouseWheel += txt_MouseWheel;
txt.TextChanged += txt_TextChanged; txt.TextChanged += txt_TextChanged;
txt.KeyDown += txt_KeyDown; txt.KeyDown += txt_KeyDown;
} }
control_SizeChanged(control, null);
}
private void Control_MouseWheel(object sender, MouseEventArgs e)
{
Control c = (Control)sender;
if (m_lstVCache.ContainsKey(c))
{
if (e.Delta > 5)
{
ControlHelper.ScrollUp(c.Handle);
}
else if (e.Delta < -5)
{
ControlHelper.ScrollDown(c.Handle);
}
SetVMaxNum(c);
}
else if (m_lstHCache.ContainsKey(c))
{
if (e.Delta > 5)
{
ControlHelper.ScrollLeft(c.Handle);
}
else if (e.Delta < -5)
{
ControlHelper.ScrollRight(c.Handle);
} }
SetHMaxNum(c);
}
}
void control_Disposed(object sender, EventArgs e) void control_Disposed(object sender, EventArgs e)
{ {
...@@ -115,6 +156,30 @@ namespace HZH_Controls.Controls ...@@ -115,6 +156,30 @@ namespace HZH_Controls.Controls
bool blnHasVScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & VSCROLL) != 0; bool blnHasVScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & VSCROLL) != 0;
bool blnHasHScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & HSCROLL) != 0; bool blnHasHScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & HSCROLL) != 0;
if (control is TextBox)
{
var txt = (TextBox)control;
if (txt.ScrollBars == ScrollBars.Both)
{
blnHasVScrollbar = true;
blnHasHScrollbar = true;
}
else if (txt.ScrollBars == ScrollBars.Vertical)
{
blnHasVScrollbar = true;
blnHasHScrollbar = false;
}
else if (txt.ScrollBars == ScrollBars.Horizontal)
{
blnHasVScrollbar = false;
blnHasHScrollbar = true;
}
else
{
blnHasVScrollbar = false;
blnHasHScrollbar = false;
}
}
if (blnHasVScrollbar) if (blnHasVScrollbar)
{ {
if (!m_lstVCache.ContainsKey(control)) if (!m_lstVCache.ContainsKey(control))
...@@ -122,20 +187,20 @@ namespace HZH_Controls.Controls ...@@ -122,20 +187,20 @@ namespace HZH_Controls.Controls
if (control.Parent != null) if (control.Parent != null)
{ {
UCVScrollbar barV = new UCVScrollbar(); UCVScrollbar barV = new UCVScrollbar();
barV.Width = SystemInformation.VerticalScrollBarWidth; barV.SmallChange = 5;
barV.Width = SystemInformation.VerticalScrollBarWidth + 1;
barV.Scroll += barV_Scroll; barV.Scroll += barV_Scroll;
m_lstVCache[control] = barV; m_lstVCache[control] = barV;
if (blnHasHScrollbar) if (blnHasHScrollbar)
{ {
barV.Height = control.Height - barV.Width - 2; barV.Height = control.Height - barV.Width;
} }
else else
{ {
barV.Height = control.Height - 2; barV.Height = control.Height;
} }
SetVMaxNum(control); SetVMaxNum(control);
barV.Location = new System.Drawing.Point(control.Right - barV.Width - 1, control.Top + 1); barV.Location = new System.Drawing.Point(control.Right - barV.Width, control.Top);
control.Parent.Controls.Add(barV); control.Parent.Controls.Add(barV);
int intControlIndex = control.Parent.Controls.GetChildIndex(control); int intControlIndex = control.Parent.Controls.GetChildIndex(control);
control.Parent.Controls.SetChildIndex(barV, intControlIndex); control.Parent.Controls.SetChildIndex(barV, intControlIndex);
...@@ -150,8 +215,7 @@ namespace HZH_Controls.Controls ...@@ -150,8 +215,7 @@ namespace HZH_Controls.Controls
{ {
if (m_lstVCache.ContainsKey(control) && m_lstVCache[control].Parent != null) if (m_lstVCache.ContainsKey(control) && m_lstVCache[control].Parent != null)
{ {
m_lstVCache[control].Parent.Controls.Remove(m_lstVCache[control]); m_lstVCache[control].Visible = false;
m_lstVCache.Remove(control);
} }
} }
...@@ -162,20 +226,21 @@ namespace HZH_Controls.Controls ...@@ -162,20 +226,21 @@ namespace HZH_Controls.Controls
if (control.Parent != null) if (control.Parent != null)
{ {
UCHScrollbar barH = new UCHScrollbar(); UCHScrollbar barH = new UCHScrollbar();
barH.Height = SystemInformation.HorizontalScrollBarHeight; barH.Height = SystemInformation.HorizontalScrollBarHeight + 1;
barH.SmallChange = 5;
barH.Scroll += barH_Scroll; barH.Scroll += barH_Scroll;
m_lstHCache[control] = barH; m_lstHCache[control] = barH;
if (blnHasHScrollbar) if (blnHasHScrollbar)
{ {
barH.Width = control.Width - barH.Height - 2; barH.Width = control.Width - barH.Height;
} }
else else
{ {
barH.Width = control.Width - 2; barH.Width = control.Width;
} }
SetHMaxNum(control); SetHMaxNum(control);
barH.Location = new System.Drawing.Point(control.Left + 1, control.Bottom - barH.Height - 1); barH.Location = new System.Drawing.Point(control.Left, control.Bottom - barH.Height);
control.Parent.Controls.Add(barH); control.Parent.Controls.Add(barH);
int intControlIndex = control.Parent.Controls.GetChildIndex(control); int intControlIndex = control.Parent.Controls.GetChildIndex(control);
control.Parent.Controls.SetChildIndex(barH, intControlIndex); control.Parent.Controls.SetChildIndex(barH, intControlIndex);
...@@ -192,7 +257,7 @@ namespace HZH_Controls.Controls ...@@ -192,7 +257,7 @@ namespace HZH_Controls.Controls
{ {
if (m_lstHCache[control].Visible && m_lstHCache[control].Parent != null) if (m_lstHCache[control].Visible && m_lstHCache[control].Parent != null)
{ {
m_lstHCache[control].Parent.Controls.Remove(m_lstHCache[control]); m_lstHCache[control].Visible = false;
} }
} }
} }
...@@ -200,64 +265,108 @@ namespace HZH_Controls.Controls ...@@ -200,64 +265,108 @@ namespace HZH_Controls.Controls
ResetScrollLocation(sender); ResetScrollLocation(sender);
} }
private void SetVMaxNum(Control control) private void SetVMaxNum(Control control)
{ {
if (!m_lstVCache.ContainsKey(control)) if (!m_lstVCache.ContainsKey(control))
return; return;
var into = ControlHelper.GetVScrollBarInfo(control.Handle); var intoV = ControlHelper.GetVScrollBarInfo(control.Handle);
var intoH = ControlHelper.GetHScrollBarInfo(control.Handle);
UCVScrollbar barV = m_lstVCache[control]; UCVScrollbar barV = m_lstVCache[control];
if (control is ScrollableControl) if (control is ScrollableControl )
{ {
barV.Maximum = (control as ScrollableControl).VerticalScroll.Maximum; barV.Maximum = intoV.ScrollMax;
barV.Value = (control as ScrollableControl).VerticalScroll.Value; barV.Visible = intoV.ScrollMax > 0 && intoV.nMax > 0 && intoV.nPage > 0;
barV.Value = intoV.nPos;
barV.BringToFront();
// barV.Maximum = (control as ScrollableControl).VerticalScroll.Maximum;
// barV.Value = (control as ScrollableControl).VerticalScroll.Value;
} }
else if (control is TreeView) else if (control is TreeView)
{ {
barV.Maximum = GetTreeNodeMaxY(control as TreeView); var tv = control as TreeView;
barV.Value = (control as TreeView).AutoScrollOffset.Y; barV.Maximum = intoV.ScrollMax * tv.ItemHeight;
barV.Visible = intoV.ScrollMax > 0 && intoV.nMax > 0 && intoV.nPage > 0;
barV.Value = intoV.nPos * tv.ItemHeight;
barV.BringToFront();
//barV.Maximum = GetTreeNodeMaxY(control as TreeView) - control.Height;
//barV.Value = (control as TreeView).AutoScrollOffset.Y;
} }
else if (control is TextBox) else if (control is TextBox)
{ {
TextBox txt = (TextBox)control; TextBox txt = (TextBox)control;
int intTxtMaxHeight = 0; barV.Maximum = intoV.ScrollMax * txt.PreferredHeight;
int intTextHeight = 0; if (txt.ScrollBars == ScrollBars.Both || txt.ScrollBars == ScrollBars.Vertical)
using (var g = txt.CreateGraphics()) {
barV.Visible = true;
}
else
{ {
intTxtMaxHeight = (int)g.MeasureString(txt.Text, txt.Font).Height; barV.Visible = false;
intTextHeight = (int)g.MeasureString(txt.Text.Substring(0, txt.SelectionStart), txt.Font).Height; }
barV.Value = intoV.nPos * txt.PreferredHeight;
barV.BringToFront();
} }
barV.Maximum = intTxtMaxHeight; else if (control is RichTextBox)
barV.Value = (control as TextBox).AutoScrollOffset.Y; {
bool blnHasVScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & VSCROLL) != 0;
barV.Maximum = intoV.ScrollMax;
barV.Visible = blnHasVScrollbar;
barV.Value = intoV.nPos;
barV.BringToFront();
} }
} }
private void SetHMaxNum(Control control) private void SetHMaxNum(Control control)
{ {
if (!m_lstHCache.ContainsKey(control)) if (!m_lstHCache.ContainsKey(control))
return; return;
var intoH = ControlHelper.GetHScrollBarInfo(control.Handle);
UCHScrollbar barH = m_lstHCache[control]; UCHScrollbar barH = m_lstHCache[control];
if (control is ScrollableControl) if (control is ScrollableControl)
{ {
barH.Maximum = (control as ScrollableControl).HorizontalScroll.Maximum; barH.Maximum = intoH.ScrollMax;
barH.Value = (control as ScrollableControl).HorizontalScroll.Value; barH.Visible = intoH.ScrollMax > 0 && intoH.nMax > 0 && intoH.nPage > 0;
barH.Value = intoH.nPos;
barH.BringToFront();
//barH.Maximum = (control as ScrollableControl).HorizontalScroll.Maximum;
//barH.Value = (control as ScrollableControl).HorizontalScroll.Value;
} }
else if (control is TreeView) else if (control is TreeView)
{ {
barH.Maximum = GetTreeNodeMaxX(control as TreeView); var tv = control as TreeView;
barH.Value = (control as TreeView).AutoScrollOffset.X; barH.Maximum = intoH.ScrollMax;
barH.Visible = intoH.ScrollMax > 0 && intoH.nMax > 0 && intoH.nPage > 0;
barH.Value = intoH.nPos;
barH.BringToFront();
//barH.Maximum = GetTreeNodeMaxX(control as TreeView);
//barH.Value = (control as TreeView).AutoScrollOffset.X;
} }
else if (control is TextBox) else if (control is TextBoxBase)
{ {
TextBox txt = (TextBox)control; TextBox txt = (TextBox)control;
int intTxtMaxWidth = 0; barH.Maximum = intoH.ScrollMax;
int intTextWidth = 0;
using (var g = txt.CreateGraphics()) if (txt.ScrollBars == ScrollBars.Both || txt.ScrollBars == ScrollBars.Horizontal)
{
barH.Visible = true;
}
else
{ {
intTxtMaxWidth = (int)g.MeasureString(txt.Text, txt.Font).Width; barH.Visible = false;
intTextWidth = (int)g.MeasureString(txt.Text.Substring(0, txt.SelectionStart), txt.Font).Width;
} }
barH.Maximum = intTxtMaxWidth;
barH.Value = (control as TextBox).AutoScrollOffset.Y; barH.Value = intoH.nPos;
barH.BringToFront();
}
else if (control is RichTextBox)
{
bool blnHasHScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & HSCROLL) != 0;
barH.Maximum = intoH.ScrollMax;
barH.Visible = blnHasHScrollbar;
barH.Value = intoH.nPos;
barH.BringToFront();
} }
} }
/// <summary> /// <summary>
...@@ -269,33 +378,57 @@ namespace HZH_Controls.Controls ...@@ -269,33 +378,57 @@ namespace HZH_Controls.Controls
Control control = (Control)sender; Control control = (Control)sender;
bool blnHasVScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & VSCROLL) != 0; bool blnHasVScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & VSCROLL) != 0;
bool blnHasHScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & HSCROLL) != 0; bool blnHasHScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & HSCROLL) != 0;
if (control.Visible) if (control is TextBox)
{ {
if (m_lstVCache.ContainsKey(control)) var txt = (TextBox)control;
if (txt.ScrollBars == ScrollBars.Both)
{ {
m_lstVCache[control].Location = new System.Drawing.Point(control.Right - m_lstVCache[control].Width - 1, control.Top + 1); blnHasVScrollbar = true;
if (blnHasHScrollbar) blnHasHScrollbar = true;
}
else if (txt.ScrollBars == ScrollBars.Vertical)
{
blnHasVScrollbar = true;
blnHasHScrollbar = false;
}
else if (txt.ScrollBars == ScrollBars.Horizontal)
{ {
m_lstVCache[control].Height = control.Height - m_lstVCache[control].Width - 2; blnHasVScrollbar = false;
blnHasHScrollbar = true;
} }
else else
{ {
m_lstVCache[control].Height = control.Height - 2; blnHasVScrollbar = false;
blnHasHScrollbar = false;
} }
} }
if (control.Visible)
if (m_lstHCache.ContainsKey(control)) {
if (m_lstVCache.ContainsKey(control))
{ {
m_lstHCache[control].Location = new System.Drawing.Point(control.Left + 1, control.Bottom - m_lstHCache[control].Height - 1); m_lstVCache[control].Location = new System.Drawing.Point(control.Right - m_lstVCache[control].Width, control.Top);
if (blnHasHScrollbar) if (blnHasHScrollbar)
{ {
m_lstHCache[control].Width = control.Width - m_lstHCache[control].Height - 2; m_lstVCache[control].Height = control.Height - m_lstHCache[control].Height;
} }
else else
{ {
m_lstHCache[control].Width = control.Width - 2; m_lstVCache[control].Height = control.Height;
} }
} }
if (m_lstHCache.ContainsKey(control))
{
m_lstHCache[control].Location = new System.Drawing.Point(control.Left, control.Bottom - m_lstHCache[control].Height);
//if (blnHasVScrollbar)
//{
// m_lstHCache[control].Width = control.Width - m_lstVCache[control].Width;
//}
//else
//{
m_lstHCache[control].Width = control.Width;
//}
}
} }
} }
...@@ -307,20 +440,17 @@ namespace HZH_Controls.Controls ...@@ -307,20 +440,17 @@ namespace HZH_Controls.Controls
void control_VisibleChanged(object sender, EventArgs e) void control_VisibleChanged(object sender, EventArgs e)
{ {
Control control = (Control)sender; Control control = (Control)sender;
if (!control.Visible)
{
if (m_lstVCache.ContainsKey(control) && m_lstVCache[control].Parent != null) if (m_lstVCache.ContainsKey(control) && m_lstVCache[control].Parent != null)
{ {
m_lstVCache[control].Parent.Controls.Remove(m_lstVCache[control]); m_lstVCache[control].Visible = control.Visible;
m_lstVCache.Remove(control);
} }
if (m_lstHCache.ContainsKey(control) && m_lstHCache[control].Parent != null) if (m_lstHCache.ContainsKey(control) && m_lstHCache[control].Parent != null)
{ {
m_lstHCache[control].Parent.Controls.Remove(m_lstHCache[control]); m_lstHCache[control].Visible = control.Visible;
m_lstHCache.Remove(control);
}
} }
} }
private const int HSCROLL = 0x100000; private const int HSCROLL = 0x100000;
...@@ -336,19 +466,23 @@ namespace HZH_Controls.Controls ...@@ -336,19 +466,23 @@ namespace HZH_Controls.Controls
if (m_lstVCache.ContainsValue(bar)) if (m_lstVCache.ContainsValue(bar))
{ {
Control c = m_lstVCache.FirstOrDefault(p => p.Value == bar).Key; Control c = m_lstVCache.FirstOrDefault(p => p.Value == bar).Key;
//ControlHelper.SetVScrollValue(c.Handle, bar.Value);
if (c is ScrollableControl) if (c is ScrollableControl)
{ {
(c as ScrollableControl).AutoScrollPosition = new Point((c as ScrollableControl).AutoScrollPosition.X, bar.Value); (c as ScrollableControl).AutoScrollPosition = new Point((c as ScrollableControl).AutoScrollPosition.X, bar.Value);
} }
else if (c is TreeView) else if (c is TreeView)
{ {
TreeView tv = (c as TreeView); ControlHelper.SetVScrollValue(c.Handle, bar.Value / ((c as TreeView).ItemHeight));
SetTreeViewVScrollLocation(tv, tv.Nodes, bar.Value);
} }
else if (c is TextBox) else if (c is TextBox)
{ {
TextBox txt = (c as TextBox); ControlHelper.SetVScrollValue(c.Handle, bar.Value / ((c as TextBox).PreferredHeight));
SetTextBoxVScrollLocation(txt, bar.Value); }
else if (c is RichTextBox)
{
ControlHelper.SetVScrollValue(c.Handle, bar.Value );
} }
} }
} }
...@@ -365,14 +499,20 @@ namespace HZH_Controls.Controls ...@@ -365,14 +499,20 @@ namespace HZH_Controls.Controls
} }
else if (c is TreeView) else if (c is TreeView)
{ {
ControlHelper.SetHScrollValue(c.Handle, bar.Value);
//TreeView tv = (c as TreeView); //TreeView tv = (c as TreeView);
//SetTreeViewVScrollLocation(tv, tv.Nodes, bar.Value); //SetTreeViewVScrollLocation(tv, tv.Nodes, bar.Value);
} }
else if (c is TextBox) else if (c is TextBox)
{ {
ControlHelper.SetHScrollValue(c.Handle, bar.Value);
//TextBox txt = (c as TextBox); //TextBox txt = (c as TextBox);
//SetTextBoxVScrollLocation(txt, bar.Value); //SetTextBoxVScrollLocation(txt, bar.Value);
} }
else if (c is RichTextBox)
{
ControlHelper.SetHScrollValue(c.Handle, bar.Value);
}
} }
} }
...@@ -386,70 +526,41 @@ namespace HZH_Controls.Controls ...@@ -386,70 +526,41 @@ namespace HZH_Controls.Controls
{ {
control_SizeChanged(sender as Control, null); control_SizeChanged(sender as Control, null);
} }
/// <summary>
/// Gets the tree node 最大高度
/// </summary>
/// <param name="tv">The tv.</param>
/// <returns>System.Int32.</returns>
private int GetTreeNodeMaxY(TreeView tv)
{
TreeNode tnLast = tv.Nodes[tv.Nodes.Count - 1];
begin:
if (tnLast.IsExpanded && tnLast.Nodes.Count > 0)
{
tnLast = tnLast.LastNode;
goto begin;
}
return tnLast.Bounds.Bottom;
}
private int GetTreeNodeMaxX(TreeView tv)
{
return tv.Nodes.Count != 0 ? tv.Nodes[0].Bounds.Right : 0;
}
void tv_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeView tv = (TreeView)sender;
if (m_lstVCache.ContainsKey(tv))
{
m_lstVCache[tv].Value = tv.Nodes.Count > 0 ? Math.Abs(tv.Nodes[0].Bounds.Top) : 0;
}
}
void tv_MouseWheel(object sender, MouseEventArgs e) // void tv_AfterSelect(object sender, TreeViewEventArgs e)
{ // {
TreeView tv = (TreeView)sender; // TreeView tv = (TreeView)sender;
if (m_lstVCache.ContainsKey(tv)) // if (m_lstVCache.ContainsKey(tv))
{ // {
m_lstVCache[tv].Value = tv.Nodes.Count > 0 ? Math.Abs(tv.Nodes[0].Bounds.Top) : 0; // m_lstVCache[tv].Value = tv.Nodes.Count > 0 ? Math.Abs(tv.Nodes[0].Bounds.Top) : 0;
} // }
} // }
/// <summary>
/// Sets the TreeView scroll location. ///// <summary>
/// </summary> ///// Sets the TreeView scroll location.
/// <param name="tv">The tv.</param> ///// </summary>
/// <param name="tns">The TNS.</param> ///// <param name="tv">The tv.</param>
/// <param name="intY">The int y.</param> ///// <param name="tns">The TNS.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> ///// <param name="intY">The int y.</param>
private bool SetTreeViewVScrollLocation(TreeView tv, TreeNodeCollection tns, int intY) ///// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
{ //private bool SetTreeViewVScrollLocation(TreeView tv, TreeNodeCollection tns, int intY)
for (int i = 0; i < tns.Count; i++) //{
{ // for (int i = 0; i < tns.Count; i++)
if (intY >= tns[i].Bounds.Top - tv.Nodes[0].Bounds.Top - 3 && intY <= tns[i].Bounds.Bottom - tv.Nodes[0].Bounds.Top + 3) // {
{ // if (intY >= tns[i].Bounds.Top - tv.Nodes[0].Bounds.Top - 3 && intY <= tns[i].Bounds.Bottom - tv.Nodes[0].Bounds.Top + 3)
tns[i].EnsureVisible(); // {
return true; // tns[i].EnsureVisible();
} // return true;
else if (tns[i].IsExpanded && tns[i].Nodes.Count > 0) // }
{ // else if (tns[i].IsExpanded && tns[i].Nodes.Count > 0)
bool bln = SetTreeViewVScrollLocation(tv, tns[i].Nodes, intY); // {
if (bln) // bool bln = SetTreeViewVScrollLocation(tv, tns[i].Nodes, intY);
return true; // if (bln)
} // return true;
} // }
return false; // }
} // return false;
//}
#endregion #endregion
#region TextBox处理 English:TextBox Processing #region TextBox处理 English:TextBox Processing
...@@ -458,80 +569,82 @@ namespace HZH_Controls.Controls ...@@ -458,80 +569,82 @@ namespace HZH_Controls.Controls
{ {
TextBox txt = sender as TextBox; TextBox txt = sender as TextBox;
control_SizeChanged(txt, null); control_SizeChanged(txt, null);
SetVMaxNum(txt);
if (m_lstVCache.ContainsKey(txt))
{
using (var g = txt.CreateGraphics())
{
var size = g.MeasureString(txt.Text.Substring(0, txt.SelectionStart), txt.Font);
m_lstVCache[txt].Value = (int)size.Height;
}
}
}
private void SetTextBoxVScrollLocation(TextBox txt, int intY)
{
using (var g = txt.CreateGraphics())
{
for (int i = 0; i < txt.Lines.Length; i++)
{
string str = string.Join("\n", txt.Lines.Take(i + 1));
var size = g.MeasureString(str, txt.Font);
if (size.Height >= intY)
{
txt.SelectionStart = str.Length;
txt.ScrollToCaret();
return;
}
}
}
}
void txt_KeyDown(object sender, KeyEventArgs e) //if (m_lstVCache.ContainsKey(txt))
{ //{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) // using (var g = txt.CreateGraphics())
{ // {
TextBox txt = (TextBox)sender; // var size = g.MeasureString(txt.Text.Substring(0, txt.SelectionStart), txt.Font);
if (m_lstVCache.ContainsKey(txt)) // m_lstVCache[txt].Value = (int)size.Height;
{ // }
using (var g = txt.CreateGraphics()) //}
{ }
var size = g.MeasureString(txt.Text.Substring(0, txt.SelectionStart), txt.Font); //private void SetTextBoxVScrollLocation(TextBox txt, int intY)
m_lstVCache[txt].Value = (int)size.Height; //{
} // using (var g = txt.CreateGraphics())
} // {
} // for (int i = 0; i < txt.Lines.Length; i++)
} // {
// string str = string.Join("\n", txt.Lines.Take(i + 1));
// var size = g.MeasureString(str, txt.Font);
// if (size.Height >= intY)
// {
// txt.SelectionStart = str.Length;
// txt.ScrollToCaret();
// return;
// }
// }
// }
//}
void txt_MouseWheel(object sender, MouseEventArgs e) void txt_KeyDown(object sender, KeyEventArgs e)
{
TextBox txt = (TextBox)sender;
if (m_lstVCache.ContainsKey(txt))
{
using (var g = txt.CreateGraphics())
{
StringBuilder str = new StringBuilder();
for (int i = 0; i < System.Windows.Forms.SystemInformation.MouseWheelScrollLines; i++)
{
str.AppendLine("A");
}
var height = (int)g.MeasureString(str.ToString(), txt.Font).Height;
if (e.Delta < 0)
{
if (height + m_lstVCache[txt].Value > m_lstVCache[txt].Maximum)
m_lstVCache[txt].Value = m_lstVCache[txt].Maximum;
else
m_lstVCache[txt].Value += height;
}
else
{ {
if (m_lstVCache[txt].Value - height < 0) TextBox txt = sender as TextBox;
m_lstVCache[txt].Value = 0; control_SizeChanged(txt, null);
else //if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
m_lstVCache[txt].Value -= height; //{
} // TextBox txt = (TextBox)sender;
} // if (m_lstVCache.ContainsKey(txt))
} // {
} // using (var g = txt.CreateGraphics())
// {
// var size = g.MeasureString(txt.Text.Substring(0, txt.SelectionStart), txt.Font);
// m_lstVCache[txt].Value = (int)size.Height;
// }
// }
//}
}
//void txt_MouseWheel(object sender, MouseEventArgs e)
//{
// TextBox txt = (TextBox)sender;
// if (m_lstVCache.ContainsKey(txt))
// {
// using (var g = txt.CreateGraphics())
// {
// StringBuilder str = new StringBuilder();
// for (int i = 0; i < System.Windows.Forms.SystemInformation.MouseWheelScrollLines; i++)
// {
// str.AppendLine("A");
// }
// var height = (int)g.MeasureString(str.ToString(), txt.Font).Height;
// if (e.Delta < 0)
// {
// if (height + m_lstVCache[txt].Value > m_lstVCache[txt].Maximum)
// m_lstVCache[txt].Value = m_lstVCache[txt].Maximum;
// else
// m_lstVCache[txt].Value += height;
// }
// else
// {
// if (m_lstVCache[txt].Value - height < 0)
// m_lstVCache[txt].Value = 0;
// else
// m_lstVCache[txt].Value -= height;
// }
// }
// }
//}
#endregion #endregion
} }
} }
...@@ -151,9 +151,11 @@ namespace HZH_Controls.Controls ...@@ -151,9 +151,11 @@ namespace HZH_Controls.Controls
set set
{ {
moValue = value; moValue = value;
if (moValue > moMaximum)
moValue = moMaximum;
int nTrackWidth = (this.Width - btnWidth * 2); int nTrackWidth = (this.Width - btnWidth * 2);
float fThumbWidth = ((float)LargeChange / (float)Maximum) * nTrackWidth; float fThumbWidth = nTrackWidth - Maximum;
//float fThumbWidth = ((float)LargeChange / (float)Maximum) * nTrackWidth;
int nThumbWidth = (int)fThumbWidth; int nThumbWidth = (int)fThumbWidth;
if (nThumbWidth > nTrackWidth) if (nThumbWidth > nTrackWidth)
...@@ -260,9 +262,14 @@ namespace HZH_Controls.Controls ...@@ -260,9 +262,14 @@ namespace HZH_Controls.Controls
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param> /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
private void CustomScrollbar_MouseDown(object sender, MouseEventArgs e) private void CustomScrollbar_MouseDown(object sender, MouseEventArgs e)
{ {
if (Maximum <= 0)
{
return;
}
Point ptPoint = this.PointToClient(Cursor.Position); Point ptPoint = this.PointToClient(Cursor.Position);
int nTrackWidth = (this.Width - btnWidth * 2); int nTrackWidth = (this.Width - btnWidth * 2);
float fThumbWidth = ((float)LargeChange / (float)Maximum) * nTrackWidth; float fThumbWidth = nTrackWidth - Maximum;
//float fThumbWidth = ((float)LargeChange / (float)Maximum) * nTrackWidth;
int nThumbWidth = (int)fThumbWidth; int nThumbWidth = (int)fThumbWidth;
if (nThumbWidth > nTrackWidth) if (nThumbWidth > nTrackWidth)
...@@ -366,6 +373,7 @@ namespace HZH_Controls.Controls ...@@ -366,6 +373,7 @@ namespace HZH_Controls.Controls
{ {
this.moThumbMouseDown = false; this.moThumbMouseDown = false;
this.moThumbMouseDragging = false; this.moThumbMouseDragging = false;
Application.DoEvents();
} }
/// <summary> /// <summary>
...@@ -376,7 +384,8 @@ namespace HZH_Controls.Controls ...@@ -376,7 +384,8 @@ namespace HZH_Controls.Controls
{ {
int nRealRange = Maximum - Minimum; int nRealRange = Maximum - Minimum;
int nTrackWidth = (this.Width - btnWidth * 2); int nTrackWidth = (this.Width - btnWidth * 2);
float fThumbWidth = ((float)LargeChange / (float)Maximum) * nTrackWidth; // float fThumbWidth = ((float)LargeChange / (float)Maximum) * nTrackWidth;
float fThumbWidth = nTrackWidth - Maximum;
int nThumbWidth = (int)fThumbWidth; int nThumbWidth = (int)fThumbWidth;
if (nThumbWidth > nTrackWidth) if (nThumbWidth > nTrackWidth)
...@@ -414,11 +423,13 @@ namespace HZH_Controls.Controls ...@@ -414,11 +423,13 @@ namespace HZH_Controls.Controls
float fPerc = (float)moThumbLeft / (float)nPixelRange; float fPerc = (float)moThumbLeft / (float)nPixelRange;
float fValue = fPerc * (Maximum - LargeChange); float fValue = fPerc * (Maximum - (nNewThumbLeft == nPixelRange ? 0 : LargeChange));
moValue = (int)fValue; //float fValue = fPerc * (Maximum - LargeChange);
if (Math.Abs(moValue - fValue) >= 1)
Application.DoEvents(); Application.DoEvents();
else
return;
moValue = (int)fValue;
Invalidate(); Invalidate();
} }
} }
...@@ -456,10 +467,12 @@ namespace HZH_Controls.Controls ...@@ -456,10 +467,12 @@ namespace HZH_Controls.Controls
{ {
base.OnPaint(e); base.OnPaint(e);
e.Graphics.SetGDIHigh(); e.Graphics.SetGDIHigh();
if (Maximum > 0)
{
//draw thumb //draw thumb
int nTrackWidth = (this.Width - btnWidth * 2); int nTrackWidth = (this.Width - btnWidth * 2);
float fThumbWidth = ((float)LargeChange / (float)Maximum) * nTrackWidth; //float fThumbWidth = ((float)LargeChange / (float)Maximum) * nTrackWidth;
float fThumbWidth = nTrackWidth - Maximum;
int nThumbWidth = (int)fThumbWidth; int nThumbWidth = (int)fThumbWidth;
if (nThumbWidth > nTrackWidth) if (nThumbWidth > nTrackWidth)
...@@ -474,8 +487,10 @@ namespace HZH_Controls.Controls ...@@ -474,8 +487,10 @@ namespace HZH_Controls.Controls
} }
int nLeft = moThumbLeft; int nLeft = moThumbLeft;
nLeft += btnWidth; nLeft += btnWidth;
if (nLeft + nThumbWidth > this.Width - btnWidth)
nLeft = this.Width - btnWidth - nThumbWidth;
e.Graphics.FillPath(new SolidBrush(thumbColor), new Rectangle(nLeft, 1, nThumbWidth, this.Height - 3).CreateRoundedRectanglePath(this.ConerRadius)); e.Graphics.FillPath(new SolidBrush(thumbColor), new Rectangle(nLeft, 1, nThumbWidth, this.Height - 3).CreateRoundedRectanglePath(this.ConerRadius));
}
ControlHelper.PaintTriangle(e.Graphics, new SolidBrush(thumbColor), new Point(btnWidth - Math.Min(5, this.Height / 2), this.Height / 2), Math.Min(5, this.Height / 2), GraphDirection.Leftward); ControlHelper.PaintTriangle(e.Graphics, new SolidBrush(thumbColor), new Point(btnWidth - Math.Min(5, this.Height / 2), this.Height / 2), Math.Min(5, this.Height / 2), GraphDirection.Leftward);
ControlHelper.PaintTriangle(e.Graphics, new SolidBrush(thumbColor), new Point(this.Width - (btnWidth - Math.Min(5, this.Height / 2)), this.Height / 2), Math.Min(5, this.Height / 2), GraphDirection.Rightward); ControlHelper.PaintTriangle(e.Graphics, new SolidBrush(thumbColor), new Point(this.Width - (btnWidth - Math.Min(5, this.Height / 2)), this.Height / 2), Math.Min(5, this.Height / 2), GraphDirection.Rightward);
......
...@@ -43,7 +43,7 @@ namespace HZH_Controls.Controls ...@@ -43,7 +43,7 @@ namespace HZH_Controls.Controls
/// <summary> /// <summary>
/// The mo small change /// The mo small change
/// </summary> /// </summary>
protected int moSmallChange = 1; protected int moSmallChange = 5;
/// <summary> /// <summary>
/// The mo minimum /// The mo minimum
/// </summary> /// </summary>
...@@ -92,7 +92,7 @@ namespace HZH_Controls.Controls ...@@ -92,7 +92,7 @@ namespace HZH_Controls.Controls
/// <summary> /// <summary>
/// The m int thumb minimum height /// The m int thumb minimum height
/// </summary> /// </summary>
private int m_intThumbMinHeight = 15; private int m_intThumbMinHeight = 30;
/// <summary> /// <summary>
/// Gets or sets the height of the BTN. /// Gets or sets the height of the BTN.
...@@ -176,7 +176,8 @@ namespace HZH_Controls.Controls ...@@ -176,7 +176,8 @@ namespace HZH_Controls.Controls
moValue = value; moValue = value;
int nTrackHeight = (this.Height - btnHeight * 2); int nTrackHeight = (this.Height - btnHeight * 2);
float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight; //float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight;
float fThumbHeight = nTrackHeight - Maximum;
int nThumbHeight = (int)fThumbHeight; int nThumbHeight = (int)fThumbHeight;
if (nThumbHeight > nTrackHeight) if (nThumbHeight > nTrackHeight)
...@@ -289,10 +290,12 @@ namespace HZH_Controls.Controls ...@@ -289,10 +290,12 @@ namespace HZH_Controls.Controls
{ {
base.OnPaint(e); base.OnPaint(e);
e.Graphics.SetGDIHigh(); e.Graphics.SetGDIHigh();
if (Maximum > 0)
{
//draw thumb //draw thumb
int nTrackHeight = (this.Height - btnHeight * 2); int nTrackHeight = (this.Height - btnHeight * 2);
float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight; //float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight;
float fThumbHeight = nTrackHeight - Maximum;
int nThumbHeight = (int)fThumbHeight; int nThumbHeight = (int)fThumbHeight;
if (nThumbHeight > nTrackHeight) if (nThumbHeight > nTrackHeight)
...@@ -307,15 +310,15 @@ namespace HZH_Controls.Controls ...@@ -307,15 +310,15 @@ namespace HZH_Controls.Controls
} }
int nTop = moThumbTop; int nTop = moThumbTop;
nTop += btnHeight; nTop += btnHeight;
if (nTop + nThumbHeight > this.Height - btnHeight)
nTop = this.Height - btnHeight - nThumbHeight;
e.Graphics.FillPath(new SolidBrush(thumbColor), new Rectangle(1, nTop, this.Width - 3, nThumbHeight).CreateRoundedRectanglePath(this.ConerRadius)); e.Graphics.FillPath(new SolidBrush(thumbColor), new Rectangle(1, nTop, this.Width - 3, nThumbHeight).CreateRoundedRectanglePath(this.ConerRadius));
}
ControlHelper.PaintTriangle(e.Graphics, new SolidBrush(thumbColor), new Point(this.Width / 2, btnHeight - Math.Min(5, this.Width / 2)), Math.Min(5, this.Width / 2), GraphDirection.Upward); ControlHelper.PaintTriangle(e.Graphics, new SolidBrush(thumbColor), new Point(this.Width / 2, btnHeight - Math.Min(5, this.Width / 2)), Math.Min(5, this.Width / 2), GraphDirection.Upward);
ControlHelper.PaintTriangle(e.Graphics, new SolidBrush(thumbColor), new Point(this.Width / 2, this.Height - (btnHeight - Math.Min(5, this.Width / 2))), Math.Min(5, this.Width / 2), GraphDirection.Downward); ControlHelper.PaintTriangle(e.Graphics, new SolidBrush(thumbColor), new Point(this.Width / 2, this.Height - (btnHeight - Math.Min(5, this.Width / 2))), Math.Min(5, this.Width / 2), GraphDirection.Downward);
} }
/// <summary> /// <summary>
/// Handles the MouseDown event of the CustomScrollbar control. /// Handles the MouseDown event of the CustomScrollbar control.
/// </summary> /// </summary>
...@@ -323,9 +326,12 @@ namespace HZH_Controls.Controls ...@@ -323,9 +326,12 @@ namespace HZH_Controls.Controls
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param> /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
private void CustomScrollbar_MouseDown(object sender, MouseEventArgs e) private void CustomScrollbar_MouseDown(object sender, MouseEventArgs e)
{ {
if (Maximum <= 0)
return;
Point ptPoint = this.PointToClient(Cursor.Position); Point ptPoint = this.PointToClient(Cursor.Position);
int nTrackHeight = (this.Height - btnHeight * 2); int nTrackHeight = (this.Height - btnHeight * 2);
float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight; //float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight;
float fThumbHeight = nTrackHeight - Maximum;
int nThumbHeight = (int)fThumbHeight; int nThumbHeight = (int)fThumbHeight;
if (nThumbHeight > nTrackHeight) if (nThumbHeight > nTrackHeight)
...@@ -441,7 +447,8 @@ namespace HZH_Controls.Controls ...@@ -441,7 +447,8 @@ namespace HZH_Controls.Controls
{ {
int nRealRange = Maximum - Minimum; int nRealRange = Maximum - Minimum;
int nTrackHeight = (this.Height - btnHeight * 2); int nTrackHeight = (this.Height - btnHeight * 2);
float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight; //float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight;
float fThumbHeight = nTrackHeight - Maximum;
int nThumbHeight = (int)fThumbHeight; int nThumbHeight = (int)fThumbHeight;
if (nThumbHeight > nTrackHeight) if (nThumbHeight > nTrackHeight)
...@@ -479,11 +486,19 @@ namespace HZH_Controls.Controls ...@@ -479,11 +486,19 @@ namespace HZH_Controls.Controls
float fPerc = (float)moThumbTop / (float)nPixelRange; float fPerc = (float)moThumbTop / (float)nPixelRange;
float fValue = fPerc * (Maximum - LargeChange); float fValue = fPerc * (Maximum - (nNewThumbTop == nPixelRange ? 0 : LargeChange));
moValue = (int)fValue; try
{
if (Math.Abs(moValue - fValue) >= 1)
Application.DoEvents(); Application.DoEvents();
else
{
return;
}
}
catch
{ }
moValue = (int)fValue;
Invalidate(); Invalidate();
} }
} }
......
...@@ -209,7 +209,7 @@ namespace HZH_Controls ...@@ -209,7 +209,7 @@ namespace HZH_Controls
} }
SetControlEnableds(lstCs.ToArray(), false); SetControlEnableds(lstCs.ToArray(), false);
} }
ThreadPool.QueueUserWorkItem(delegate(object a) ThreadPool.QueueUserWorkItem(delegate (object a)
{ {
try try
{ {
...@@ -1334,8 +1334,24 @@ namespace HZH_Controls ...@@ -1334,8 +1334,24 @@ namespace HZH_Controls
static uint SB_CTL = 0x2; static uint SB_CTL = 0x2;
static uint SB_BOTH = 0x3; static uint SB_BOTH = 0x3;
[DllImport("user32.dll", SetLastError = true, EntryPoint = "GetScrollInfo")] [DllImport("user32.dll", SetLastError = true, EntryPoint = "GetScrollInfo")]
private static extern int GetScrollInfo(IntPtr hWnd, uint idObject, ref SCROLLINFO psbi); private static extern int GetScrollInfo(IntPtr hWnd, uint fnBar, ref SCROLLINFO psbi);
[DllImport("user32.dll")]//[return: MarshalAs(UnmanagedType.Bool)]
private static extern int SetScrollInfo(IntPtr handle, uint fnBar, ref SCROLLINFO si, bool fRedraw);
[DllImport("user32.dll", EntryPoint = "PostMessage")]
private static extern bool PostMessage(IntPtr handle, int msg, uint wParam, uint lParam);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
/// <summary>
/// ShowScrollBar
/// </summary>
/// <param name="hWnd">hWnd</param>
/// <param name="wBar">0:horizontal,1:vertical,3:both</param>
/// <param name="bShow">bShow</param>
/// <returns></returns>
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
/// <summary> /// <summary>
///获取水平滚动条信息 ///获取水平滚动条信息
/// </summary> /// </summary>
...@@ -1344,8 +1360,8 @@ namespace HZH_Controls ...@@ -1344,8 +1360,8 @@ namespace HZH_Controls
public static SCROLLINFO GetHScrollBarInfo(IntPtr hWnd) public static SCROLLINFO GetHScrollBarInfo(IntPtr hWnd)
{ {
SCROLLINFO info = new SCROLLINFO(); SCROLLINFO info = new SCROLLINFO();
info.cbSize = (uint)Marshal.SizeOf(info); info.cbSize = (int)Marshal.SizeOf(info);
info.fMask = (int)ScrollInfoMask.SIF_ALL; info.fMask = (int)ScrollInfoMask.SIF_DISABLENOSCROLL | (int)ScrollInfoMask.SIF_ALL;
int intRef = GetScrollInfo(hWnd, SB_HORZ, ref info); int intRef = GetScrollInfo(hWnd, SB_HORZ, ref info);
return info; return info;
} }
...@@ -1357,20 +1373,21 @@ namespace HZH_Controls ...@@ -1357,20 +1373,21 @@ namespace HZH_Controls
public static SCROLLINFO GetVScrollBarInfo(IntPtr hWnd) public static SCROLLINFO GetVScrollBarInfo(IntPtr hWnd)
{ {
SCROLLINFO info = new SCROLLINFO(); SCROLLINFO info = new SCROLLINFO();
info.cbSize = (uint)Marshal.SizeOf(info); info.cbSize = (int)Marshal.SizeOf(info);
info.fMask = (int)ScrollInfoMask.SIF_ALL; info.fMask = (int)ScrollInfoMask.SIF_DISABLENOSCROLL | (int)ScrollInfoMask.SIF_ALL;
int intRef = GetScrollInfo(hWnd, SB_VERT, ref info); int intRef = GetScrollInfo(hWnd, SB_VERT, ref info);
return info; return info;
} }
public struct SCROLLINFO public struct SCROLLINFO
{ {
public uint cbSize; public int cbSize;
public uint fMask; public int fMask;
public int nMin; public int nMin;
public int nMax; public int nMax;
public uint nPage; public int nPage;
public int nPos; public int nPos;
public int nTrackPos; public int nTrackPos;
public int ScrollMax { get { return nMax + 1 - nPage; } }
} }
public enum ScrollInfoMask : uint public enum ScrollInfoMask : uint
{ {
...@@ -1380,6 +1397,66 @@ namespace HZH_Controls ...@@ -1380,6 +1397,66 @@ namespace HZH_Controls
SIF_DISABLENOSCROLL = 0x8, SIF_DISABLENOSCROLL = 0x8,
SIF_TRACKPOS = 0x10, SIF_TRACKPOS = 0x10,
SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS), SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS),
SB_THUMBTRACK = 5,
WM_HSCROLL = 0x0114,
WM_VSCROLL = 0x0115,
SB_LINEUP = 0,
SB_LINEDOWN = 1,
SB_LINELEFT = 0,
SB_LINERIGHT = 1,
}
public static void SetVScrollValue(IntPtr handle, int value)
{
var info = GetVScrollBarInfo(handle);
info.nPos = value;
SetScrollInfo(handle, SB_VERT, ref info, true);
PostMessage(handle, (int)ScrollInfoMask.WM_VSCROLL, MakeLong((short)ScrollInfoMask.SB_THUMBTRACK, highPart: (short)info.nPos), 0);
}
public static void SetHScrollValue(IntPtr handle, int value)
{
var info = GetHScrollBarInfo(handle);
info.nPos = value;
SetScrollInfo(handle, SB_HORZ, ref info, true);
PostMessage(handle, (int)ScrollInfoMask.WM_HSCROLL, MakeLong((short)ScrollInfoMask.SB_THUMBTRACK, highPart: (short)info.nPos), 0);
}
private static uint MakeLong(short lowPart, short highPart)
{
return (ushort)lowPart | (uint)(highPart << 16);
}
/// <summary>
/// 控件向上滚动一个单位
/// </summary>
/// <param name="handle">控件句柄</param>
public static void ScrollUp(IntPtr handle)
{
SendMessage(handle, (int)ScrollInfoMask.WM_VSCROLL, (int)ScrollInfoMask.SB_LINEUP, 0);
}
/// <summary>
/// 控件向下滚动一个单位
/// </summary>
/// <param name="handle">控件句柄</param>
public static void ScrollDown(IntPtr handle)
{
SendMessage(handle, (int)ScrollInfoMask.WM_VSCROLL, (int)ScrollInfoMask.SB_LINEDOWN, 0);
}
/// <summary>
/// 控件向左滚动一个单位
/// </summary>
/// <param name="handle">控件句柄</param>
public static void ScrollLeft(IntPtr handle)
{
SendMessage(handle, (int)ScrollInfoMask.WM_HSCROLL, (int)ScrollInfoMask.SB_LINELEFT, 0);
}
/// <summary>
/// 控件向右滚动一个单位
/// </summary>
/// <param name="handle">控件句柄</param>
public static void ScrollRight(IntPtr handle)
{
SendMessage(handle, (int)ScrollInfoMask.WM_VSCROLL, (int)ScrollInfoMask.SB_LINERIGHT, 0);
} }
#endregion #endregion
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!