将文字插入标签 [英] insert text to label

查看:93
本文介绍了将文字插入标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!




我想要的是,对于每个:1,2,3,4循环,它都会在之前添加一个数字,例如其计数,但会停在4.所以:1,2,3,4,11,12,13 ,14,21,22,23,24,31,32,33,34,41,42,43,44,111,112,113,114,121,122,123,124,131,132,133,134,141,142,143,144,211 ........
就像盘点一样,但用4个数字代替9.

而且我希望它像这样工作,每次我按下按钮时,我都希望它显示一个新的数字.

Hello!




What I want is that, for each time that : 1,2,3,4 loop it will ad a number before, like its counting but it stops at 4. so: 1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44,111,112,113,114,121,122,123,124,131,132,133, 134,141,142,143,144,211........
just like counting but with 4 numbers instead of 9.

And i want it to work like this, for each time that i press the button i want it to show a new number.

String[] text = { "1", "2", "3", "4" };
        int count = 0;

        private void button1_Click(object sender, EventArgs e)
        {
            if (count == text.Length)
            {
                count = 0;
                
            }
            label1.Text = text[(count % text.Length)];
            count++;

        } 




谢谢!




Thank you!

推荐答案

为什么不随便去:
Why not just go:
myLabel.Text = "My new text: " + myLabel.Text;




不,实际上我发现它不起作用!...就我而言-euhiemf 31分钟前".

那为什么不呢?什么无效"?




"No, actually i found out that it doesn''t work!... for my thing - euhiemf 31 mins ago"

So why not? What "doesn''t work"?

String[] text = { "1", "2", "3", "4" };
int count = 0;

private void button1_Click(object sender, EventArgs e)
{
    if (count == text.Length)
    {
        count = 0;

    }
    label1.Text = text[(count % text.Length)];
    count++;

}

-euhiemf 35分钟前

好的,这是一个代码片段.看来与您的问题无关.
您的片段仅在每次按下按钮时才将标签文本设置为不同的值.如果不打算这样做,那意味着要做什么? :laugh:
我想要的是,对于每次1,2,3,4循环,它都会在之前添加一个数字,例如其计数,但会停在4.因此:1,2,3,4,11, 12,13,14,21,22,23,24,31,32,33,34,41,42,43,44,111,112,113,114,121,122,123,124,131,132,133,134,141,142,143,144,211 ..... ;)-euhiemf 25分钟前"

哦,这就是全部:
您不能这么简单地做到这一点,因为您没有零可玩!所以.有点复杂...

- euhiemf 35 mins ago

Ok, so it''s a code fragment. It appears to have nothing to do with your question.
Your fragment just sets a label text to a different value each time a button is pressed. If it isn''t intended to do that, what is it meant to do? :laugh:
"what i want is that for each time that : 1,2,3,4 loop it will ad a number before, like its counting but it stops at 4. so: 1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44,111,112,113,114,121,122,123,124,131,132,133, 134,141,142,143,144,211........ just like counting but with 4 numbers instead of 9. ;) - euhiemf 25 mins ago"

Oh, is that all:
You can''t do that quite so simply, you have no zero to play with! So. it gets a bit complex...

int[] currentValue = new int[3] { 0, 0, 0 };
private void button1_Click(object sender, EventArgs e)
    {
    for (int i = 0; i < currentValue.Length; i++)
        {
        if (currentValue[i] != 4)
            {
            currentValue[i]++;
            break;      // No need to move next digit.
            }
        else
            {
            // Move the next highest digit.
            currentValue[i] = 1;
            }
        }
    string s = "";
    for (int i = currentValue.Length - 1; i >=0; i--)
        {
        s += currentValue[i].ToString();
        }
    label1.Text = s;


这只能处理三个四边形(不能再叫数字,"dig"从基数10开始),第一次按会将标签设置为"001",但是我要给您做点工作!


This only handles three quadits (Can''t call then digits, the "dig" comes from base ten) and the first press will set the label to "001", but I have to leave you some work!


显然您不能使用SelectionStart属性.
插入应该可以工作,它是一个String方法.

为什么不简单
Obviously you can''t use the SelectionStart property.
The Insert should work though, it''s a String method.

Why not simply
label1.Text = "labe" + label1.Text;


?

您是否看到过:转换到任何基础 [


?

Did you see this : Convert to any base[^]

Change your array to

string quat = IntToString(42, 
            new char[] { ''0'', ''1'', ''2'', ''3'', ''4'' };



将此函数放在您的代码中:



Put this function in your code :

public static string IntToString(int value, char[] baseChars)
{
    string result = string.Empty;
    int targetBase = baseChars.Length;

    do
    {
        result = baseChars[value % targetBase] + result;
        value = value / targetBase;
    }
    while (value > 0);

    return result;
}



现在重写您的函数:



Now rewrite your function :

private void button1_Click(object sender, EventArgs e)
{
    label1.Text = IntToString(count, quat);
    count++;

}



足够接近,未经测试,但大致正确:)



Close enough, not tested but about right :)


这篇关于将文字插入标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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