簡體   English   中英

是否可以動態設置分配給標簽的圖像的高度和寬度

[英]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' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator";

加載時結果如下

在此處輸入圖片說明

是否可以更改以下內容,使文本和圖像看起來類似

在此處輸入圖片說明

如果我對您的理解正確,只需進行一些字符串操作即可完成您想要的操作。

碼:

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的答案。

您可以使用<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會更加容易和穩定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM