Jump to content

Recommended Posts

Posted (edited)

Hi,

I'am creating a form using visual studio that is a Windows Form. People will fill out to fine people, I have the form created but struggling on the printing part, I can get the form to print but its as an image and you can see the whole window, since this will be a legal document it needs to be as good as it can be! What I'am wanting to do is just get the form to print out for example they fill the form out, they click print and it prints the filled out form with what they have typed in and the options they have chosen, in this case Yes or No, but not as an image, is that possible? I also don't want them to be able to print the form unless all the required questions are answered I have an error provider on the form already I just need to make that work with the print button.

Any help would be greatly appreciated!

 

Duke

Edited by lduke
Posted

My first thought would be to have the 'print' button generate an RTF/HTML file populated with the values you want, then print that. That'd be the simplest way I can think of to essentially add your own reporting routine to your system.

 

As for the error providers working with the print button, I'm assuming you're using the standard .Net Forms ErrorProvider class and that you're setting/clearing error text as necessary? If so, iterate through all your ErrorProvider objects and check their error contents (GetError); if they're all empty, you have no errors, so continue to printing.

  • Thanks 1
Posted
My first thought would be to have the 'print' button generate an RTF/HTML file populated with the values you want, then print that. That'd be the simplest way I can think of to essentially add your own reporting routine to your system.

 

As for the error providers working with the print button, I'm assuming you're using the standard .Net Forms ErrorProvider class and that you're setting/clearing error text as necessary? If so, iterate through all your ErrorProvider objects and check their error contents (GetError); if they're all empty, you have no errors, so continue to printing.

 

Thanks for the reply, i should have mentioned i don't know a great deal about .Net. How do i get the print button to generate an RTF/HTML file? Sorry I'm being a pain.

 

As for the ErroProvider yes I'am using the .Netforms class and basically its checking to see if the field or combobox is blank if it is then display what i have told it to, if not then clear the Error but how would i use and where would i use the GetError in the print procedure?

 

Thanks a million!

Posted (edited)
Thanks for the reply, i should have mentioned i don't know a great deal about .Net. How do i get the print button to generate an RTF/HTML file? Sorry I'm being a pain.

 

You'll want to look at how to write data to a file - I suggested RTF or HTML as they're plain text so relatively easy to generate on the fly, you just ouput the relevant tages where you want them. HTML is probably easiest, but you will of course need to know HTML too (a quick skim through w3schools tutorials will sort you out).

 

File Class (System.IO)

HTML Tutorial

 

As for the ErroProvider yes I'am using the .Netforms class and basically its checking to see if the field or combobox is blank if it is then display what i have told it to, if not then clear the Error but how would i use and where would i use the GetError in the print procedure?

 

Each ErrorProvider will be represented in your code as an object. If you coded the ErrorProviders, you'll already know their names, if not click on their icon in form designer then look for their name in the 'properties' window. You'll need to call errorProviderName.GetError() on each one and check if it's empty. Easiest way to do this in .NET is to use the String.IsNullOrEmpty method, i.e.

 

String.IsNullOrEmpty([i]errorProviderName[/i].GetError())

 

That will return True/False, which can be interpreted as there is/isn't an error. For simplicity's sake, you could shove the lot in one long 'if' statement within the print button's 'OnClick' method. Not sure whether you're using VB or C#, but in C# this would look something like:

 

if (String.IsNullOrEmpty(errorProvider1.GetError()) && String.IsNullOrEmpty(errorProvider2.GetError()) && String.IsNullOrEmpty(errorProvider3.GetError()))
{
   // you have no errors, so call your print method
} else {
   // there are some errors so don't print
}

Edited by LosOjos
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...