Cyotek Forums

Source Code => Source Code => Topic started by: wmjordan on November 30, 2014, 11:44:07 AM

Title: Scrollbar Issue
Post by: wmjordan on November 30, 2014, 11:44:07 AM
I am now using the VirtualMode of ImageBox to render some content to the client.
I found that when I set the virtual image to GetInsideViewPort ().Width of the ImageBox, the horizontal scrollbar inappropriately appeared. Since the width of the image was the same as the inside view port, there was no need to show the horizontal scrollbar.

To verify this, please run the ImageBox.Demo application and launch the Virtual Mode demo. The initial size of the box in the demo was (543, 327). Please set the VirtualSize to (510, 327). You will see the result the same as shot1.png. Obviously there is still some margin on the right of the box and the Horizontal scrollbar was displayed despite of this.

Title: Re: Scrollbar Issue
Post by: Richard Moss on November 30, 2014, 07:44:32 PM
Interesting, I can confirm it here too. I thought it might have something to do with padding, but the padding on that demo is set to the default of zero. I'll do so more digging and see if I can figure out what's wrong.

Thanks for the bug report :)

Regards;
Richard Moss
Title: Re: Scrollbar Issue
Post by: Richard Moss on December 01, 2014, 07:01:39 PM
Hello,

The problem doesn't seem to be in the ImageBox control itself, but the underlying VirtualScrollableControl. I've done some tinkering, and seem to have resolved the problem, getting rid of the extra right and bottom padding which was appearing and causing the scrollbar to appear. However, I've only tested this in the context of VirtualMode demo form, so take it with a pinch of salt!

If you want to test out the fix, replace the AdjustScrollbars method of the VirtualScrollableControl as follows:

    private void AdjustScrollbars()
    {
      Rectangle clientRectangle;
      Size scrollSize;
      Size pageSize;
      bool horizontalScrollVisible;
      bool verticalScrollVisible;

      clientRectangle = this.ClientRectangle;
      scrollSize = Size.Empty;
      pageSize = Size.Empty;

      horizontalScrollVisible = this.AutoScroll && this.AutoScrollMinSize.Width > clientRectangle.Width;
      verticalScrollVisible = this.AutoScroll && this.AutoScrollMinSize.Height > clientRectangle.Height;

      if (verticalScrollVisible)
      {
        scrollSize.Height = this.AutoScrollMinSize.Height;
        pageSize.Height = clientRectangle.Height - 1;
      }

      if (horizontalScrollVisible)
      {
        scrollSize.Width = this.AutoScrollMinSize.Width;
        pageSize.Width = clientRectangle.Width - 1;
      }

      this.ScrollSize = scrollSize;
      this.PageSize = pageSize;
    }


Let me know if this solves your problem.

Regards;
Richard Moss
Title: Re: Scrollbar Issue
Post by: wmjordan on December 05, 2014, 02:08:28 AM
Thank you very much for the awesome work!
The issue was fixed successfully.

Title: Re: Scrollbar Issue
Post by: wmjordan on December 08, 2014, 11:03:52 AM
Somehow I ran into a problem.
I set the ImageBox with the following properties in the visual designer:

Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
Location = new System.Drawing.Point(3, 3);
Size = new System.Drawing.Size(281, 268);
VirtualMode = true;


When setting the Location property, due to effect of the Anchor property, the resize operation would be triggered, and AdjustScrollbars would be called.
At that time, since the Size property was not yet set, the client size of the ImageBox became (width,height)=(-2,-2).
When the code ran to the last line, it would crash.

if (verticalScrollVisible) {
scrollSize.Height = this.AutoScrollMinSize.Height;
pageSize.Height = clientRectangle.Height - 1;
}

if (horizontalScrollVisible) {
scrollSize.Width = this.AutoScrollMinSize.Width;
pageSize.Width = clientRectangle.Width - 1;
}

this.ScrollSize = scrollSize;
this.PageSize = pageSize;


I added the following lines after assigning value to the clientRectangle variable (clientRectangle = this.ClientRectangle;) and avoided the above issue.


// after clientRectangle = this.ClientRectangle;
if (clientRectangle.Width < 1 || clientRectangle.Height < 1) {
return;
}
// before scrollSize = Size.Empty;
Title: Re: Scrollbar Issue
Post by: Richard Moss on December 08, 2014, 04:49:00 PM
I had noticed while debugging the original issue that AdjustScrollbars was being called much more than I would have expected, however I didn't pursue it then. One problem at a time :)

Thanks for finding this issue and the fix - I'll look into this more carefully when I've got a chance.

Regards;
Richard Moss
Title: Re: Scrollbar Issue
Post by: wmjordan on December 17, 2014, 02:19:47 AM
Thank you for looking into this issue.
I am using SVN to synchronize with your latest release.