Another year has gone by and some things don't change. That's right, paying taxes. What has changed over the years is that taxes have become more and more complicated. If you've ever looked at the 1040 Form, the 1099, the W-2, the Schedule A, B, C and the rest of the alphabet, you probably found yourself wondering which is worse: paying the money to the government or filling out the paperwork. A few years ago, the government heard the cry of the citizen who was up to his neck in forms and tried to ease the process of filing the 1040 by creating the 1040EZ form. This form, which is miraculously only a single page, is a lot less painful than its descendant the 1040. Of course if you are able to take advantage of any of the tax benefits the government provides (such as deductions), you'll need to file the old dependable, but tedious 1040.
Figure 1 - 1040EZ Form Application
Since the 1040EZ form is only a single page, I thought it would be fun to create a Window Form application that helped you to type into the form. This program will allow you to fill out most of the fields and perform the calculations on certain fields as well. The application also allows you to print the form, print preview the form, open an existing form, and save your current 1040EZ Form. This article is similar to a previous article I wrote on Printing out a W-2 Form. The program in this current article is slightly improved in that it allows you to scroll through the form by setting the AutoScroll property of the form to true. This program is also more generic. Except for the specific calculations for the 1040EZ form, all the drawing, printing and saving of information is done by simply cycling through the controls of the form. The same code could be used for any form (e.g. a driver's license application). Below is the code for saving the information in the controls of the form. Note how we cycle through each control in the form. Then, using the StreamWriter, we write out the content of each control.
Another year has gone by and some things don't change. That's right, paying taxes. What has changed over the years is that taxes have become more and more complicated. If you've ever looked at the 1040 Form, the 1099, the W-2, the Schedule A, B, C and the rest of the alphabet, you probably found yourself wondering which is worse: paying the money to the government or filling out the paperwork. A few years ago, the government heard the cry of the citizen who was up to his neck in forms and tried to ease the process of filing the 1040 by creating the 1040EZ form. This form, which is miraculously only a single page, is a lot less painful than its descendant the 1040. Of course if you are able to take advantage of any of the tax benefits the government provides (such as deductions), you'll need to file the old dependable, but tedious 1040.
Listing 1 - Saving the 1040EZ form contents to an ASCII file
- private void SaveMenu_Click(object sender, System.EventArgs e) {
-
- saveFileDialog1.InitialDirectory = Application.ExecutablePath.ToString();
-
- if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
-
- FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write);
-
- StreamWriter sw = new StreamWriter(fs);
-
- foreach(Control c in Controls) {
-
- string strType = c.GetType().ToString().Substring(c.GetType().ToString().LastIndexOf(".") + 1);
-
- if (strType == "TextBox") {
- sw.WriteLine(((TextBox) c).Text.ToString());
- }
-
- else if (strType == "CheckBox") {
- if (((CheckBox) c).Checked)
- sw.WriteLine("1");
- else
- sw.WriteLine("0");
- }
- }
-
- sw.Close();
- fs.Close();
- }
- }
The routine for printing the control is just as generic. In the printing routine we cycle through each control and draw the control contents if its either a TextBox or a CheckBox. The drawing of the form for printing is called from the PrintPage event (More on how to add printing to your applications can be found in the book The Complete Visual C# Programmer's Guide.)
Listing 2 - Routine called for printing out the 1040EZ form
- private void DrawAll(Graphics g) {
-
-
- StringFormat sf = new StringFormat();
- sf.Alignment = StringAlignment.Far;
-
- this.AutoScrollPosition = new Point(0, 0);
-
- RectangleF srcRect = new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height);
-
- int nWidth = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width;
- int nHeight = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Height;
- RectangleF destRect = new Rectangle(0, 0, nWidth, nHeight);
-
- g.DrawImage(HiResImage, destRect, srcRect, GraphicsUnit.Pixel);
-
-
-
- float scalex = destRect.Width / srcRect.Width;
- float scaley = destRect.Height / srcRect.Height;
-
- foreach(Control c in Controls) {
-
- string strType = c.GetType().ToString().Substring(c.GetType().ToString().LastIndexOf(".") + 1);
- if (strType == "TextBox") {
- TextBox theText = (TextBox) c;
-
-
-
- if (theText.TextAlign.ToString() == "Left")
- g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex, theText.Bounds.Top *
- scaley,
- new StringFormat());
- else {
- RectangleF LayoutRect = new RectangleF(theText.Bounds.Left * scalex, theText.Bounds.Top * scaley,
- theText.Bounds.Width * scalex, theText.Bounds.Height * scaley);
- g.DrawString(theText.Text, theText.Font, Brushes.Black, LayoutRect, sf);
- }
- }
-
- if (strType == "CheckBox") {
- CheckBox theCheck = (CheckBox) c;
- Rectangle aRect = theCheck.Bounds;
- if (theCheck.Checked) {
- g.DrawString("x", theCheck.Font, Brushes.Black,
- theCheck.Left * scalex + 1, theCheck.Top * scaley + 1, new StringFormat());
- }
- }
- }
- }
Improvements
One thing I noticed is that would be nice to have are some TextBox controls that have masks for phone numbers and social security numbers so dashes and parentheses are automatically placed in the right places. In this application, you need to add spaces to your Social Security Number to have the Numbers fall in the correct spots on the line. Also, the program should also validate eligibility for using the 1040EZ form. (e.g. if you over the age of 65, you can't use the form). What might be cool, if the W-2 Application and the 1040EZ form application could be linked together to extract the form information from the W-2 Application. I think the future of all these government forms is to have these applications running on the web, all linked together similar to the way they are in applications such as Turbo Tax so anyone can access them and file there taxes over the internet. Maybe the .NET initiative will help pave the way for a less complicated and less taxing situation.