COP4226, Homework 2
Due Thursday, November 1 (late 6am 11/2)
Zip your entire project and upload on the web. Exclude the
Debug and Release directories.
Submitting
Homework Online.
Be sure to include your control library in your uploaded file.
Create a Single Document Interface application.
Avoid long methods. Each method that you create should be short, to promote
encapsulation. If you have a method that is longer than 25 lines, then it
probably needs to be divided into smaller methods.
Do not create a new data structure if one that already exists will
solve the problem.
Create Image
Create a separate project that will draw to an image and save the image to a file.
- The image should be no larger than 250x250 pixels.
- Only use four colors to create the image. Use four known colors.
- Use a pen that is at least 6 pixels wide.
- Draw an arc.
- Fill a closed bezier.
- Set the end cap for the pen as an anchor.
- Draw a polygon with at least three points.
- Draw several connected lines. Draw at least four lines.
- Change the color of the pen. Change the type of anchor. Create a custom pen dashing. Translate the graphics context and draw the exact same lines again.
- Change the color of the pen. Change the type of anchor. Change the pen to a compound pen. Turn off the dashing from the previous step. Translate the graphics context and draw the exact same lines again.
- Change the color of the pen. Change the type of anchor. Change the pen to a simple, solid pen. Translate and rotate the graphics context and draw the exact same lines again.
- Be sure that all of your shapes stay within the canvas of the image.
- Set the image as the background image for the main form.
- Save the image to the folder that contains the executable. Use the Application class to access this path.
- Run this project once, before running the main project for the first time.
Control Library
Use the control library from homework 1. Be sure to include the file in the zip that you upload.
- Add a form that will be used as a base form for the main form in the main
project.
- Add a menu strip, docked to the top.
- Add a top level menu item named Help to the menu strip.
- Add a menu item named Oath
- Add a menu item named About.
- Add handlers for both of these menu options; make them virtual.
The implementation of each should throw a new NotSupportedException
with an appropriate message.
- Add tool tips to the top level menu item and to each submenu
item.
- Add a top level menu item named File to the menu strip.
- Add a menu item named Close. When clicked, close the application.
- Add a status strip, docked to the bottom.
- Add a name control from your user library, dock it to the top, so
that it abuts the bottom of the menu strip.
- Add a main panel that fills the remaining area of the form; if the
form is resized, the panel should still fill the rest of the client
area.
- Change the access modifier for all of these so that derived classes
can access them.
Interfaces
Use interfaces to encapsulate implementation details. Design code so that the implementation details of data could be changed in the future without having to rewrite all the code that accesses that data.
Resources
Add to the project resources.
- Add the image that you created to the project resources.
Oath Dialog
Create a dialog in the main application that will display the pledge of honesty.
- Use the image resource as the background image.
- Extend from the base dialog in the control library.
- Add the oath control. Center it in the remaining space.
- The dialog should be a fixed size. Remove the icon, minimize button and maximize button.
About Dialog
Create a dialog in the main application that will display a description of the assignment.
- Use the image resource as the background image.
- Extend from the base dialog in the control library.
- Add a description of the assignment in your own words. Center it in the remaining space.
- The dialog should be a fixed size. Remove the icon, minimize button and maximize button.
Word Class
Create a class that will hold data for a word. The word will have text, location, amount of rotation, font size, typeface. Add properties to improve encapsulation. Add more properties and helper methods that contain operations that work on words. Encapsulate word processes in this class.
Document Class
Create a document class that will store words. Add properties and helper methods to encapsulate document processes in this class.
Word Options Dialog
Create a dialog in the main application that will allow the user to modify information for words.
- Extend it from the base dialog from the control library.
- Add controls to change all the properties in a word.
- Perform thorough validation. Allow focus change.
- Anchor the OK, Apply and Cancel buttons so that they remain in the lower right
area of the form when the form is resized.
- When using an interface, it is better to encapsulate actual properties in the dialog or components than to create additional variables.
- The dialog may not access any members from the main form, application settings or user settings.
Main Form
Extend the main form from the form that was added to the control library for this assignment.
- Override the handlers for the Oath and About menu items so they open the Oath and About dialogs modelesslly. Only allow one of each to be open at a time. Open the dialogs so they do not cover the main window. The main form should own the dialogs.
- Add a tab page group to the main form, so it fills the remaining area. Add two tabs, one for drawing backgrourds and one for drawing text. The details of these tabs are explained below.
From the main form, insert a new menu item into the base menu. This
cannot be done in the designer, due to issues with visual inheritance of
collection containers.
- Add a context menu to the main form.
- Add an item named Print.
- Add an item named Print Preview.
- Add tool tips to the menu items.
- Perform the following operations for the menu items
- Print the information for each word that is in the document: text,
location, typeface, font size
, rotation.
- Print the information in columns.
- Print five lines per page. Each line will contain the above information. Tabs will be helpful.
- Print a header on each page that contains the course aligned
to the left and the name of the assignment aligned to the
right. The header should be outside the margin bounds.
- Print a footer on each page that contains your name centered
and the page number aligned to the right. The footer should be outside the margin bounds.
- Use different fonts for the header, footer and content of the
page. Use a serif font, a sans serif font and a monospace font.
For one of them, use a generic font family. Make the
header font bold; make the footer font italic.
- Allow the user to print selections and ranges.
- Print preview will do the same as printing but will show the
results in a print preview dialog.
- Combine this context menu with the File menu in the base class.
Tab for Drawing Backgrounds
Add a tab page for drawing backgrounds.
- Add an item to the main menu in the base class for the color theme.
- The menu will contain the names of at least three color themes. Create an enumeration for the names of the themes.
- Each theme will have four colors associated with it.
- One of the themes should be the known colors that you used to create your image.
- One theme should use system colors.
- One theme should use colors that are not known colors.
- When a theme is selected, redraw the background with the new colors for the theme.
- Create a context menu that contains the options for the brush that will fill the background. Make this the context menu for the tab page. The brush will be used to fill the client rectanble for the tab page.
- Solid - Use a solid brush to paint the background. The brush should be drawn with a color from the current theme.
- Texture - Use your image to paint the background.
- Wrap the image so that it flips something.
- When the theme changes, change the colors in the image to match the theme. Use the changed image in the brush that draws the background.
- Hatched - Use a hatched brush. The brush should be drawn using two colors from the current theme.
- LinearGradient - Use a linear gradient brush to draw the background. Use all four colors from the current theme. Set the positions for the colors.
- PathGradient - Use a path gradient brush to draw the background. Use all four colors from the current theme. Change the center of the gradient.
- After an option is selected, be sure the new brush repaints the tab page.
- Add an item to the main menu in the base class that will display the same menu items as the context menu. The menu item should only appear when this tab page is open.
- Use an animated cursor that is only used on this tab.
Tab for Drawing Text
Add a tab page for drawing text.
- Create a context menu, for this tab, with one option for importing text from a text file.
- Read the file using a StreamReader and FileReader. There is a convenient method in StreamReader for grabbing all the text from the file.
- Split the text from the file into words and add the words to the document.
- Choose a default font for each word.
- Set the location of the words so that none of the words will overlap when displayed on the screen. You will need to calculate the size that is needed to display the word using a graphics context and the word's font. It is a bad idea to recalculate this every time that the tab is painted.
- Decide where it is best to place the code for these operations to increase encapsulation.
Add an item to the File menu from the base class that will display an option that does the same thing as the context menu. The menu item should only appear when this tab page is open.
- Be able to drag a word anywhere in the page. Do not use double buffereing, but limit flicker.
- Open a word options dialog for this word when the word is right-clicked.
- Open the dialog modally
modelessly.
- Only have one button, for closing the dialog.
- Be able to change all the properties for the word, except the location. Show the x and y for the location as labels..
- You may use a FontDialog for selecting the typeface and font size, but you may also just use text boxes.
- If the
font is typeface or size are changed, this will affect how the word can be dragged.
- If the text is changed, this will affect how the word can be dragged.
The rotation property is used to rotate the graphics context when this word is drawn. I suggest you implement this feature last. When the rotation is not zero, it will affect how you select a word for dragging, how a word is dragged, and how a word is selected.
- Use an animated cursor that is only used on this tab.
Application Demo: Demo