2012-02-02 3 views
0

안녕 나는 label 텍스트에 이미지를 추가하려면 아래의 코드를 사용하고 모든 할당 된 이미지의 폭을 설정하는 것입니다 로드이 가능</p> <p><code>lblPopUp.Text = "<img src='Popup(Images)/notfound.png' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator";</code></p> <p>이 따를 때 나를 결과 높이와 라벨 동적으로

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' style='height:50px; width:50px;' />&nbsp;&nbsp;&nbsp;&nbsp; Access Denied,Contact Administrator"; 


: 당신은 style 속성을 사용할 수

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

대안을 한 가지 더 : 나는 강력하게 추천 정보를 모두 사용하여 &nbsp을 (를) 사용하는 것이 좋습니다. 일부 padding-right<img> 태그에 넣는 것이 훨씬 쉽고 훨씬 안정적입니다.

+0

미리 jQuery가 없으면 사과드립니다. ;-) – jadarnel27

관련 문제