I put a GoSheet on the Goview to mimic a page.
I want the following behavour:
1. When one dimesion of the sheet is larger than the dimension of the view, the corresponding scrollbar should appear and the scroll range should be only the length of the sheet.
2. When one of the dimesion of the seet is smaller than the dimesion of the view, the corresponding scrollbar should disapear and the sheet should be position in the middle in that dimesion.
For example, if the sheet's height is larger than the view's height, the vertical scrollbar should appear so that the use can scroll vertically. If the sheet's height is shorter than the view's height, the vertical scrollbar should disappear and the user cannot scroll can the sheet is position centered vertically.
If both the height and width of the sheet is smaller than the view's height and width, both the scroll bars should disappear and the sheet should always stay in the center of the view.
Could you give me some ideas or clear me of the following relationships:
GoSheet position and GoView.DocPosition
GoSheet Bounds and Document.Bounds
It would be of great help if you can provide some sample code.
OK, I did it.
I also replaced the scrollbars with devexpress ones and they are auto-hidden based on the sheet size and the view size.
If someone else wants the similiar, this code may be of help.
public override PointF LimitDocPosition(PointF p)
{
PointF basePt = base.LimitDocPosition(p);
if (Sheet != null)
{
if (RightBar == null)
{
basePt.Y = (Sheet.Height * DocScale - DisplayRectangle.Height) / DocScale / 2;
}
else
{
if (basePt.Y < 0)
{
basePt.Y = 0;
}
else
{
float maxY = Sheet.Height - DisplayRectangle.Height / DocScale;
if (basePt.Y > maxY)
{
basePt.Y = maxY;
}
}
}
if (BottomBar == null)
{
basePt.X = (Sheet.Width * DocScale - DisplayRectangle.Width) / DocScale / 2;
}
else
{
if (basePt.X < 0)
{
basePt.X = 0;
}
else
{
float maxX = Sheet.Width - DisplayRectangle.Width / DocScale;
if (basePt.X > maxX)
{
basePt.X = maxX;
}
}
}
}
return basePt;
}
protected override void OnPropertyChanged(PropertyChangedEventArgs evt)
{
base.OnPropertyChanged(evt);
if (evt.PropertyName == "DocPosition" || evt.PropertyName == "DocScale")
{
if (hScrollBar == null || vScrollBar == null)
{
return;
}
float clientDocWidth = (DisplayRectangle.Width) / DocScale;
float clientDocHeight = (DisplayRectangle.Height) / DocScale;
hScrollBar.Minimum = 0;
hScrollBar.Maximum = (int)(Sheet.Width - clientDocWidth) + hScrollBar.LargeChange;
if (clientDocWidth >= Sheet.Width)
{
BottomBar = null;
}
else
{
if (DocPosition.X < 0)
{
hScrollBar.Value = 0;
}
else if (DocPosition.X > hScrollBar.Maximum)
{
hScrollBar.Value = hScrollBar.Maximum;
}
else
{
hScrollBar.Value = (int)DocPosition.X;
}
BottomBar = hScrollBar;
}
vScrollBar.Minimum = 0;
vScrollBar.Maximum = (int)(Sheet.Height - clientDocHeight) + vScrollBar.LargeChange;
if (clientDocHeight >= Sheet.Height)
{
RightBar = null;
}
else
{
if (DocPosition.Y < 0)
{
vScrollBar.Value = 0;
}
else if (DocPosition.Y > vScrollBar.Maximum)
{
vScrollBar.Value = vScrollBar.Maximum;
}
else
{
vScrollBar.Value = (int)DocPosition.Y;
}
RightBar = vScrollBar;
}
}
}