Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 28 Mar 2009 06:42:07 pm    Post subject:

I need help drawing in C#. How do I draw on a picture box that scrolls in a panel without the lines erasing?

So the layout is like this:

Panel component
Inside panel is PictureBox (allows a wider and taller picture than the form

When I draw lines on the picturebox they erase. How do I prevent this?
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 28 Mar 2009 09:56:02 pm    Post subject:

Handle the PictureBox's Paint event and draw your lines in there. The event should be called automatically, but you can force it by calling Invalidate on the PictureBox.

As an example, I dropped one Panel onto a form, named panel1. I set its AutoScroll property to true. I then dropped another Panel into it, named panel2, and added this event handler:

Code:
private void panel2_Paint(object sender, PaintEventArgs e) {
   e.Graphics.DrawLine(Pens.Black, 0, 0, 100, 100);
}
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 28 Mar 2009 10:01:29 pm    Post subject:

EDIT: Thanks a lot. I got it working. Appreciate your help.

Last edited by Guest on 28 Mar 2009 10:25:22 pm; edited 1 time in total
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 29 Mar 2009 10:24:56 am    Post subject:

I have one more question. Is it easy to get the mouse coordinates when it is in a panel box? I'm using the panel box to create a graph and I want when the mouse is over data on the graph to display what it is. So I guess what I need is to know how to get the specific coordinates in a panel box when the mouse is over it to display the relevant data.

Last edited by Guest on 29 Mar 2009 10:37:14 am; edited 1 time in total
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 29 Mar 2009 03:42:51 pm    Post subject:

You can get the current mouse position by handling the MouseMove event of the control.
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 31 Mar 2009 12:52:34 pm    Post subject:

How do I pass a multidimensional array to:


Code:
        private void pnlGraph_Paint(object sender, PaintEventArgs e)
        {
            int index = 0;

            while (index != 530)
            {
                e.Graphics.DrawLine(Pens.Black, 0, index, 1600, index);
                index = index + 10;
            }
        }
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 31 Mar 2009 03:43:18 pm    Post subject:

I'm afraid I don't follow what you mean; what are you using the array for?

Also, what's wrong with for loops? Wink

Code:
      private void pnlGraph_Paint(object sender, PaintEventArgs e)
      {
         for (int index = 0; index < 530; index += 10)
         {
            e.Graphics.DrawLine(Pens.Black, 0, index, 1600, index);
         }
      }
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 31 Mar 2009 04:27:08 pm    Post subject:

What I mean is I declared an array in another procedure ie a different button click and I need to pass those values to the paint procedure to use in order to draw on the screen.
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 31 Mar 2009 06:29:52 pm    Post subject:

You could store the array as a member field of the class that contains the event handler for the button click and panel paint.

Last edited by Guest on 31 Mar 2009 06:30:07 pm; edited 1 time in total
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 31 Mar 2009 06:44:56 pm    Post subject:

Can you give an example of that please?
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 31 Mar 2009 06:53:55 pm    Post subject:

I'm not sure what your code looks like at the moment!

Code:
class Form1 : Form {

   private int[,] SomeMultidimensionalArray = new int[10, 10];

   private void btnSomeButton_Click(object sender, EventArgs e) {
      // Manipulate the array in some fashion.
      this.SomeMultidimensionalArray[0, 2] = 102;
      // Force a repaint with the new data.
      this.pnlGraph.Invalidate();
   }

   private void pnlGraph_Paint(object sender, PaintEventArgs e) {
      // Paint using this.SomeMultidimensionalArray;
   }

}
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement