Question

In: Computer Science

C#: If the code is the only thing that you can provide without the pictures of...

C#: If the code is the only thing that you can provide without the pictures of the form, then that is fine as well.

Topics: hiding/showing controls, StatusStrip, custom event arguments, radio buttons

Students will create an application that uses a dialog to create a spaceship object to populate a ListView. This ListView will be able to display in either large or small icon mode using a menu option to switch between them. Selecting a spaceship in the ListView will give the user the ability to modify that object’s values and apply those changes.

You will be creating two forms, the main window with a ListView, MenuStrip, and StatusStrip, and a dialog window with some user input fields for making a spaceship object. The inputs needed for the spaceship are a TextBox for name, a numericUpDown for crew size, a checkbox for indicating active duty, and a set of 3 radio buttons for selecting the type of ship (Cruiser, Destroyer, or Freighter). There should be three buttons on this dialog: OK, Cancel, and Apply. OK and Cancel will always be visible, but the Apply button will only appear when attempting to modify an item from the ListView. The OK button will add a ListViewItem with the current input to the main window’s ListView, and the Cancel button will close the window without changing anything in the main window. The Apply button should use a custom EventHandler and custom event arguments to modify the selected item in the main window’s ListView to have the current input values in the dialog. The main window’s MenuStrip should have three separate menus: File, Ship, and View. Each of these menus will have the following options: File->Clear to clear the ListView, File->Exit to exit the application, Ship->New to open a dialog to make a new spaceship without the Apply button being visible, View->Large to make the ListView use LargeIcon mode, and View->Small to make the ListView use SmallIcon mode. The currently selected icon mode should have a checkmark displayed next to it. The StatusStrip should appear at the bottom of the window and have a single ToolStripStatusLabel showing the current number of items in the ListView. There should be unique images for each of the 3 ships with a large 32x32 and a small 16x16. Double-clicking an item in the ListView should bring up the spaceship dialog with the Apply button visible and the fields pre-populated with the selected item’s current values.

Follow these guidelines for this application:

User Input Dialog

  • Radio buttons are used for ship selection that function as radio buttons should (only one option selectable at a time).

  • Apply button should only be visible when opened by double clicking a ListViewItem.

  • A TextBox for name, NumericUpDown for crew size, and CheckBox for active duty are present for additional user input about the spaceship.

  • OK and Cancel buttons should always be present on this dialog.

ListView/Main Window

  • ListView exists, set to dock/fill the parent container, and can be toggled between LargeIcon and SmallIcon mode.

  • A StatusStrip is present at the bottom of the window that always displays the current Item count of the ListView.

  • Double clicking a ListViewItem brings up the spaceship dialog as does selecting the Ship->New MenuStrip option.

  • 3 Unique images are used in the ListView that correspond to the three ship types. Large(32x32) and Small(16x16) image lists are used for this purpose.

Events

  • When the Apply button is pressed, a custom EventArgs class is used with an EventHandler to pass the updated spaceship information to the main window. The updated spaceship fields are used to update the currently selected spaceship.

  • When the OK button is pressed, a new spaceship with the current input values is added to the ListView and the spaceship dialog is closed.

  • When the Cancel button is pressed, the spaceship dialog closes without affecting the main window’s controls.

Solutions

Expert Solution

ListViewControl

private void CreateMyListView()
{
   // Create a new ListView control.
   ListView listView1 = new ListView();
   listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));

   // Set the view to show details.
   listView1.View = View.Details;
   // Allow the user to edit item text.
   listView1.LabelEdit = true;
   // Allow the user to rearrange columns.
   listView1.AllowColumnReorder = true;
   // Display check boxes.
   listView1.CheckBoxes = true;
   // Select the item and subitems when selection is made.
   listView1.FullRowSelect = true;
   // Display grid lines.
   listView1.GridLines = true;
   // Sort the items in the list in ascending order.
   listView1.Sorting = SortOrder.Ascending;
          
   // Create three items and three sets of subitems for each item.
   ListViewItem item1 = new ListViewItem("item1",0);
   // Place a check mark next to the item.
   item1.Checked = true;
   item1.SubItems.Add("1");
   item1.SubItems.Add("2");
   item1.SubItems.Add("3");
   ListViewItem item2 = new ListViewItem("item2",1);
   item2.SubItems.Add("4");
   item2.SubItems.Add("5");
   item2.SubItems.Add("6");
   ListViewItem item3 = new ListViewItem("item3",0);
   // Place a check mark next to the item.
   item3.Checked = true;
   item3.SubItems.Add("7");
   item3.SubItems.Add("8");
   item3.SubItems.Add("9");

   // Create columns for the items and subitems.
   // Width of -2 indicates auto-size.
   listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
   listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
   listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
   listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

   //Add the items to the ListView.
       listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

   // Create two ImageList objects.
   ImageList imageListSmall = new ImageList();
   ImageList imageListLarge = new ImageList();

   // Initialize the ImageList objects with bitmaps.
   imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));
   imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));
   imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));
   imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));

   //Assign the ImageList objects to the ListView.
   listView1.LargeImageList = imageListLarge;
   listView1.SmallImageList = imageListSmall;

   // Add the ListView to the control collection.
   this.Controls.Add(listView1);
}


Related Solutions

MIPS ASSEMBLY LANGUAGE (I'm using MARS) Can you provide me with the code of this, without...
MIPS ASSEMBLY LANGUAGE (I'm using MARS) Can you provide me with the code of this, without using DIV (4a-b)%[(2+c)/d] (a,b,c,d are user inputs)
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW...
provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials * * 2. Adding polynomials * * 3. Multiplying polynomials. * * 4. Displaying polynomials * * 5. Clearing polynomials. * * 6. Quit. * *********************************** Select the option (1 through 6): 7 You should not be in this class! ************************************* *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1. Creating polynomials...
Suppose that the only thing you know about Gondor is that its economy can be described...
Suppose that the only thing you know about Gondor is that its economy can be described as a Cobb-Douglas production function of labor and capital with constant returns to scale. After some Internet surfing, you find out from the United Nations website that Gondor has a GDP of 16. Then you discover on the World Bank website that capital's share of total income in Gondor is 40%. The final piece of the puzzle comes from the CIA Factbook, where you...
PROVIDE CODE ONLY IN C++ / NO OTHER LANGUAGES PLEASE ADD SELECTION SORT/ INSERTION SORT/ AND...
PROVIDE CODE ONLY IN C++ / NO OTHER LANGUAGES PLEASE ADD SELECTION SORT/ INSERTION SORT/ AND BUBBLE SORT FUNCTION TO THIS PROGRAM #include <iostream> #include<vector> #include <algorithm >   #include <chrono>    #include <ctime> using namespace std; void bubblesSort() { // Please create Bubble Sort function// Make another for Selection Sort and  Insertion Sort } int main() { // empty vector vector<int> data; // data [0], data [1]... data[N-1] <-- end(data) // set of values to test N for (auto N :...
The code should be written in c++. It should be in only OpenGL // ***** ONLY...
The code should be written in c++. It should be in only OpenGL // ***** ONLY OpenGL PLEASE ******// write a program snippet that accepts the coordinates of the vertices of a rectangle centered around the origin, with edges that are parallel to the X and Y axes, and with aspect ratio W and converts it into a rectangle centered around the origin with aspect ratio of 1/W. The program has to figure W from the given points. You MUST...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function for the radius variable. • getRadius. An acccssor function...
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
can you please explain each and every statement of the code without missing. it would be...
can you please explain each and every statement of the code without missing. it would be really helpful AVA PROJECT CREATING GUI WITH ARRAY Read from a file that contains a paragraph of words. Put all the words in an array, put the valid words (words that have only letters) in a second array, and put the invalid words in a third array. Sort the array of valid words using Selection Sort. Create a GUI to display the arrays using...
Can someone make this code work without using template? C++ using namespace std; template < typename...
Can someone make this code work without using template? C++ using namespace std; template < typename T>    void print_array(T arr[], int size)    {        ofstream outfile;        outfile.open("/Users/android/Desktop/outfile.txt");        cout << "Printing Array: " << endl;        for (int i = 0; i < size; i++)        {            cout << arr[i] << endl;            outfile << arr[i] << endl;        }    } template < typename T>...
For the following two questions you need to provide a code in C 1. Build a...
For the following two questions you need to provide a code in C 1. Build a double linked list with 5 in the first node following the instructions: Insert a node with 3 at the top of the list Insert a node with 10 at the bottom of the list Insert a node with 7 between nodes with 5 and 10 2. Start deleting nodes from the list in the following order; Delete the node with 7 Delete the node...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT