I'm writting a simple Windows Forms aplication and I have a 'textBox1' with some simple text. The task is to create a menu button which, when clicked, saves all the 'textBox1' content to a new file USING A DIALOG. I suppose it should be done using 'PrintDialog', but how to do it ?
I'm a beginner to Windows Forms :), so thanks for your patience.
You create a method for the button, then in that method you use a CFileDialog http://msdn.microsoft.com/en-US/library/dk77e5e7(v=vs.80).aspx to open/create a new file to save the content of your text box.
You open the file with either ofstream(std) or CFile, and use the apropriate methots for adding the text from the textBox to the file.
If you use a multiline textbox(Assuming its CEdit) you use a for loop based on CEdit::GetLineCount - returns the number of lines
No, I'm not using MFC... I only use Windows Forms Applications in Visual Studio 2010. To be honest, I don't even know what MFC is. I only need to make this printing of the textBox1 and that will be the end of my Windows Forms adventure, I'm planning to start programming using Qt.
But I can't deal with this printing, nothing in the web about this...
Ok, I've forgotten to mention it visibly - I'm using C++. I thought, that if this page names cplusplus it's clear, that I'm making code with C++ :P.
So, as I consider, plain C is not appropriate choice here...
I'm also using some Open/Save file methods in my app, but I'm using a OpenFileDialog and SaveFileDialog for this and it works ok (I mean saving textBox1 content do txt file and load txt file content and place it into textBox1).
.NET, exactly. Yes, I know, but it's an university task and I have to use C++ only.
I've found something like that (it's in Polish, doesn't matter, the code is most important) -> http://patryknet.blogspot.com/2009/11/drukowanie.html but, as I suppose that's for C#, not C++.
I've written such a code -> http://pastebin.com/X7vaKNpv
The idea was to copy the textBox1's content to the String^ and then send it to the printer.
Using the code above, after clicking button6 printer choosing window opens normally, but, after choosing it the MessageBox with "OK" appears and then the application crashes.
Try and put a break point at the beginning of the button6_Click and document_PrintPage functions and us step into until the program crashes. Note at what line it crashes.
Also if it's not to much you could upload the entire project someware and put the link here and i will try and make a debug when i get home(hope i get the time :)) )
You are right, the 2 lines of code are responsible for printing.In this type of situations is best to try and check if your string really have the values you want. Try and output the value of text either in a label or in a message box.
Also i thing it would be better to use the ToString method, rather then Text(might be wrong though, i think i am not checking the right class :)) ).