Groups | Blog | Home
all groups > dotnet drawing api > may 2005 >

dotnet drawing api : Using autoscroll


Steve Magoon
5/11/2005 12:00:00 AM
I would like to autoscroll objects as I select them (via hit testing),
separately, on a panel. In other words, if I select drawing (A) with the
mouse, then the autoscroll function would apply only to that object. Is this
possible with autoscroll, or is there a better way? I have several objects
that I'm drawing to a panel using a retained mode graphics method.

Thanks for your help,

Steve

Bob Powell [MVP]
5/12/2005 12:00:00 AM
Maybe I'm just feeling dense today. Can you explain what you want to do a
bit more consicely please.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]

Bob Powell [MVP]
5/12/2005 12:00:00 AM
If you want to move object A then the process is the same as normal, select
the object and move it according to the mouse values. If you want it to
remain visible while being moved regardless of it's position then you could
update the window's auto-scroll positions to ensure that the object was in
the viewing area.

This will be handled by your own particular brand of drawing canvas
interpretation. Without knowing what that code is doing I will be unable to
make a suggestion.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]

Scott McChesney
5/12/2005 9:38:27 AM
Steve -

If I understand what you're wanting to do, you want to be able to
selectively scroll objects within your panel, taking advantage of the
AutoScroll capabilities. For example:

You have three objects in the panel - A, B, and C. If you select A and
scroll the panel, you *only* want A to scroll - B and C should retain their
positions.

If I have it right, I believe it is possible. From my way of thinking,
you'll have to store which objects are selected, and then in your Paint
event, you'll have to "undo" the scroll translation on all unselected
objects. That way, they should remain in their current position, while all
others scroll as appropriate.

If you're using a retained-mode system, probably the best thing to do (if
you aren't already) is to store the transformation to apply within each
object. That way, you could apply the appropriate translations (scrolling
or otherwise) to each object - in this case, you would only apply the
scrolling translation to the selected objects. That would provide the best
control over object placement. I don't think the Panel control provides a
Scroll event, but you could apply the scrolling translation in your Paint
event before you actually draw each object.

I'm not nearly the GDI+ expert that Bob is, so he may have a better
solution. But this is how I'd tackle the problem.

HTH

- Scott

[quoted text, click to view]

Steve Magoon
5/12/2005 12:40:20 PM
[quoted text, click to view]


Yah, you're right. I didn't explain myself very clearly; thanks for the
'translation'. I have three objects drawn into a panel. I want to scroll one
of them without affecting the others. Each object has its own Matrix and
Properties that I can change. I'm wondering if it's possible to do this on a
panel using its autoscroll properties, or should I try scrolling individual
objects with a scroll bar from the tool box?

I hope this makes more sense.

Thanks for helping this novice!

Steve



[quoted text, click to view]

Scott McChesney
5/12/2005 1:29:00 PM
You can certainly use the AutoScroll capabilities of the Panel control to do
what you want, and it sounds like you're already set up to handle it. The
thing you have to realize is that, as far as drawing graphic objects is
concerned, you still have to write code for the AutoScroll to do anything
for you, unless you have a panel contained within your scrolling panel that
you actually draw on (and size to fit your entire canvas.) Given your
retained-mode object model, I wouldn't recommend that method, since
enclosing a panel object within another kinda defeats the purpose of your
object model, and makes solving this problem REALLY hard.

Any .NET controls contained within the panel will be scrolled for you, but
anything you draw will have to be managed by the Paint event of your Panel,
using the translate methods of each object's Matrix in order to get the
right position. In case you haven't yet, check out the "AutoScrollMinSize",
"AutoScrollMargin", and "AutoScrollPosition" properties to see how to get
everything working. It's not hard to do, but like I said, in order to
actually get your graphics to scroll with the scrollbar, you'll have to
write some translation code within your Paint event. However, given that
each object already has its own Matrix property, it should be relatively
simple to add the scrolling translation to each selected object's Matrix
before drawing them. Doing that should ensure that your non-selected
objects don't go anywhere.

If you need a "push" to get you started, Bob Powell's GDI+ FAQ is about the
best out there right now. In fact, he's got an article that explains the
basics of AutoScroll and graphics operations:

http://www.bobpowell.net/understanding_autoscroll.htm

He also has an article discussing retained-mode graphics systems, and there
is some MSDN information on that available as well.

You're also going to want to investigate the Begin/EndContainer methods, if
you haven't already. Given that each object has its own Matrix, each object
can be transformed/translated independently within the canvas. That almost
requires Begin/EndContainer use, so that you can isolate the translations
appropriately. Each object needs to start from a consistent translation
state, and the easiest one is the identity matrix (no translation), since
that's how your Graphics object will be when you enter your Paint event.
Using the Begin/EndContainer methods will let you to isolate your
transformation to the specific object you're drawing, and reset the Graphics
object before you draw your next one. If you don't do it that way, then you
will probably never get it to work right.

Of course, depending on where your retained-mode graphics system came from,
this might all be handled for you, so it's certainly something to
investigate before you go writing a bunch of code. If you developed it from
scratch, then you'll have to deal with all of this. If you got it from
somewhere else, it may already manage some or all of this for you.

HTH

- Scott

[quoted text, click to view]

Steve Magoon
5/13/2005 12:00:00 AM
[quoted text, click to view]

What if I don't want object A to move at all when I move the scroll box? How
would I set up object A's matrix so that it will *not* move on the panel,
while other objects on the panel do, when I move the scroll box?

Thanks for your help,

Steve

Bob Powell [MVP]
5/13/2005 12:00:00 AM
Each object will create it's own matrix from it's scale, rotate, translate
parameters. take a look at the animation example on my site...You would
benefit from the following algorithm...

Save Graphics using BeginContainer
Scale
Rotate
Translate
Draw
Restore Graphics using EndContainer

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]

Steve Magoon
5/13/2005 8:31:36 PM
Thanks Bob. In your Animation program (very cool BTW) posted on your web
site, is BeginContainer an actual method or is it a name you give for
SetupTransform {...}?

Steve



[quoted text, click to view]

Bob Powell [MVP]
5/14/2005 12:00:00 AM
Graphics.BeginContainer

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]

James Westgate
5/14/2005 12:00:00 AM
In a nutshell, offset your primitive by the Control.DisplayRectangle
property, manually , or by using a matrix.

James

--
Create interactive diagrams and flowcharts with ERM Diagram at
http://www.crainiate.net

Take the ERM Tour at http://www.flowchartcontrol.com


[quoted text, click to view]

AddThis Social Bookmark Button