[英]Is it possible to set height and width of image which was assigned to a label dynamically
大家好,我正在使用下面的代碼將圖像附加到label
文本
lblPopUp.Text = "<img src='Popup(Images)/notfound.png' /> Access Denied,Contact Administrator";
加載時結果如下
是否可以更改以下內容,使文本和圖像看起來類似
如果我對您的理解正確,只需進行一些字符串操作即可完成您想要的操作。
碼:
lblPopup.Text = "<img src='Popup(Images)/notfound.png' /> 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的答案。
您可以使用<img>
標簽的height
和width
屬性設置高度和寬度:
lblPopUp.Text = "<img src='Popup(Images)/notfound.png' height='50px' width='50px' /> Access Denied,Contact Administrator";
或者,您可以使用style
屬性:
lblPopUp.Text = "<img src='Popup(Images)/notfound.png' style='height:50px; width:50px;' /> Access Denied,Contact Administrator";
 
來使您的對齊正確。
在您的<img>
標簽上添加一些padding-right
會更加容易和穩定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.