Make sure WM_HSCROLL and WM_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 a ScrollableControl derivative, which includes (but is not limited to) Panel, UserControl, and Form. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles]