spelger

hi,

if i have a form that has the AutoScroll property set to true and i have a control on the form that is located at say (-10, 10) then shouldn't i get a horizontal scroll bar

i don't and i am wondering how i can get it aside from implementing scrolling by myself.

thanks,
scott


Re: Windows Forms General AutoScroll question

nobugz

Hmm, that wouldn't be necessary, scrolling is relative. If you locate it at (0, 10) and set the AutoScrollMinSize to (ClientSize.Width + 10, 0), you could always scroll it to (-10, 10)...





Re: Windows Forms General AutoScroll question

spelger

thanks,

i am not sure that would work. i am trying to manipulate virtual controls on a UserControl. the controls are rendered in an image. to take advantage of the AutoScroll feature i place only two Panel objects in the UserControl, one at (0, 0) and the other at (x, y) where x == the bottom of the bottom most virtual object, and y == ...

what i need is to be able to allow the user to move one of these virtual objects further to the left and have the UserControl show the scroll bars. this works, but only when i move an item to the right.

this approach is taken to support zooming, a large number of custom (hand drawn) objects, and flicker free rendering.

thanks,
scott




Re: Windows Forms General AutoScroll question

nobugz

Sorry, it's confusing to me what you're trying to accomplish and why you would use two panels. Just set the AutoScrollMinSize property to a value larger than the UserControl's size and the scrollbars will automatically appear. If you are using the Paint event to render your "virtual objects", offset the coordinates of those objects by AutoScrollPosition. And write a Scroll event handler that just calls Invalidate() to force the control to repaint itself when the user uses the scroll bars. Here's a simple example:

public partial class UserControl1 : UserControl {
public UserControl1() {
InitializeComponent();
this.AutoScroll = true;
this.AutoScrollMinSize = new Size(2 * this.Width, 2 * this.Height);
this.Scroll += RepaintOnScroll;
this.Paint += PaintSample;
}
private void PaintSample(object sender, PaintEventArgs e) {
Point p1 = new Point(0, 0);
Point p2 = new Point(this.Width, this.Width);
p1.Offset(this.AutoScrollPosition);
p2.Offset(this.AutoScrollPosition);
e.Graphics.DrawLine(Pens.Black, p1, p2);
}
private void RepaintOnScroll(object sender, ScrollEventArgs e) {
this.Invalidate();
}
}






Re: Windows Forms General AutoScroll question

spelger

thanks nobugz,

i the use of the panels was to get the scroll bars to appear. i later saw the min scroll size as you indicated.

and i do understand what you showed me. unfortunately, it will not be so simple as offsetting all of the virtual objects. certain objects being moved can have an effect on others and is costly if many are moved, there are lots of hand calculated beziers, weird regions and paths being used.

i have a nearly working solution going right now using manual scroll (if you can call it that).

thanks,
scott




Re: Windows Forms General AutoScroll question

nobugz

You can make that easy by offsetting the origin of the Graphics coordinate system. For example:

private void PaintSample(object sender, PaintEventArgs e) {
Point p1 = new Point(0, 0);
Point p2 = new Point(this.Width, this.Width);
e.Graphics.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
e.Graphics.DrawLine(Pens.Black, p1, p2);
}






Re: Windows Forms General AutoScroll question

spelger

hmmm,

that might work. on the surface at least it sounds viable. i will have to think about that. it is simpler than what i have worked out now, sometimes simpler does work.

thanks a bunch,
scott