Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Strange windows forms control bug?

Strange windows forms control bug?

Scheduled Pinned Locked Moved C#
helpquestioncsharpwinforms
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venomation
    wrote on last edited by
    #1

    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?

    S 1 Reply Last reply
    0
    • V venomation

      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?

      S Offline
      S Offline
      simplefolk
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups