如何过去编号到textBox? [英] How to past number to textBox?

查看:86
本文介绍了如何过去编号到textBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我需要过去按钮到textBox的数量。

步骤

1)选择textBox。 ,现在Cursor焦点textBox。

2)点击任意按钮,文本按钮过去到textBox。

但我不知道如何...

请给我一个好主意。

我需要这样的查看图片

推荐答案

可以在TextBox中写入Button的Text属性,或者将文本附加到它。



以下面的场景为例,



The thing can be, to write the Text property of the Button inside the TextBox, or append the text to it.

Take the following scenario as example,

// Create button and write 2 to it; just as example
Button button = new Button();
button.Text = "2";

// To handle event, 
button.Click += Button_Click;

// Create a new instance of TextBox
TextBox textBox = new TextBox();





现在点击,你可以处理该事件并将其值写入TextBox。像这样





Now upon click, you can handle the event and write its value to the TextBox. Like this

void Button_Click(object sender, EventArgs e) {
   // The object that raised this event was Button so change it 
   Button button = sender as Button;
   string value = button.Text; // would be '2'
   // assign (append; see the +=) this value to the TextBox
   textBox.Text += value;
}





这是这个项目和场景的一个非常基本的例子,对于一个简单的例子,我有一个项目对于Calculator应用程序,您可以查看该应用程序以了解此模式,在 https://获取该模式的源代码code.msdn.microsoft.com/Simple-Calculator-34e18835 [ ^ ]


有趣的一个terzasek。



您可以使用文本框的Mouse_Down事件。您可以使用全局变量或标签将鼠标的值保持在哪个文本框中。然后在按钮点击后从标签中获取值(即选择了文本框)并进行必要的工作或计算。我在你的问题中的图像中描述了一个小例子。看看这个。我希望在查看示例后,您的混淆将被清除。

示例:

https://app.box.com/s/ iedkdaraa1uts4n43l31hlwvf5cp30d6 [ ^ ]
Interesting one terzasek.

You can use Mouse_Down event of the text boxes. You can take a global variable or a label to hold the value of the mouse down on which textbox. and after button click get the value from label(ie. whcih textbox has been selected) and do your necessary work or calculations . I have done a small example to do this as you describe in the image in your question. just take a look on this. I hope your confusion will be cleared after checking the example.
Example :
https://app.box.com/s/iedkdaraa1uts4n43l31hlwvf5cp30d6[^]

这篇关于如何过去编号到textBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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