Reputation:
I have a user control that uses a vertical scroll bar to browse through it. Each time I click on a min button of the scroll bar it executes the called method properly but instead of exiting, following the return from the called method, it recalls the method a second time. Basically the scroll bar event is firing twice updating its value each time. Why?
Here is a condensed version of my code....
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
ThreadTest((ushort)vScrollBar1.Value);
}
private void ThreadTest(ushort value)
{
if (mC6800Screen1.InvokeRequired)
{
TestCallBack tcb = new TestCallBack(displayVirtualMemory);
Invoke(tcb, new object[] {value});
}
else
{
displayVirtualMemory(value);
}
}
private void displayVirtualMemory(ushort value)
{
//This method simply displays the contents of an array [0 - 0xffff]
//16 rows at a time.
for (ushort row = value; row < value + 400; row += 16)
{
//Compute the index offset (16 bits per row)
string indexOffset = row.ToString("X4");
var indexChars = indexOffset.ToCharArray();
//Display memory index
for (ushort arrayPosition = 0; arrayPosition < indexOffset.Length; arrayPosition++)
{
mC6800Screen1.screenMemory[screenPosition] = (byte)indexChars[arrayPosition];
screenPosition += 2;
}
screenPosition += 4;
}
//the data is copyied to a bitmap which is transfered to a user control
//once all the processing is complete.
mC6800Screen1.Invalidate();
mC6800Screen1.Update();
}
Upvotes: 0
Views: 856
Reputation:
After much web browsing, I discovered that an EndScroll event is being created following the initial SmallIncrement event. Why this occurs is beyond my grey matter! I changed the vScrollbar event handler as follows:
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
if (e.Type == ScrollEventType.EndScroll) return;
ThreadTest((ushort)vScrollBar1.Value);
}
Upvotes: 3