单击按钮时如何在文本框中显示数字?
我是c#的新手,我正在为修改后的预警评分系统(MEWS)构建窗口表单,该表单用于医院中以监视患者的健康状况.我已经为此构建了一个GUI,但是我不确定要使用什么代码才能使其正常工作.我使用计时器在屏幕上移动彩色标签,以代表患者的生命体征.
我只用一个按钮启动计时器,就可以正常工作了.但是我接下来要做的是根据该生命体征计时器的输出显示分数.我要使用按钮,当按下这些按钮时,分数将在文本框中显示.我想知道的是我使用什么代码来完成这项工作?您也可以给我示例代码,因为我很可能不知道如何自己写出来.
到目前为止,这是我程序的代码:
Im new to c# and im building a windows form for the Modified early warning scoring system (MEWS) which is used in hospitals to monitor a patients health. I have built a GUI for it, but im not sure what code to put in to get it to work. Im using timers to move coloured labels across the screen to represent a patient vital signs.
Ive but a button in which starts the timers and this works fine. But what I want to do next is show a score based on the output of that vital sign timer. I want to use buttons which when pressed will display the score in a text box. What I want to know is what code do i use to make this work? Also can you give me example code since I will most likely not know how to write it out myself.
Heres the code for my program so far:
namespace MewsV1._0
{
public partial class frmMews : Form
{
Random r = new Random();
public frmMews()
{
InitializeComponent();
}
private void txtPatientName_TextChanged(object sender, EventArgs e)
{
}
private void frmMews_Load(object sender, EventArgs e)
{
tmrResps.Enabled = false;
tmrResps.Interval = 300; // milliseconds
tmrHeart.Enabled = false;
tmrHeart.Interval = 700; // milliseconds
tmrBlood.Enabled = false;
tmrBlood.Interval = 700; // milliseconds
tmrConsious.Enabled = false;
tmrConsious.Interval = 600; // milliseconds
tmrTemp.Enabled = false;
tmrTemp.Interval = 600; // milliseconds
tmrUrine.Enabled = false;
tmrUrine.Interval = 600; // milliseconds
}
private void btnStart_Click(object sender, EventArgs e)
{
tmrResps.Enabled = true;
tmrResps.Interval = 2000; // milliseconds
tmrHeart.Enabled = true;
tmrHeart.Interval = 1000; // milliseconds
tmrBlood.Enabled = true;
tmrBlood.Interval = 2000; // milliseconds
tmrConsious.Enabled = true;
tmrConsious.Interval = 5000; // milliseconds
tmrTemp.Enabled = true;
tmrTemp.Interval = 1000; // milliseconds
tmrUrine.Enabled = true;
tmrUrine.Interval = 5000; // milliseconds
}
private void tmrResps_Tick(object sender, EventArgs e)
{
Random r = new Random();
int x = ( (int)( (r.Next(0, 100) ) / 10) ) * 10;
//---
if (lblResps.BackColor == System.Drawing.Color.Magenta)
{
lblResps.BackColor = System.Drawing.Color.Magenta;
lblResps.Size = new System.Drawing.Size( x, 23);
}
else
{
lblResps.BackColor = System.Drawing.Color.Magenta;
}
}
private void tmrHeart_Tick(object sender, EventArgs e)
{
int x = ((int)((r.Next(0, 100)) / 10)) * 10;
if (lblHeart.BackColor == System.Drawing.Color.Cyan)
{
lblHeart.BackColor = System.Drawing.Color.Cyan;
lblHeart.Size = new System.Drawing.Size(x, 23);
}
else
{
lblHeart.BackColor = System.Drawing.Color.Cyan;
}
}
private void tmrBlood_Tick(object sender, EventArgs e)
{
int x = ((int)((r.Next(0, 100)) / 10)) * 10;
if (lblBlood.BackColor == System.Drawing.Color.Red)
{
lblBlood.BackColor = System.Drawing.Color.Red;
lblBlood.Size = new System.Drawing.Size(x, 23);
}
else
{
lblBlood.BackColor = System.Drawing.Color.Red;
}
}
private void tmrConsious_Tick(object sender, EventArgs e)
{
int x = ((int)((r.Next(0, 100)) / 10)) * 10;
if (lblConsious.BackColor == System.Drawing.Color.Green)
{
lblConsious.BackColor = System.Drawing.Color.Green;
lblConsious.Size = new System.Drawing.Size(x, 23);
}
else
{
lblConsious.BackColor = System.Drawing.Color.Green;
}
}
private void tmrTemp_Tick(object sender, EventArgs e)
{
int x = ((int)((r.Next(0, 100)) / 10)) * 10;
if (lblTemp.BackColor == System.Drawing.Color.Brown)
{
lblTemp.BackColor = System.Drawing.Color.Brown;
lblTemp.Size = new System.Drawing.Size(x, 23);
}
else
{
lblTemp.BackColor = System.Drawing.Color.Brown;
}
}
private void tmrUrine_Tick(object sender, EventArgs e)
{
int x = ((int)((r.Next(0, 100)) / 10)) * 10;
if (lblUrine.BackColor == System.Drawing.Color.Yellow)
{
lblUrine.BackColor = System.Drawing.Color.Yellow;
lblUrine.Size = new System.Drawing.Size(x, 23);
}
else
{
lblUrine.BackColor = System.Drawing.Color.Yellow;
}
}
}
}
}
随机数代码im使用:
Random Number code im using:
namespace RandomNumber
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
for (int i = 0; i < 500; i++)
{
int x = ( (int)( ( r.Next(0, 100) ) / 10 ) ) * 10;
Console.WriteLine(x.ToString());
}
}
}
}
在按钮的click事件中,将文本框的text方法分配给您希望其显示的值,例如:
in the button''s click event, assign the text box''s text method to the value you want it to display for example:
textbox1.Text = "item you want to display"