使用单选按钮创建输入框c# [英] Creating an inputbox with radiobuttons c#

查看:128
本文介绍了使用单选按钮创建输入框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:

  1. 点击Project> Add Windows Form.
  2. 将Form控件的FormBorderStyle属性设置为FixedDialog以防止 用户调整表单的大小.
  3. MinimizeBoxMaximizeBox属性设置为false.
  4. StartPosition属性设置为CenterScreenCenterParent.
  5. 在带有文本OK的表单中添加一个按钮,并设置DialogResult 属性设置为OK.
  6. 将带有文本Cancel的按钮添加到表单并设置DialogResult 属性Cancel.
  7. 更改表单的AcceptButton属性以引用OK按钮.
  8. 更改表单的CancelButton属性以引用Cancel按钮.
  9. 在表单中添加TextBoxRadioButtonCheckBox控件.
  10. F7键打开表单的代码视图.
  11. 实现类型为string的属性,该属性返回以下属性的Text属性: TextBox控件.
  12. 您还需要想出一种方法来解决 形式;我会让你自己弄清楚这部分:)
  13. 要显示表单,请创建一个实例并调用ShowDialog()方法. 这将阻止调用方法,直到用户单击按钮为止. ShowDialog方法将返回DialogResult,可用于 确定单击了哪个按钮.
  1. Click Project > Add Windows Form.
  2. Set the FormBorderStyle property of the Form control to FixedDialog to prevent the user from resizing the form.
  3. Set the MinimizeBox and MaximizeBox properties to false.
  4. Set the StartPosition property to CenterScreen or CenterParent.
  5. Add a button to the form with the text OK and set the DialogResult property to OK.
  6. Add a button to the form with the text Cancel and set the DialogResult property to Cancel.
  7. Change the AcceptButton property of the form to reference the OK button.
  8. Change the CancelButton property of the form to reference the Cancel button.
  9. Add a TextBox and a RadioButton or CheckBox control to the form.
  10. Press the F7 key to open the code view for the form.
  11. Implement a property of type string that returns the Text property of the TextBox control.
  12. 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 :)
  13. 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.

这篇关于使用单选按钮创建输入框c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆