Click here to Skip to main content
15,867,756 members
Articles / Programming Languages / C#

MDI Case Study Purchasing - Part VI - Document Form I

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
24 Nov 2015CPOL5 min read 10.6K   336   6  

Introduction

In Part VI we will continue the design of our document form, PurchaseOrderForm. This will involve placing data bound controls onto the form, and laying them out into a presentable interface.

Finishing PurchaseOrderForm - MDI Menu Merging

First of all, once again let's delete the controls for PurchaseOrderNumber, the Label and TextBox. Let's also delete the purchaseOrderNumberTextbox_TextChanged handler from our code. Now once again we have a fresh empty form. First, lets add a MenuStrip to our form, and create one root menu item named "Document". However, when you type in the name "Document", type it as "&Document". This will cause the 'D' to have an underscore, and will cause the menu to respond to the Alt+D hot keys. Basically, any letter you want to be your Alt hot key, preceed it with an '&' in the menu item name.

Screenshot 1

Screenshot 2

MDI Parent forms emply menu merging, so that the menu for child form merges into the main menu. You can test this out now by running the application and creating a new form, and you will see the "Document" menu as part of the main parent menu. And when all documents are closed, the "Document" menu goes away.

Screenshot 3

Next, lets change the BackColor of our form. The end goal of our appearance is to mimic Microsoft Word, and have the look of a page in our form. To achieve this, our "page" will be a Panel with a White BackColor, agains the darker BackColor of the form. I've chosen AppWorkspace as the color for the form BackColor, but you could certainly alter that to your liking. After changing the BackColor, add a Panel control to the form by dragging it from the Toolbox, and name it pagePanel. Change BackColor to Window. Now your form should look more like a "page" document. We want our page to be a static size that will not change, so change the MaximumSize and MinimumSize both to (1024,768). Also, for PurchaseOrderForm, change the AutoScroll property to True. Now the page will the same size always, and you can scroll the form as needed.

Screenshot 4

Next let's add a logo to our document. The goal is to have the document form resemble the printed document as closely as possible. There will be a few differences as we move along, but not many. I have created a logo for the project, again using our truck, and a comany name of MDI Purchasing, Inc. And for simplicity sake, our document will be grayscale only, so the logo is also grayscale.

Truck Logo

Lets drag a PictureBox onto our form. Give it a size of (320,100) and set its Image to the image above, or whatever other logo image you like. We want this to be in the upper left corner of our panel, you can set it's location to (24,30). Now we have a logo on our document form

Screenshot 5

Next we will add the display for the Purchase Order Number. For the Purchase Order Number, we want a box with the Label and the property itself. In this case, we will show the Purchase Order Number with a Label. For this display, we will create 2 panels, one ontop of the other. The top one will hold the label that reads "Purchase Order Number", and will have a slightly darker BackColor, the other will hold the actual PurchaseOrderNumber label, and will have the default BackColor. Both need a Border of FixedSingle. Now let's go to the Data Sources tool panel, and find PurchaseOrderNumber. Click the drop down for it, and select Label in stead of TextBox. Now drag this property onto our form. Again, 2 labels will be created, one that displays the property name, and one that displays the property value. Move the name label into the top panel, and center it. set its Font.Bold property to True. Then dray the value label into the bottom panel. Lastly, make the value label the same size as the panel it's in, and set its TextAlign to MiddleCenter. So here is what you should have

Screenshot 6

Next, we will add our Billing Address display. First, for the PurchaseOrder.BillingAddress data source, in the Data Sources tool panel, for each of its properties, use the drop down to change them from TextBox type to Label type. Now lets create a new 2 panel set, similar to the Purchase Order Number panels above, but this time larger. And drag each of the PurchaseOrder.BillingAddress properties into the larger bottom Panel, and lay them out the way a normal address should look. Also, no need for the property name labels this time, except for Phone and Fax, so delete the others. When you are finished, here is what your form should look like

Screenshot 7

Now, below the logo, repeat the above process and create a VendorAddress display area, and below the Billing Address, create a ShippingAddress display area. For vendor address, we wont need Attention, so you can leave it off. For shipping address, don't worry about Phone and Fax number, unless you want to, but for this project we wont use them. So after this, your form should resemble this

Screenshot 8

Finally, to conclude this installment, let's put some data into these address objects to see them populate onto our form. In the future we will be loading the Billing Address and Shipping Address from our application configuration, and we will be loading the Vendor Address from the selected vendor for the document, which we will allow selection for soon. For now, lets just put some sample data into these address objects in the PurchaseOrder default constructor.

C#
public PurchaseOrder()
{
    _billingAddress = new BillingAddress();
    // Sample billing address data
    _billingAddress.Attention = "Accounts Payable";
    _billingAddress.CompanyName = "MDI Purchasing, Inc.";
    _billingAddress.AddressLine1 = "PO Box 12345";
    _billingAddress.City = "Anytown";
    _billingAddress.State = "NY";
    _billingAddress.ZipCode = "12345";
    _billingAddress.PhoneNumber = "212-555-1234";
    _billingAddress.FaxNumber = "212-555-1237";
    _shippingAddress = new ShippingAddress();
    // Sample shipping address data
    _shippingAddress.Attention = "Receiving Dept.";
    _shippingAddress.CompanyName = "MDI Purchasing, Inc.";
    _shippingAddress.AddressLine1 = "123 Place Way";
    _shippingAddress.AddressLine2 = "Suite 100";
    _shippingAddress.City = "Anytown";
    _shippingAddress.State = "NY";
    _shippingAddress.ZipCode = "12345";
    _purchaseOrderNumber = String.Empty;
    _vendor = new Vendor();
    _vendorAddress = _vendor.Address;
    // Sample vendor address data
    _vendorAddress.CompanyName = "Nuts and Bolts ETC";
    _vendorAddress.AddressLine1 = "321 Street Drive";
    _vendorAddress.AddressLine2 = "Suite A";
    _vendorAddress.City = "Cityville";
    _vendorAddress.State = "CA";
    _vendorAddress.ZipCode = "54321";
    _vendorAddress.PhoneNumber = "555-456-1234";
    _vendorAddress.FaxNumber = "555-456-4321";
    _items = new ItemCollection();
}

 

Now you can run the app, create a new document, and your addresses will be populated, and should look like this

Screenshot 9

So that does it for Part VI. Next we will finish out our form layout.

Points of Interest

  • ObjectDataSources
  • Form layout

History

Keep a running update of any changes or improvements you've made here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --