المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Strange windows forms control bug?



C# Programming
08-25-2011, 05:21 AM
I have the following code inside a Derived "Panel" control in C# 4:
public void ForceMoveScrollBar(int distX, int distY) { if (Math.Abs(distX) > HorizontalScroll.Maximum - HorizontalScroll.Value) { HorizontalScroll.Value = HorizontalScroll.Maximum; } else { HorizontalScroll.Value += distX; } }
It is meant to scroll the horizontal scroll inside the panel by a certain amont when a key is clicked on the keyboard.

However I have to tap the key twice for it to work, the first time make my panel flicker and the second time works.

The only fix I have is:

public void ForceMoveScrollBar(int distX, int distY) { if(Math.Abs(distX) >HorizontalScroll.Maximum - HorizontalScroll.Value) { HorizontalScroll.Value = HorizontalScroll.Maximum; } else { //The value does not set on the first assigment! HorizontalScroll.Value += distX; //so I add another one!? HorizontalScroll.Value += distX; } }


Why does it do this strange behaviour?