如何使用C#在Asp.net中设置动态标签的位置 [英] How to set the position of a Dynamic Label in Asp.net using C#

查看:75
本文介绍了如何使用C#在Asp.net中设置动态标签的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我创建了一个名为lblShow的动态标签。现在我想在.cs文件中设置该标签的位置。我应该怎么做?

In my application i create one dynamic label called lblShow. Now i want to set the position of that label in .cs file.How should i do this?

推荐答案

你可以使用Control.Style属性来设置一个样式控制。

例如

You can use Control.Style Property to set style of a control.
E.g.
Label lbl = new Label();
lbl.Style[HtmlTextWriterStyle.Position] = "Absolute";
lbl.Style[HtmlTextWriterStyle.Top] = "10px";







欲了解更多详情,请点击此处


你可以通过manu方式实现这个目标



1->

添加一个占位符并在运行时放置标签

You can achive this with manu ways

1->
add a placeholder and put your label at runtime
<asp:placeholder id="PlaceHolder1" runat="server" xmlns:asp="#unknown">


</asp:placeholder>


CS代码中的



in CS code

PlaceHolder1.Controls.Add(lbl);





2->在运行时设置CSS



2-> set CSS at runtime

style1
{
position:absolute;
left:100px;
top:150px;
}




$ CS $ b CS代码

使用



in CS code
use

Label1.CssClass = "style1";


尝试

lblShow.Location =新点(eX,eY);



lblShow.Location =新点(100,200);





将起作用:)
try
lblShow.Location=new point(e.X,e.Y);
or
lblShow.Location=new point(100,200);


will work :)


这篇关于如何使用C#在Asp.net中设置动态标签的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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