web| Control | display | string
We often need to display a paragraph on a line of text, and because of the uncertainty of Web page width, we arbitrarily adjust its width, usually make text to support the page or fold into many lines. By using CSS, we can limit the width to one line and hide the extra characters. For convenience, make a small Web control to use.
Using System;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.ComponentModel;
Namespace Cnblogs.birdshome.WebControls
{
/**////<summary>
Summary description for AutoLabel.
</summary>
[Defaultproperty ("Text"),
ToolBoxData ("<{0}:autolabel runat=server></{0}:autolabel>")]
public class AutoLabel:System.Web.UI.WebControls.Label
{
protected override void CreateChildControls ()
{
Base. CreateChildControls ();
This. Width = unit.percentage (100);
This. attributes["onmouseover"] =
"If" (This.clientwidth < this.scrollwidth) this.title = This.innertext; else this.title = '; ';
This. attributes.cssstyle["white-space"] = "nowrap";
This. attributes.cssstyle["Overflow"] = "hidden";
This. attributes.cssstyle["Text-overflow"] = "ellipsis";
}
}
}
AutoLabel inherits to the label control, the default width is "100%", and when the AutoLabel is placed in the container class element, the width of its contents is automatically adjusted by the container size. And when the AutoLabel appears with the "..." number, the mouse is placed above it, and its ToolTip automatically displays the full contents. The following figure: