使用动态标签 [英] working with dynamic label

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

问题描述





我有两个按钮(加载,向上)

当我按下加载按钮时,动态标签被加载为



label0

label1

label2

label3

label4

label5





然后我点击上面的任何标签并按下按钮它应该来吧第一个

例如:



如果我点击label4就应该这样,



as



输出:

label4

label0

label1

label2

label3

label5



I have two buttons(load,up)
when i press load button , dynamic labels are loaded as

label0
label1
label2
label3
label4
label5


then i click any label in that from above and press up button it should come first
example:

wen i click label4 it should come like this,

as

output:
label4
label0
label1
label2
label3
label5

推荐答案

而不是实际移动标签,我建议你最好只需要移动标签内容 - 它的Text属性 - 这样做起来容易得多,并且在发生这种情况时可能看起来更好。它也是一段代码:

Rather than actually moving the labels, I would suggest you would need better off just moving the label content - it's Text property - which is a lot easier to do, and will probably look better while it is happening as well. It's also a piece of came to code:
string temp = label1.Text;
Label1.Text = label2.Text;
Label2.Text = label3.Text;
...
Label7.Text = label8.Text;
Label8.Text = temp;


您可以动态添加标签,如下图所示:



You can add dynamically label to you form like below :

static int labelID;
        protected void btnload_Click(object sender, EventArgs e)
        {
            Label label = new Label();
            label.ID = "Label" + labelID;
            label.Text = "Label" + labelID;
            form1.Controls.Add(label);
            labelID++;
        }





然后提升标签使用解决方案1,这是更好,更简单的方法。



如果有帮助,请接受答复并投票。



Then for moving up label use solution 1 that is better and easy way.

Accept as answer and vote if help to you.


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

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