Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. AddRectangle Exception

AddRectangle Exception

Scheduled Pinned Locked Moved C#
graphicshelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gwithey
    wrote on last edited by
    #1

    Hi i seem to be getting an argumentException on the indicated line for no reason that i can see. There is a perameter not valid message however it is, as i create the rectangle and add it straight away.

        // Add two rectangles to graphics path
        Rectangle rectangle = new Rectangle(5, 5, 10, 10);
    
        // Create two rectangles representing the node and expand box
        Rectangle textBacking = new Rectangle(m\_expandBox.Width + (m\_gap \* 2),
        m\_gap - (int)(m\_gap \* 0.5), Size.Width - m\_gap, Size.Height - m\_gap);
    

    -----> m_gpExpandBox.AddRectangle(rectangle);
    m_gpTextBacking.AddRectangle(textBacking);

    Does anyone know why this is happening. I cannot see any information on the net that would reveal the cause of the problem. Thanx George

    OriginalGriffO 1 Reply Last reply
    0
    • G gwithey

      Hi i seem to be getting an argumentException on the indicated line for no reason that i can see. There is a perameter not valid message however it is, as i create the rectangle and add it straight away.

          // Add two rectangles to graphics path
          Rectangle rectangle = new Rectangle(5, 5, 10, 10);
      
          // Create two rectangles representing the node and expand box
          Rectangle textBacking = new Rectangle(m\_expandBox.Width + (m\_gap \* 2),
          m\_gap - (int)(m\_gap \* 0.5), Size.Width - m\_gap, Size.Height - m\_gap);
      

      -----> m_gpExpandBox.AddRectangle(rectangle);
      m_gpTextBacking.AddRectangle(textBacking);

      Does anyone know why this is happening. I cannot see any information on the net that would reveal the cause of the problem. Thanx George

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      We would probably need to know more about whatever m_gpExpandBox is, and what it's AddRectangle method is declared as.

      If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      G 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        We would probably need to know more about whatever m_gpExpandBox is, and what it's AddRectangle method is declared as.

        If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

        G Offline
        G Offline
        gwithey
        wrote on last edited by
        #3

        Yep thats kwl: GraphicsPath.AddRectangle(); (standard method .net) Takes a rectangle as perameter and adds it to graphics path

        private GraphicsPath m_gpExpandBox; // Represents the box for the expand and contract

          public Node(string name)
          {
             // Set the name of this node
             m\_name = name;
        
             // Create objects
             m\_childNodes = new List<Node>();
        

        -----> m_gpExpandBox = new GraphicsPath();
        m_gpTextBacking = new GraphicsPath();
        m_fontLocation = new Point(0, 0);

             // Set size and location of the node
             m\_size = new Size(60, 20);
             m\_location = new Point(0, 0);
          }
        

        There is too much code to include every reference to m_gpExpandBox. It is a graphics path i add to in order to draw an expansion box on a node of a tree view control. Do you think this could be a cause of the problem even though it complains of an invalid perameter. Thanx George

        OriginalGriffO 1 Reply Last reply
        0
        • G gwithey

          Yep thats kwl: GraphicsPath.AddRectangle(); (standard method .net) Takes a rectangle as perameter and adds it to graphics path

          private GraphicsPath m_gpExpandBox; // Represents the box for the expand and contract

            public Node(string name)
            {
               // Set the name of this node
               m\_name = name;
          
               // Create objects
               m\_childNodes = new List<Node>();
          

          -----> m_gpExpandBox = new GraphicsPath();
          m_gpTextBacking = new GraphicsPath();
          m_fontLocation = new Point(0, 0);

               // Set size and location of the node
               m\_size = new Size(60, 20);
               m\_location = new Point(0, 0);
            }
          

          There is too much code to include every reference to m_gpExpandBox. It is a graphics path i add to in order to draw an expansion box on a node of a tree view control. Do you think this could be a cause of the problem even though it complains of an invalid perameter. Thanx George

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          My bad - I missed the hungarian notation and GraphicsPath reference.

          gwithey wrote:

          Do you think this could be a cause of the problem even though it complains of an invalid perameter.

          Don't know - have you stuck a breakpoint on and looked at the actual values of the rectangle?

          If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          G 2 Replies Last reply
          0
          • OriginalGriffO OriginalGriff

            My bad - I missed the hungarian notation and GraphicsPath reference.

            gwithey wrote:

            Do you think this could be a cause of the problem even though it complains of an invalid perameter.

            Don't know - have you stuck a breakpoint on and looked at the actual values of the rectangle?

            If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

            G Offline
            G Offline
            gwithey
            wrote on last edited by
            #5

            Yes i think it may be related to the graphics path as all its variables have an exception before the line in question is reached. I will have to try and find where it is going wrong. Thanx George

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              My bad - I missed the hungarian notation and GraphicsPath reference.

              gwithey wrote:

              Do you think this could be a cause of the problem even though it complains of an invalid perameter.

              Don't know - have you stuck a breakpoint on and looked at the actual values of the rectangle?

              If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

              G Offline
              G Offline
              gwithey
              wrote on last edited by
              #6

              public int Draw(Graphics g)
              {
              DrawNode();

                   // Create font for text
                   Font nodeFont = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular);
              
                   // Fill node if selected
                   if (m\_selected)
                   {
                      g.FillPath(Brushes.Red, m\_gpTextBacking);
                      g.DrawString(m\_name, nodeFont, Brushes.White, m\_fontLocation);
                   }
                   else
                   {
                      g.DrawString(m\_name, nodeFont, Brushes.Black, m\_fontLocation);
                   }
                   
                   // Draw node backing if hover is true
                   if (m\_hover)
                   {
                      g.DrawPath(Pens.Black, m\_gpTextBacking);
                   }
              
                   // Draw expand box
                   g.FillPath(Brushes.Gray, m\_gpExpandBox);
                   g.DrawPath(Pens.Black, m\_gpExpandBox);
              
                   // Dispose of graphics paths
              

              ------> //m_gpExpandBox.Dispose();
              ------> //m_gpTextBacking.Dispose();

              Thank you for the help found the soulution. It now works when comment out the indicated lines

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups