I'm currently making a simple C# game for a college assignment, wondering if it's possible to have radio or checkbox (or something similar) inputs upon loading, in an external window.
I'm currently using this to get a username:
public Form1()
{
InitializeComponent();
Initialize();
GlobalVar.Username = Microsoft.VisualBasic.Interaction.InputBox("Welcome to EasiGame, Please enter your username.", "Welcome", "Player1", -1, -1);
label4.Text = GlobalVar.Username;
}
This references VB, and that works great, however could I include radio buttons or something in this box, or a separate box, to grab user input for a difficulty setting.
Thanks in advance!
You would have implement your own form. Assuming you're using a recent version of Visual Studio:
- Click
Project
> Add Windows Form
.
- Set the
FormBorderStyle
property of the Form control to FixedDialog
to prevent
the user from resizing the form.
- Set the
MinimizeBox
and MaximizeBox
properties to false.
- Set the
StartPosition
property to CenterScreen
or CenterParent
.
- Add a button to the form with the text
OK
and set the DialogResult
property to OK
.
- Add a button to the form with the text
Cancel
and set the DialogResult
property to Cancel
.
- Change the
AcceptButton
property of the form to reference the OK
button.
- Change the
CancelButton
property of the form to reference the Cancel
button.
- Add a
TextBox
and a RadioButton
or CheckBox
control to the form.
- Press the
F7
key to open the code view for the form.
- Implement a property of type
string
that returns the Text
property of
the TextBox
control.
- You'll also need to come up with a way of getting the difficulty from the
form; I'll let you figure this part out for yourself :)
- To show the form, create an instance and call the
ShowDialog()
method.
This will block the calling method until the user has clicked a button.
The ShowDialog
method will return a DialogResult
, which can be used to
determine which button was clicked.