铵钮的文本换行显示
看看下动画效果:
C#有一个类System.Environment,它有一个NewLine静态Get属性,即可实现换行。
OK,知道有这个功能后,我们就可以文本换行了,我们在Default.aspx放一个按钮,参考下第12行。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6 <head runat="server">
7 <title></title>
8 </head>
9 <body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:Button ID="Button1" runat="server" Text="" />
13 </div>
14 </form>
15 </body>
16 </html>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6 <head runat="server">
7 <title></title>
8 </head>
9 <body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:Button ID="Button1" runat="server" Text="" />
13 </div>
14 </form>
15 </body>
16 </html>
然后在cs写:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Button1.Text = "Hi,Insus.NET," + Environment.NewLine + "请用Mouse点击我";
this.Button1.Click +=Button1_Click;
}
protected void Page_Load(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script>alert('看看,按钮的Text换行显示。');</script>");
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Button1.Text = "Hi,Insus.NET," + Environment.NewLine + "请用Mouse点击我";
this.Button1.Click +=Button1_Click;
}
protected void Page_Load(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script>alert('看看,按钮的Text换行显示。');</script>");
}
}
下面补充于2012-11-01 20:29,可以用此方法实现垂直铵钮。