Scrollbar movement Notification:
-
Hi.. I have a specification sheet which has a horizontal scrool bar.. I would like to know what is the windows notify message sent when i move the horizontal scroll bar. I tried WM_HSCROLL but it was not working for me.. Can any one help me in this reg. Thanks Sudhakar
-
Hi.. I have a specification sheet which has a horizontal scrool bar.. I would like to know what is the windows notify message sent when i move the horizontal scroll bar. I tried WM_HSCROLL but it was not working for me.. Can any one help me in this reg. Thanks Sudhakar
Make sure
WM_HSCROLL
andWM_VSCROLL
are defined correctly, as in this example:using System;
using System.Drawing;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
Label lbl;
Test()
{
Text = "Sample";
AutoScroll = true;
lbl = new Label();
Controls.Add(lbl);
lbl.Location = new Point(0, 0);
lbl.Size = Size + Size;
lbl.TextAlign = ContentAlignment.MiddleCenter;
}
protected override void OnResize(EventArgs e)
{
lbl.Size = Size + Size;
base.OnResize(e);
}
const int WM_HSCROLL = 0x0114; // == 276
const int WM_VSCROLL = 0x0115; // == 277
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_HSCROLL)
{
lbl.Text = string.Format("HPos: {0}", HIWORD((int)m.WParam));
}
if (m.Msg == WM_VSCROLL)
{
lbl.Text = string.Format("VPos: {0}", HIWORD((int)m.WParam));
}
base.WndProc(ref m);
}
int HIWORD(int dword)
{
return dword >> 16;
}
}(Scroll to the center and watch the values change) You can also use the
AutoScrollPosition
for aScrollableControl
derivative, which includes (but is not limited to)Panel
,UserControl
, andForm
. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles]