Click here to Skip to main content
15,889,335 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help ploting Excel graph in C# Pin
Mc_Topaz31-May-10 1:10
Mc_Topaz31-May-10 1:10 
GeneralRe: Help ploting Excel graph in C# Pin
Henry Minute31-May-10 1:23
Henry Minute31-May-10 1:23 
GeneralRe: Help ploting Excel graph in C# Pin
Mc_Topaz31-May-10 2:29
Mc_Topaz31-May-10 2:29 
GeneralRe: Help ploting Excel graph in C# Pin
Henry Minute31-May-10 2:51
Henry Minute31-May-10 2:51 
Questiondarw rectangle modification.... [modified] Pin
Nivas8230-May-10 22:42
Nivas8230-May-10 22:42 
AnswerRe: darw rectangle modification.... Pin
OriginalGriff30-May-10 23:00
mveOriginalGriff30-May-10 23:00 
GeneralRe: darw rectangle modification.... Pin
Nivas8231-May-10 18:53
Nivas8231-May-10 18:53 
GeneralRe: darw rectangle modification.... Pin
OriginalGriff31-May-10 22:13
mveOriginalGriff31-May-10 22:13 
Ok, loads of things. Lets start with the simple stuff. Ignoring your drawing for the moment, your rectangle array has probably got problems. I can't see where you have defined it, or count, but I see nowhere where you change the value of count, so you would be over-writing the same rectangle. Unless you know in advance how many times teh use is going to click on your picture box, don't use an array - they are a fixed size. Use a List<Rectangle> instead:
List<Rectangle> rectangles = new List<Rectangle>();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
   {
   rectangles.Add(new Rectangle(0, 0, e.X, e.Y));
   }
This adds a new rectangle to your list every time the user clicks the picture box. Note that I have changed the parameters for the rectangle to give it a width and height, which yours lacked!
Changing to a List will almost certainly get rid of your "Object reference not set..." error.

The next bit involves your drawing: You draw in the PictureBox.Paint event, but this may be a problem all on it's own. Your bitmap is persistent: changes you make to it are not lost. The paint event is there because the screen is not persistent - whenever it is invalidated, it must be re-drawn. When you draw on your bitmap in the Paint event, you are drawing again, and again, and again on the same bitmap that you drew on last time! Am I also right in thinking that your PictureBox control also displays the bitmap? If so, why are you handlign Paint yourself? If not, why are you using a PictureBox?

Instead, draw onto your bitmap when you add the rectangle to the list. If you need to handle the Paint event, either draw each rectangle onto the graphics context provided (e.Graphics) using a foreach loop to process each Rectangle in the list, or draw the bitmap to the graphics context provided.

Well done on putting using blocks round your Graphics and Pen items though!Thumbs Up | :thumbsup:
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

GeneralRe: darw rectangle modification.... Pin
Nivas821-Jun-10 22:17
Nivas821-Jun-10 22:17 
GeneralRe: darw rectangle modification.... Pin
OriginalGriff1-Jun-10 22:59
mveOriginalGriff1-Jun-10 22:59 
AnswerRe: darw rectangle modification.... [modified] Pin
Nivas822-Jun-10 19:18
Nivas822-Jun-10 19:18 
GeneralRe: darw rectangle modification.... Pin
Nivas827-Jun-10 21:39
Nivas827-Jun-10 21:39 
AnswerRe: darw rectangle modification.... Pin
Luc Pattyn31-May-10 1:57
sitebuilderLuc Pattyn31-May-10 1:57 
GeneralRe: darw rectangle modification.... Pin
Nivas8231-May-10 19:02
Nivas8231-May-10 19:02 
GeneralRe: darw rectangle modification.... Pin
Luc Pattyn1-Jun-10 1:48
sitebuilderLuc Pattyn1-Jun-10 1:48 
QuestionA Question Of Focus and Tab Indices [Solved] Pin
Roger Wright30-May-10 22:20
professionalRoger Wright30-May-10 22:20 
AnswerRe: A Question Of Focus and Tab Indices Pin
Henry Minute30-May-10 23:10
Henry Minute30-May-10 23:10 
GeneralRe: A Question Of Focus and Tab Indices [modified] Pin
Roger Wright30-May-10 23:20
professionalRoger Wright30-May-10 23:20 
GeneralRe: A Question Of Focus and Tab Indices Pin
OriginalGriff30-May-10 23:27
mveOriginalGriff30-May-10 23:27 
GeneralRe: A Question Of Focus and Tab Indices Pin
Henry Minute30-May-10 23:30
Henry Minute30-May-10 23:30 
GeneralRe: A Question Of Focus and Tab Indices Pin
Luc Pattyn31-May-10 2:02
sitebuilderLuc Pattyn31-May-10 2:02 
Questiondeclare string[] Pin
jojoba201130-May-10 20:31
jojoba201130-May-10 20:31 
AnswerRe: declare string[] Pin
Vikram A Punathambekar30-May-10 20:34
Vikram A Punathambekar30-May-10 20:34 
AnswerRe: declare string[] Pin
Abhinav S30-May-10 20:43
Abhinav S30-May-10 20:43 
QuestionRe: declare string[] Pin
jojoba201130-May-10 20:52
jojoba201130-May-10 20:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.