I have to create an application that will dynamically add a menu strip with menu items to a form(ie NOT dragged and dropped onto the form) in Visual Basic. The menu strip should be created in the Form_Load event handler.
I have to use a TextBox for user input. If the user enters information into the TextBox and clicks on the Add Button, the text should be added to a ComboBox control.A Menu should then be created that must be added to the menu strip dynamically.
There should be a second TextBox that will be used to add a new menu item to the menu that is currently selected in the ComboBox.
When a menu item is selected, it must simply display a MessageBox with the items name (For example, adding a menu item called View would display a MessageBox with the message “View”)
I have to create a quiz machine program in in Visual Basic with the following:
A menu strip that must be created programmatically (ie NOT dragged and dropped onto the form). There should be an exit option added to the menu strip that must exit the application.
A structure must be created to encapsulate all the questions and suggested answers. The structure must contain:
Question String
Answers Collection
Correct Answer String
When the form loads, 5 questions must be created in code using these structures. These 5 structures will then serve as the quiz. The user must be shown the first question, and have the option of browsing forwards and backwards through the quiz. The program should store saved answers to select the radio button when users cycle through. This can be done by any means possible, for example an ArrayList or SortedList.
I have to ensure that the suggested answers are randomized the first time the form loads only.
Once the user has selected an answer for every question, the Submit button should be enabled. When the user clicks this button, the program must then evaluate the quiz and compare the users selected answers against the correct answer. A valid message must then be displayed via a MessageBox indicating the user's score.
I desperately need the code to create these applications!

Recommended Answers

All 5 Replies

This sounds like a homework assignment. We are here to offer help if you are having trouble in specific areas but we will not do your homework for you. Please show us what you have done so far.

I have tried to do this question. I know how to create a Main Menu dynamically,but I don't know how to create a Menu Strip and then add menu items to it dynamically. I also don't know how to create new Menu Items from the the text in the textbox when they tell you to create the Menustrip in the Form_Load event handler? With the second one I'm not sure where I should create the 5 arrays that hold the possible answers. I know that I must create one Structure that will act as a template from which to create the 5 questions. But pretty much everything else they ask I'm not sure how to do (cycling through the questions etc.)
Any help will be appreciated

An easy way to see how to code a menu strip is to create a sample project and add a menu strip using the designer. Save the project, then use notepad to look at the generated code in the project folder. The file will have a name like


and the code will look like

    Me.MenuStrip1 = New System.Windows.Forms.MenuStrip()
    Me.FileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
    Me.OpenToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
    Me.CloseToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
    Me.ExitToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
    Me.EditToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
    Me.CopyToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
    Me.CutToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
    Me.PasteToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
    Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem, Me.EditToolStripMenuItem})
    Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
    Me.MenuStrip1.Name = "MenuStrip1"
    Me.MenuStrip1.Size = New System.Drawing.Size(356, 24)
    Me.MenuStrip1.TabIndex = 1
    Me.MenuStrip1.Text = "MenuStrip1"
    Me.FileToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.OpenToolStripMenuItem, Me.CloseToolStripMenuItem, Me.ExitToolStripMenuItem})
    Me.FileToolStripMenuItem.Name = "FileToolStripMenuItem"
    Me.FileToolStripMenuItem.Size = New System.Drawing.Size(37, 20)
    Me.FileToolStripMenuItem.Text = "File"
    Me.OpenToolStripMenuItem.Name = "OpenToolStripMenuItem"
    Me.OpenToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
    Me.OpenToolStripMenuItem.Text = "Open"
    Me.CloseToolStripMenuItem.Name = "CloseToolStripMenuItem"
    Me.CloseToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
    Me.CloseToolStripMenuItem.Text = "Close"
    Me.ExitToolStripMenuItem.Name = "ExitToolStripMenuItem"
    Me.ExitToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
    Me.ExitToolStripMenuItem.Text = "Exit"
    Me.EditToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.CopyToolStripMenuItem, Me.CutToolStripMenuItem, Me.PasteToolStripMenuItem})
    Me.EditToolStripMenuItem.Name = "EditToolStripMenuItem"
    Me.EditToolStripMenuItem.Size = New System.Drawing.Size(39, 20)
    Me.EditToolStripMenuItem.Text = "Edit"
    Me.CopyToolStripMenuItem.Name = "CopyToolStripMenuItem"
    Me.CopyToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
    Me.CopyToolStripMenuItem.Text = "Copy"
    Me.CutToolStripMenuItem.Name = "CutToolStripMenuItem"
    Me.CutToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
    Me.CutToolStripMenuItem.Text = "Cut"
    Me.PasteToolStripMenuItem.Name = "PasteToolStripMenuItem"
    Me.PasteToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
    Me.PasteToolStripMenuItem.Text = "Paste"

Start with your sample project and move the code from the Designer file into your Form Load handler. Play around with the simple case until you understand what is happening then add to it until you have something appropriate for your project.

I suggest you create a "Question" class with the following properties

question (string containing the question text)
answers (array of 5 strings containing the various choices)
answer (integer identifying the index (0-4) of the correct answer)

You can define a "New" method to which you could pass the values of the three properties. Create an array of type Question to store you entire quiz.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.