带有按钮,文本框和一些单选按钮的Windows窗体。 a,b,c是变量(整数),它根据检查的单选按钮进行一些数学计算。让我们说最后a = 15,b = 20,c = 10这个想法是点击按钮后的东西: 结果是:a = 15,b = 20,c = 10 必须在文本框中显示为文本,其中15,20和10是a,b和c的结束值。问题:
我在哪里进行数学运算?这很简单:
CREATE FUNCTION fn_getFirstNthSentence
(
@TargetStr VARCHAR(MAX) ,
@SearchedStr VARCHAR(8000) ,
@Occurrence INT
)
RETURNS varchar(MAX)
AS
BEGIN
DECLARE @pos INT ,
@counter INT ,
@ret INT;
SET @pos = CHARINDEX(@TargetStr, @SearchedStr);
IF ( @pos = 0 )
RETURN @SearchedStr
SET @counter = 1;
IF @Occurrence = 1
SET @ret = @pos;
ELSE
BEGIN
WHILE ( @counter < @Occurrence )
BEGIN
IF(LEN(@SearchedStr) < @pos + 1)
RETURN @SearchedStr
SELECT @ret = CHARINDEX(@TargetStr, @SearchedStr,
@pos + 1);
IF(@ret = 0)
RETURN @SearchedStr
SET @counter = @counter + 1;
SET @pos = @ret;
END;
END;
RETURN LEFT(@SearchedStr, @ret)
END;
如何通过点击按钮在文本框中显示结果?
答案 0 :(得分:0)
将变量声明为私有,就像表单中的第一个变量一样。在按钮点击事件上进行计算:
public partial class Form1 : Form
{
private int a, b, c;
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked) a = 5; else a = 0;
if (radioButton2.Checked) b = 5; else b = 0;
if (radioButton3.Checked) c = 5; else c = 0;
}
}
您可以使用String.Format
格式化输出:
textBox1.Text = String.Format("a is {0}, b is {1}, c is {2}", a, b, c);
如果使用VS2015字符串插值:
textBox1.Text = $"a is {a}, b is {b}, c is {c}";