获取以像素为单位的动态增长的标签高度 [英] Get dynamically growing Label height in pixels

查看:86
本文介绍了获取以像素为单位的动态增长的标签高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况...

在按钮单击事件中,在文本框中输入的字符将显示在标签中.标签的宽度固定为ex,200px,但未设置标签的高度.

通过更改文本框中的字符,并触发按钮单击事件,标签将使用文本框中的文本填充.那时,标签的宽度将保持不变,但高度将根据在文本框中输入的字符数而动态变化.....

在这里,我需要获取按钮单击事件上的标签高度(以像素为单位)???????

在此先感谢您,有人可以帮助我吗????

Here is my scenario...

The characters that are entered in the text box will be displayed in the label at the button click event. Label is having fixed width for ex,200px but the height is not set for the label.

By changing the characters in the text box,and firing the button click event the label will get populated with the text from the text box. At that time label width will be constant but height will change dynamically according to the no of characters entered in the textbox.....

Here I need to get the label height in pixels on the button click event???????

Thanks in Advance ?Can Anyone help me????

推荐答案

使用 JavaScript .在click事件上,使用Javascript或jQuery较容易,以使您可以轻松地在DOM中获取标签对象,然后在控件中获取特定属性.根据需要显示,修改属性.
Use Javascript. On click event, use Javascript or jQuery whichever is easy for you to get the label object in DOM and then the specific property of the control. Show, modify the properties as per your need.


感谢指导....

我自己找到了解决方法.在这里,

Thankz for the guidance....

Myself found the solution.Here it is,

<pre lang="xml">Label1.Text = TextBox1.Text;<br />
        string txt = Label1.Text;<br />
        Font f = new Font("Times New Roman",14,GraphicsUnit.Pixel);<br />
        Bitmap bp = new Bitmap(1, 1);<br />
        Graphics gp = Graphics.FromImage(bp);<br />
        int height = (int)gp.MeasureString(txt,f,260).Height;<br />
        Response.Write("<script>alert(''Height is :-''+"+Convert.ToString(height)+");</script>");</pre><br />



根据svetlin的评论,它不会提供更准确的高度.
但这很有帮助....



As per the svetlin comment it won''t provide more accurate height.
But it mey be helpful....


这篇关于获取以像素为单位的动态增长的标签高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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