Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

scrolling a panel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Dankert - 13 Oct 2004 21:03 GMT
I am having trouble scrolling a panel horizontally to match the horizontal
scroll from a listbox.  Currently, I catch the listbox WM_HSCROLL in the
listbox WndPrc, and have this call a method in my Panel to scroll the panel.
The method is:

public void ScrollMeHorizontal(System.IntPtr wParam)
{
System.Windows.Forms.Message ScrollMessage = new Message();
ScrollMessage.HWnd = this.Handle;
ScrollMessage.Msg = 0x0114;
ScrollMessage.WParam = wParam;
this.DefWndProc(ref ScrollMessage);
MessageBox.Show("Test");
}

The message box is displaying 'test', so I know the method is getting
called, however the panel is not being scrolled at all.  For reference, the
panel contains two labels side by side, and right-most label is half cut-off
and should scroll.

(As you can probably guess, I am implementing my own column headers for a
list box - and if your wondering, netiehr a listview nor datagrid will work
for my application.)

Thanks!

Bob Dankert
Bob Dankert - 13 Oct 2004 21:49 GMT
I made some progress with this issue.
1.  Need to use the SendMessage API, can not send a message through
DefWndPrc
2.  Need to set AutoScroll = true for the Panel.

However, I am still having trouble getting the Panel to match the listbox
when a SB_THUMBPOSITION or SB_THUMBTRACK call is made.  In fact, the panel
does not scroll at all for either of these.  The Panel does seem to respond
to the rest of the scroll messages, however.

I would greatly appreciate any help with this...

Bob Dankert

>I am having trouble scrolling a panel horizontally to match the horizontal
>scroll from a listbox.  Currently, I catch the listbox WM_HSCROLL in the
[quoted text clipped - 23 lines]
>
> Bob Dankert
"Jeffrey Tan[MSFT]" - 14 Oct 2004 03:48 GMT
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
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Bob Dankert - 14 Oct 2004 14:41 GMT
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

> Hi Bob,
>
[quoted text clipped - 26 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 15 Oct 2004 03:29 GMT
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.

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
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Bob Dankert - 15 Oct 2004 14:02 GMT
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

> Hi Bob,
>
[quoted text clipped - 43 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 18 Oct 2004 10:23 GMT
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

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.