I think I finally got a good solution. In the listbox, I completely took
control of the scrolling using the following:
/// <summary>
/// This scrolls the control up or down one unit, depending on the parameter
/// </summary>
/// <param name="dir">The direction to scroll. 0 is down and 1 is up</param>
private void scrollMe(System.IntPtr dir)
{
System.Windows.Forms.Message ScrollMessage = new Message();
ScrollMessage.HWnd = Handle;
ScrollMessage.Msg = 0x0115;
ScrollMessage.WParam = dir;
this.DefWndProc( ref ScrollMessage );
}
private void scrollMe(System.IntPtr dir, int count)
{
for (int a=0;a<count;a++)
scrollMe(dir);
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == 0x020A) // WM_MOUSEWHEEL
{
if (m.WParam.ToInt32() > 0)
this.scrollMe(new IntPtr(0),5);
else
this.scrollMe(new IntPtr(1),5);
return;
}
if (m.Msg == 0x0115) // WM_VSCROLL
{
int w = m.WParam.ToInt32();
if (w == 0) // clicked the scroll arrow down
this.scrollMe(new IntPtr(0),3);
else if (w == 1) // clicked the scroll arrow up
this.scrollMe(new IntPtr(1),3);
else if (w == 2) // clicked to scroll down a page
this.scrollMe(new IntPtr(0),10);
else if (w == 3) // clicked to scroll up a page
this.scrollMe(new IntPtr(1),10);
else if (w != 8) // 8 happens at the end, dont like 8
{
int num = (int)Math.Round((double)Math.Abs(this.scrollmark -
w)/65536); // 65536 is one item up/down (0x10000), num is the number of
scrolls
if (w > this.scrollmark) // scroll up
{
this.scrollMe(new IntPtr(1),num);
this.scrollmark = w;
}
else if (w < this.scrollmark) // scroll down
{
this.scrollMe(new IntPtr(0),num);
this.scrollmark = w;
}
}
return;
}
base.WndProc(ref m);
}
This, coupled with the textbox modifications you provided, works great. It
gets a little slow with 100 textboxes, but this is to be expected.
Thanks
Bob
Bob Dankert said:
Ying,
Thank you for the help. After applying some of your various modifications
as well as a few others I came up with, the issue is much less prevelent.
Thanks a lot for your help!
Bob Dankert
"Ying-Shen Yu[MSFT]" said:
Hi Bob,
My modified listbox works well in my test machine, I'm not sure where is
the problem, I sent my test code to your mail box, you may try it to see if
works on your machine.
In my experience, Analyzing the underlying Win32 messages of the Listbox
and the TextBox will be helpful to determine the cause of the ficker since
flicker is caused by frequent WM_PAINT messages. You may capturing the
messages using Spy++, In my testing, I captured the List box and its child
windows, I only choosed "general" and the Listbox messages in "Messages"
Tab.
Also, in my test, There is an option in windows system settings names
"smooth-scroll list boxes", which will change the behavior of the listbox,
if it is enabled the Listbox will send WM_PRINT to save the bitmap first,
which will cause trouble to the Textbox since it does not aware the
scrolling. That's why I disabled the WM_PRINT message.
When this option is disabled, it will just repaint the item as needed, in
my test Rhett's workaround works better with this option disabled.
Here is just some findings in my investigation, I hope it will help you a
bit. If you need help in investigating the flicker issue, don't hesitate to
post it in the newsgroup.
Good Luck!
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.