简体   繁体   中英

Is List<GraphicsPath> possible in C#?

I'm trying to use a list of GraphicsPath instead of an array as I don't know the number of the paths that will be created by user.

List<GraphicsPath> PathDB = new List<GraphicsPath>();

After this I fill the List as follows:

using(GraphicsPath myPath = new GraphicsPath())
{
   myPath.AddPolygon(myPoints);
   PathDB.Add(myPath);
}

But when I try to use the GraphicsPath from the list, while the Count property is correct, I cannot use the object like below because of an argument exception.

num = PathDB.Count;
for(int k=0; k < num; k++)
   {
      using(GraphicsPath myCurrentPath = new GraphicsPath())
      {
         myCurrentPath = PathDB[k];
         myCurrentPath.AddLine(0,0,400,400); //at this stage exception is thrown 
         myGraphics.DrawPath(myPen, myCurrentPath)
      }
   }

Is it something related to GraphicsPath being Disposabe ?? Or doing smt wrong?

using(GraphicsPath myPath = new GraphicsPath())
{
   myPath.AddPolygon(myPoints);
   PathDB.Add(myPath);
} // this disposes myPath

This is a local graphics path. Your using block Dispose s it after the scope if done. So you need to remove that using block and instead dispose your paths when you no longer need them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM