Re: scrolling a panel

閲覧: 380 回
最初の未読メッセージにスキップ

Jeffrey Tan[MSFT]

未読、
2004/10/13 22:48:332004/10/13
To:
Hi Bob,

Based on my understanding, you want to make the panel horizontally scroll
with SB_THUMBPOSITION or SB_THUMBTRACK.

I have writen a sample, you may use the code snippet to this done:
const int WM_HSCROLL=0x114;
const int SB_THUMBPOSITION=0x4;
const int SB_THUMBTRACK = 0x5;

[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam,
IntPtr lParam);
private void button4_Click(object sender, System.EventArgs e)
{
SendMessage(this.panel1.Handle, WM_HSCROLL,
(IntPtr)(0x100000000&SB_THUMBPOSITION), IntPtr.Zero);
}
For more information of wParam and lParam, please refer to the document of
WM_HSCROLL Notification in MSDN.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Bob Dankert

未読、
2004/10/14 9:41:412004/10/14
To:
Jeffrey,

I found the problem with my code after doing a bit of investigating. It
seems that the internal method SetDisplayRectLocation needs to be called
after a SB_THUMBPOSITION or SB_THUMBTRACK scroll event. Here is my modified
code for scrolling which works:

public void ScrollMeHorizontal(System.IntPtr wParam)
{
int lo = LOWORD(wParam);
int hi = HIWORD(wParam);
SendMessage(this.Handle, (uint)0x0114, (UIntPtr)wParam.ToInt32(),
(System.IntPtr)0);
if (lo == 4 || lo == 5)
SetDisplayRectLocation(-hi, -DisplayRectangle.Y);
this.Invalidate();
foreach (Control ctrl in this.Controls)
ctrl.Refresh();
}

Unfortunately, I am unable to find any information regarding
SetDisplayRectLocation and DisplayRectangle as these are supposed to be
internal methods. Is there somewhere I can get more information on the
method and property which have fixed my code?

Thanks,

Bob Dankert

""Jeffrey Tan[MSFT]"" <v-j...@online.microsoft.com> wrote in message
news:JHJnRhZs...@cpmsftngxa10.phx.gbl...

Jeffrey Tan[MSFT]

未読、
2004/10/14 22:29:292004/10/14
To:
Hi Bob,

Thanks very much for your feedback!

I think I am not fully understand your problem. I think you just want to
programmatically control the scroll bar, yes? Does my code snippet of
P/inovke like this work for you?


const int WM_HSCROLL=0x114;
const int SB_THUMBPOSITION=0x4;
const int SB_THUMBTRACK = 0x5;

[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam,
IntPtr lParam);
private void button4_Click(object sender, System.EventArgs e)
{
SendMessage(this.panel1.Handle, WM_HSCROLL,
(IntPtr)(0x100000000&SB_THUMBPOSITION), IntPtr.Zero);
}

At my side, this code may will scroll the panel horizontally.

Also, we may use Panel's AutoScrollPosition property to control the scroll
position, like this:
private void Form1_Load(object sender, System.EventArgs e)
{
pt=new Point(this.panel1.AutoScrollPosition.X,
this.panel1.AutoScrollPosition.Y);
}

private Point pt;
private void button5_Click(object sender, System.EventArgs e)
{
pt=new Point(pt.X +5, pt.Y+5);
this.panel1.AutoScrollPosition=new Point(pt.X, pt.Y);
} //scroll the horizontally 5 pt and vertically 5 pt.

If I misunderstand you, please feel free to tell me, thanks.

Bob Dankert

未読、
2004/10/15 9:02:442004/10/15
To:
Jeffrey,

Sending a SB_THUMBPOSITION and SB_THUMBTRACK message does not work for me
unless I call the ScrollableControl.SetDisplayRectLocation method after the
message is sent. I found other people that were experiencing the same
problem. Everything is working great with this method, so I feel pretty
confident that it should work well for me.

Thanks for following up!

Bob Dankert

""Jeffrey Tan[MSFT]"" <v-j...@online.microsoft.com> wrote in message

news:SUQCU7l...@cpmsftngxa10.phx.gbl...

Jeffrey Tan[MSFT]

未読、
2004/10/18 5:23:032004/10/18
To:
Hi Bob,

Ok, I am glad it works well for your. Anyway, if you need further help,
please feel free to tell me, I will work with you. Thanks

全員に返信
投稿者に返信
転送
新着メール 0 件