Strange windows forms control bug?
-
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?
-
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?
I'm assuming your using autoscroll I have had better luck setting the postion
int distX += HorizontalScroll.Value;
int distY += VerticalScroll.Value;
//do some sort of range check
//then set the AutoScrollPostion
AutoScrollPosition = new Point(x, y);hope this helps