什么是使用Windows窗体,视觉工作室的游戏中的开始按钮的代码? [英] What is a code for a start button in a game using windows form, visual studio?

查看:159
本文介绍了什么是使用Windows窗体,视觉工作室的游戏中的开始按钮的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个寻宝游戏,并且已经找到了用于启动按钮的代码,我正在使用Visual Studio,Windows Form。

NOte:它是一个切换按钮

请尽快帮助。




我尝试过的事情:



我有字面上尝试了一些代码,但没有用。

I have designed a game of treasure hunt and have looked for a code to use for the start button, I am using Visual Studio, Windows Form.
NOte: it is a toggle button
Please help ASAP.


What I have tried:

I have literally tried some codes but did not work.

推荐答案

试试这个

创建一个名称 as btnStartPause和 Text as Start

try this
Create a button with Name as btnStartPause and Text as Start
private void btnStartPause_Click(object sender, EventArgs e)
        { 
            btnStartPause.Text = btnStartPause.Text == "Start" ? "Pause" : "Start";
            if (btnStartPause.Text == "Start")
            {
                // Pause Code...
                MessageBox.Show("Pause code");
            }
            else
            {
                // Start code...
                MessageBox.Show("Start code");
            }
        }


最简单的方法是更改​​按钮上的文字(或图像)。

对于文本按钮:

The simplest way is to change the text (or image) on the button.
For text button:
private const string PromptStart = "Start";
private const string PromptPause = "Pause";
private void butStartPause_Click(object sender, EventArgs e)
    {
    if (butStartPause.Text == PromptStart)
        {
        butStartPause.Text = PromptPause;
        // Do the pause
        ...
        }
    else if (butStartPause.Text == PromptPause)
        {
        butStartPause.Text = PromptStart;
        // UnPause
        ...
        }
    else
        {
        throw new ApplicationException("Unknown button context: " + butStartPause.Text);
        }
    }

请记住将Text设置为构造函数或Load事件中的已知值之一。

对于图像,它是相同的进程,但使用Image对象和Button.Image属性。

Remember to set the Text to one of the "known" values in your constructor or Load event.
For images it's the same process, but using Image objects and the Button.Image property.


这篇关于什么是使用Windows窗体,视觉工作室的游戏中的开始按钮的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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