save file as atext...using v.s 2003 !
-
i wanna to make aprogram that can draw (ellips , line,..) but i have problems with the save & open ..thats apart of the code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization; namespace graphics_practis { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Panel panel1; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button line; private System.Windows.Forms.Button square; private System.Windows.Forms.Button circle; private System.Windows.Forms.Button ellipse; private System.Windows.Forms.Button polygon; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button ok; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MenuItem menuItem5; private BinaryFormatter formtter = new BinaryFormatter(); private FileStream str_reader; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.Windows.Forms.OpenFileDialog openFileDialog1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // dr = new draw(this.pictureBox1); } static void Main() { Application.Run(new Form1()); } private void menuItem4_Click(object sender, System.EventArgs e) { //saving FileStream outStream=File.Create(saveFileDialog1.FileName);//To create text file Stream streamWriter=new StreamWriter(outStream); } private void menuItem3_Click(object sender, System.EventArgs e) { //opening FileStream outStream=File.Create(saveFileDialog1.FileName);//To create text file StreamWriter streamWriter=new StreamWriter(outStream); } the error...>>(cannot implicity convert type '
-
i wanna to make aprogram that can draw (ellips , line,..) but i have problems with the save & open ..thats apart of the code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization; namespace graphics_practis { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Panel panel1; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button line; private System.Windows.Forms.Button square; private System.Windows.Forms.Button circle; private System.Windows.Forms.Button ellipse; private System.Windows.Forms.Button polygon; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button ok; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MenuItem menuItem5; private BinaryFormatter formtter = new BinaryFormatter(); private FileStream str_reader; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.Windows.Forms.OpenFileDialog openFileDialog1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // dr = new draw(this.pictureBox1); } static void Main() { Application.Run(new Form1()); } private void menuItem4_Click(object sender, System.EventArgs e) { //saving FileStream outStream=File.Create(saveFileDialog1.FileName);//To create text file Stream streamWriter=new StreamWriter(outStream); } private void menuItem3_Click(object sender, System.EventArgs e) { //opening FileStream outStream=File.Create(saveFileDialog1.FileName);//To create text file StreamWriter streamWriter=new StreamWriter(outStream); } the error...>>(cannot implicity convert type '
Oh, you're using VS2003. Then WriteAllText is not an option.
mr jets wrote:
cannot implicity convert type 'System.IO.StreamWritet'to 'System.IO.Stream'.
You keep posting this, there's no such thing as StreamWritet, is this really not a typo ? System.IO.FileStream fs = new System.IO.FileStream("c:\\testing.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); // create a stream writer System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.ASCII); // write to file (buffer), where textbox1 is your text box sw.Write("text"); // flush buffer (so the text really goes into the file) sw.Flush(); // close stream writer and file sw.Close(); fs.Close(); Perhaps the defaults for the params you're not passing in, are not the ones you need ?
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 )
-
Oh, you're using VS2003. Then WriteAllText is not an option.
mr jets wrote:
cannot implicity convert type 'System.IO.StreamWritet'to 'System.IO.Stream'.
You keep posting this, there's no such thing as StreamWritet, is this really not a typo ? System.IO.FileStream fs = new System.IO.FileStream("c:\\testing.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); // create a stream writer System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.ASCII); // write to file (buffer), where textbox1 is your text box sw.Write("text"); // flush buffer (so the text really goes into the file) sw.Flush(); // close stream writer and file sw.Close(); fs.Close(); Perhaps the defaults for the params you're not passing in, are not the ones you need ?
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 )
i reaally appreciat ur time bro..okie ur code creating atext in c drive but it doesnt save the values of (x,y,..) remember bro my program like Paint ..so when i open the text it doesnt display my drawings (line,polygon,..) thats my open code : { OpenFileDialog fileChooser=new OpenFileDialog(); DialogResult result = fileChooser.ShowDialog(); String fileName ; // name of file to containing data // exit event handler if user clicked "cancel" if (result == DialogResult.Cancel) return; // get specified file name fileName= fileChooser.FileName; //show error if user specified invalid file if (fileName=="" || fileName==null) MessageBox.Show("Invalid File Name ","Error",MessageBoxButtons.OK,MessageBoxIcon.Error); else //creat Filestream to obtain read access to file input = new FileStream(fileName,FileMode.Open,FileAccess.Read); } Regards ;:sigh:
-
i reaally appreciat ur time bro..okie ur code creating atext in c drive but it doesnt save the values of (x,y,..) remember bro my program like Paint ..so when i open the text it doesnt display my drawings (line,polygon,..) thats my open code : { OpenFileDialog fileChooser=new OpenFileDialog(); DialogResult result = fileChooser.ShowDialog(); String fileName ; // name of file to containing data // exit event handler if user clicked "cancel" if (result == DialogResult.Cancel) return; // get specified file name fileName= fileChooser.FileName; //show error if user specified invalid file if (fileName=="" || fileName==null) MessageBox.Show("Invalid File Name ","Error",MessageBoxButtons.OK,MessageBoxIcon.Error); else //creat Filestream to obtain read access to file input = new FileStream(fileName,FileMode.Open,FileAccess.Read); } Regards ;:sigh:
I'm not sure that I understand. I see you opening a file stream, but I don't see you reading anything, nor does the fact that you read the text have anything to do with seeing polygons ( there's a step in the middle where the text is intepreted to give you the data to show that )
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 )
-
I'm not sure that I understand. I see you opening a file stream, but I don't see you reading anything, nor does the fact that you read the text have anything to do with seeing polygons ( there's a step in the middle where the text is intepreted to give you the data to show that )
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 )
-
thank god u back ..iam soo close to break my pc...u said (there's a step in the middle where the text is intepreted to give you the data to show that ) can u just tell me what that step..iam baggginngg Christian:doh: Regards ;
I have no idea. Reading a text file is NOT going to do anything more than put some text into a piece of memory. For that to turn into ellipses, or whatever, you need to write some code that does that. So, it depends. what is in this text file ? How did it get there ? How did you expect this text to become something on your screen ?
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 )