.net framework text generator

Started by
4 comments, last by speed258 9 years, 6 months ago

hi guys i'am new in this forum and i creating software which genarates text and print with printer so basicly i'am new with framework so i'd like to see some examples,how to generate my custom text and get some strings from user input and put in the text so after that i can print with my own printer, thanks for suggestions.

Advertisement
So you want to create a console application that reads user input and prints it to physical paper using a printer?

Yes

So you want to create a console application that reads user input and prints it to physical paper using a printer?

Exactly

Well, this is a game developer forum, but fine. I'm at work now, so this is a hackish solution, but it should work.

Please note that printing in Windows is complicated, so you'd better leave the job to some other control/tool.

The quickest and easiest way to print in Windows (generally) is to create a text file, then launch Notepad and tell it to print the file. This is not a perfect solution, but since you ask the question, I guess you need a quick solution.

  • Console.ReadLine() can read text from the console
  • File.WriteAllText() will write any string to a file
  • Process.Start() will launch an external program

To start Notepad in "printing" mode, you just do Process.Start(string.Format("notepad /p {0}", filename)), where filename is a variable that holds the file name.

In order to print text via API in Windows, you usually use a printing DC. You'll usually use a WinForms app to do that, as WinForms has nice wrappers for Win32. Here is a quick example on how to do that:

http://msdn.microsoft.com/en-us/library/aa287530(v=vs.71).aspx

.Net has a lot nicer printing support than Win32 did.

Here's another example of just printing text from a file:

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.print(v=vs.110).aspx

You can obviously get the text from anywhere - it doesn't need to be a file. Your program can ask the user to type it in.

If you want to draw other things, like lines, boxes, etc - you can do that as well. Instead of "DrawString" just use the various other "Draw*" methods.

.Net has a lot nicer printing support than Win32 did.

Here's another example of just printing text from a file:

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.print(v=vs.110).aspx

You can obviously get the text from anywhere - it doesn't need to be a file. Your program can ask the user to type it in.

If you want to draw other things, like lines, boxes, etc - you can do that as well. Instead of "DrawString" just use the various other "Draw*" methods.

okey so i got it but if my text is "Hello my name is: "string"" predefined text would readed from file but "string" input user, and that "string" would be with bold effect, i actually didnt learned about formating text with effects, and how about detecting from user pc is really connected to printer not virtual one, printer is connected with cable not bluetooh or remote connection systems.

P.S Never mind i found about printers. Thanks.

P.S.S hey not creating another topic maybe you have guys working mysql system for framework, because on internet i couldnt find working one.

This topic is closed to new replies.

Advertisement