MyWay
MyWay

Reputation: 1025

c# drawing on the panel and scrolling the result

I have problem with showing a diagram which is too big to see on one panel. I have to scrollbars which should change the point of view on the diagram, but when i want to scroll the picture, the shapes are moving on the different position, everything getting crushed.

it looks like this here link when i show it,and like this here link when i try to look on the bottom of the graph

it looks like application drawing the shapes every time when i scroll the panel, and when i go on the bottom of picture the point on the top left corner still is (0,0) not (0,500)

I have algorithm, which giving value of location on the panel and nr id of object to the array, then i have the loop which drawing it, getting info from dictionary about the object and his position from array.

How this problem can be solved ? Thx for any advice's

Edited I dont want to draw it again i want to draw one big graph, something like this(link in the comment), but i know that user can make for example 50 objects(shapes) and that kind of big graph cant be seen on the small panel so we have to have a chance to scroll and see the bottom of grapf, left side or this side which he want.

I'll try to give more details about application. When you lunch it, you see the control panel(form1), where you adding events/functions/xor/or every of this option have their own shape on the graph. So user adds for example event with text, pressing the button add which creates the object and adding it to the collection. He can adds events/functions,xor/or as many as he wants.

Ok, when he adds everything what he wanted, and now he would like to see graph so he pressing the button "generate the diagram", now the application is showing the next windwow with panel and scrollbars. You can see the window in links. In the second form after this line

private void panel1_Paint(object sender, PaintEventArgs e){

I have algorithm which is putting the coordinate values to table, then forech loop is taking from dictionary ( collection):

from arrays loop taking the coordinate values.

This how its work, I can also put a code in here when its needed.

Upvotes: 2

Views: 5233

Answers (2)

Hans Passant
Hans Passant

Reputation: 941635

The standard mistake is forgetting to offset your drawing by the scroll position. Use the panel's AutoScrollPosition property, like this:

    void panel1_Paint(object sender, PaintEventArgs e) {
        e.Graphics.TranslateTransform(panel1.AutoScrollPosition.X, panel1.AutoScrollPosition.Y);
        e.Graphics.DrawLine(Pens.Black, 0, 0, 300, 2000);
    }

The Panel control is in general pretty cranky about painting, it was designed to be a container control. You typically also want it double-buffered and to force a repaint when it is being resized. Setting the DoubleBuffered and ResizeRedraw properties requires deriving your own control from Panel.

Upvotes: 7

Odrai
Odrai

Reputation: 2353

It looks like application drawing the shapes every time when i scroll the panel

Why don't you erase the drawing area and draw the shapes again?

Maybe you can post a code snippet?

Upvotes: 0

Related Questions