使用单选按钮创建输入框c# [英] Creating an inputbox with radiobuttons c#
本文介绍了使用单选按钮创建输入框c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在为大学作业制作一个简单的C#游戏,想知道加载时是否可以在外部窗口中输入广播或复选框(或类似内容). 我目前正在使用它来获取用户名:
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;
}
这引用了VB,效果很好,但是我可以在此框或单独的框中包含单选按钮或其他内容,以获取用户输入以进行难度设置. 预先感谢!
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!
推荐答案
您将实现自己的表单.假设您使用的是Visual Studio的最新版本:
You would have implement your own form. Assuming you're using a recent version of Visual Studio:
- 点击
Project
>Add Windows Form
. - 将Form控件的
FormBorderStyle
属性设置为FixedDialog
以防止 用户调整表单的大小. - 将
MinimizeBox
和MaximizeBox
属性设置为false. - 将
StartPosition
属性设置为CenterScreen
或CenterParent
. - 在带有文本
OK
的表单中添加一个按钮,并设置DialogResult
属性设置为OK
. - 将带有文本
Cancel
的按钮添加到表单并设置DialogResult
属性Cancel
. - 更改表单的
AcceptButton
属性以引用OK
按钮. - 更改表单的
CancelButton
属性以引用Cancel
按钮. - 在表单中添加
TextBox
和RadioButton
或CheckBox
控件. - 按
F7
键打开表单的代码视图. - 实现类型为
string
的属性,该属性返回以下属性的Text
属性:TextBox
控件. - 您还需要想出一种方法来解决 形式;我会让你自己弄清楚这部分:)
- 要显示表单,请创建一个实例并调用
ShowDialog()
方法. 这将阻止调用方法,直到用户单击按钮为止.ShowDialog
方法将返回DialogResult
,可用于 确定单击了哪个按钮.
- Click
Project
>Add Windows Form
. - Set the
FormBorderStyle
property of the Form control toFixedDialog
to prevent the user from resizing the form. - Set the
MinimizeBox
andMaximizeBox
properties to false. - Set the
StartPosition
property toCenterScreen
orCenterParent
. - Add a button to the form with the text
OK
and set theDialogResult
property toOK
. - Add a button to the form with the text
Cancel
and set theDialogResult
property toCancel
. - Change the
AcceptButton
property of the form to reference theOK
button. - Change the
CancelButton
property of the form to reference theCancel
button. - Add a
TextBox
and aRadioButton
orCheckBox
control to the form. - Press the
F7
key to open the code view for the form. - Implement a property of type
string
that returns theText
property of theTextBox
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. TheShowDialog
method will return aDialogResult
, which can be used to determine which button was clicked.
这篇关于使用单选按钮创建输入框c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文