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.
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
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
Thank you very much for the awesome work!
The issue was fixed successfully.
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;
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
Thank you for looking into this issue.
I am using SVN to synchronize with your latest release.