2012-02-02 41 views
0

大家好我使用下面的代码添加图像到label文本图像的宽度是否有可能设置高度和被分配到一个标签动态

lblPopUp.Text = "<img src='Popup(Images)/notfound.png' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator";

这导致了我如下的时候加载

enter image description here

是否有可能改变一些如下,这样的文字和图像看起来应该类似于什么

enter image description here

回答

2

如果我正确地理解了你,一个小小的字符串操作应该能够实现你想要的。

代码:

lblPopup.Text = "<img src='Popup(Images)/notfound.png' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator"; 
String strInsertStyle = " style=\"height: 100px; width: 100px;\""; 
int intInsertPoint = lblPopup.Text.IndexOf("<img") + 4; 
lblPopup.Text = lblPopup.Text.Substring(0, intInsertPoint) + strInsertStyle + lblPopup.Text.Substring(intInsertPoint); 

编辑: 我也假设你的意思是你想在以后添加的高度/宽度,与jadarnel27的答案,否则去。

1

您可以设置高度和宽度与<img>标签的heightwidth属性:

lblPopUp.Text = "<img src='Popup(Images)/notfound.png' height='50px' width='50px' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator"; 

或者,你可以使用style属性:

lblPopUp.Text = "<img src='Popup(Images)/notfound.png' style='height:50px; width:50px;' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator"; 


还有一件事:我会 强烈建议不要使用所有这些 &nbsp来确保您的对齐方式正确。在您的 <img>标签上放置一些 padding-right将会更容易和更稳定。

+0

为jquery的缺席事先道歉;-) – jadarnel27 2012-02-02 16:39:50