Results 1 to 6 of 6

Thread: Need some help please :)

  1. #1
    Senior Member kasavien's Avatar
    Join Date
    Aug 2005
    Location
    St. Albans
    Posts
    1,829
    Thanks
    145
    Thanked
    104 times in 49 posts

    Need some help please :)

    Hi i have the piece of code below which is supposed to draw lines, it isn't complete but should at least draw lines between the points in _currentLinks

    Code:
            protected override void OnPaint(PaintEventArgs e)
            {
                Graphics graphics = e.Graphics;
                drawNetwork(graphics, this.Width, this.Height);
            }
    
            private void drawNetwork(Graphics graphics, int width, int height)
            {
                if (this._currentNodes.Count > 0)
                {
                    foreach (Node node in this._currentNodes)
                    { 
                    
                    }
                }
                if (this._currentLinks.Count > 0)
                {
                    foreach (Link link in this._currentLinks)
                    {
                        Pen linkPen = new Pen(Color.Blue);
                        linkPen.Width = 5;
                        graphics.DrawLine(linkPen, link.start, link.end);
                        linkPen.Dispose();
                    }
                }
            }
    The problem is it doesn't draw anything, i've debugged it as best i know how and it goes through each of the "link"s in "_currentLinks" and goes through the drawline part but nothing appears on screen. Is there something obvious that i have missed. If someone can help i'd be very grateful!

    Many thanks

    Andy

    edit: i aren't using width and height yet, they're there for future use at the moment

  2. #2
    Flower Child stytagm's Avatar
    Join Date
    Aug 2004
    Location
    London
    Posts
    754
    Thanks
    47
    Thanked
    23 times in 18 posts

    Re: Need some help please :)

    Does the draw function work if you simplify it? Ie, get rid of the loops, and try and get the Draw statement working with some hard coded coords. Then slowly build the other functionality back in.

    PS what language is this? C#? Java?
    They told me I was gullible ... and I believed them.

  3. #3
    Senior Member kasavien's Avatar
    Join Date
    Aug 2005
    Location
    St. Albans
    Posts
    1,829
    Thanks
    145
    Thanked
    104 times in 49 posts

    Re: Need some help please :)

    Sorry yeah forgot to say, it's written in c#, if i call the draw function from somewhere else it works and draws the lines correctly. The only thing i can think that it might be is that it's not drawing on the correct surface.

    edit: or could i be drawing it on the correct surface just not within the right bounds, i've tried to check this through debugging and it doesn't appear to be the case since the coordinates it's drawing seem to be less than the width and height.
    Last edited by kasavien; 12-02-2008 at 09:43 PM.

  4. #4
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Need some help please :)

    C#, the dispose is the give away!

    look at using. Always use using, as it stands any exceptions can cause leaks. ie
    Code:
    using (Pen pen = new Pen(Color.Blue) {
    //.... use the pen obj here ....
    }// the .Dispose is automatically closed, even if an exception occurs
    there is also no point doing the .Count > 0 bit, as foreach will gracefully simply not run if there is nothing to enumerate. (as long as its not null, but .Count would cause the same nullreferenceexception).

    so, odds are the values in the links collection are wrong, breakpoint on the drawline, and have a look at the co-ords been used.

    either that or post the required code.
    throw new ArgumentException (String, String, Exception)

  5. Received thanks from:

    kasavien (14-02-2008)

  6. #5
    Senior Member kasavien's Avatar
    Join Date
    Aug 2005
    Location
    St. Albans
    Posts
    1,829
    Thanks
    145
    Thanked
    104 times in 49 posts

    Re: Need some help please :)

    Hi, thanks for all your help, i sorted it in the end. I noticed that when i minimised and restored the screen the points were being drawn, so as it turned out i needed to refresh the screen after a draw. I also changed my code to start using the "using" keyword as TheAnimus suggested.

    Thanks

    Andy

  7. #6
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Need some help please :)

    Well I was going to suggest that, followed by 'is the background blue'?
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •