[英]Scroll Bar click event method running twice c#
我有一個使用垂直滾動條瀏覽的用戶控件。 每次我單擊滾動條的min按鈕時,它都會正確執行被調用的方法,但是不會退出,而是從被調用的方法返回后再次調用該方法。 基本上,滾動條事件每次觸發兩次以更新其值。 為什么?
這是我的代碼的精簡版。
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();
}
經過大量的網絡瀏覽后,我發現在初始SmallIncrement事件之后正在創建一個EndScroll事件。 為什么發生這種情況超出了我的想法! 我將vScrollbar事件處理程序更改如下:
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
if (e.Type == ScrollEventType.EndScroll) return;
ThreadTest((ushort)vScrollBar1.Value);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.