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. saving drawing as text file

saving drawing as text file

Scheduled Pinned Locked Moved C#
graphicshelpcss
6 Posts 4 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.
  • M Offline
    M Offline
    mr jets
    wrote on last edited by
    #1

    helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !

    C P 2 Replies Last reply
    0
    • M mr jets

      helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      mr jets wrote:

      for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1];

      This obviously writes each point except the first and last twice.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      M 1 Reply Last reply
      0
      • C Christian Graus

        mr jets wrote:

        for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1];

        This obviously writes each point except the first and last twice.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        M Offline
        M Offline
        mr jets
        wrote on last edited by
        #3

        hello my friend..i know it writes each point twice one for idicate the start ..and other indicate the last..but the problem is when i draw 2 shapes like line the squar ..it writes SQUAR WORD TWICE in the text file as: squar {X=151,Y=49}{X=281,Y=143} squar {X=55,Y=96}{X=157,Y=202}

        M 1 Reply Last reply
        0
        • M mr jets

          hello my friend..i know it writes each point twice one for idicate the start ..and other indicate the last..but the problem is when i draw 2 shapes like line the squar ..it writes SQUAR WORD TWICE in the text file as: squar {X=151,Y=49}{X=281,Y=143} squar {X=55,Y=96}{X=157,Y=202}

          M Offline
          M Offline
          Mark Greenwood
          wrote on last edited by
          #4

          Thats because your code looks like this for(int j=0;j { streamWriter.WriteLine("squar"); Move the streamWriter.WriteLine("squar"); outside of the for loop Plus I would be tempted to actually store this information as XML - that way you can process all of the LINE shapes or all of the SQUARE shapes just by a simple xpath query - otherwise you'll be doing a lot of manual string comparisons and conversions when you read the file back in..... e.g <shapes> <shape type="line> <points> <point x="100" y="100" /> <point x="200" y="100" /> <points> </shape> </shapes> -- modified at 2:34 Friday 11th May, 2007

          M 1 Reply Last reply
          0
          • M Mark Greenwood

            Thats because your code looks like this for(int j=0;j { streamWriter.WriteLine("squar"); Move the streamWriter.WriteLine("squar"); outside of the for loop Plus I would be tempted to actually store this information as XML - that way you can process all of the LINE shapes or all of the SQUARE shapes just by a simple xpath query - otherwise you'll be doing a lot of manual string comparisons and conversions when you read the file back in..... e.g <shapes> <shape type="line> <points> <point x="100" y="100" /> <point x="200" y="100" /> <points> </shape> </shapes> -- modified at 2:34 Friday 11th May, 2007

            M Offline
            M Offline
            mr jets
            wrote on last edited by
            #5

            ok i did that ..: if(drawwhat==1) { streamWriter.WriteLine("Line"); for(int j=0;j lessthan arraylist_points.Count;j++) { start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { streamWriter.WriteLine("squar"); for(int j=0;jlessthan arraylist_points.Count;j++) { start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } it will be saved in text file as : squar {X=131,Y=61}{X=265,Y=143} {X=68,Y=106}{X=146,Y=196} or u can recommend me ausfull article talkin about this..thats will be abetter idea..:sigh::confused: Regards:);

            1 Reply Last reply
            0
            • M mr jets

              helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              A basic rule of the forums is "Don't cross post". You have asked this question in other places as well. Please don't.

              Deja View - the feeling that you've seen this post before.

              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