文本框控件TextBox, TextMode:值SingleLine表示单行文本,MultiLine表示多行文本,等等。
下拉列表控件DropDownList,单项按钮控件Radio,复选框控件CheckBox,等
###以一个文本框的实现,来说明这些控件吧。
用vs2015建立完整,过程看图。 新建------>网站 选择C#,ASP.NET空网站 添加---->新添新项 选择Web窗体 展开相关文件 工具箱,有服务器控件,点击TextBox 编辑TextBox1的属性 添加CheckBox控件 设置CheckBox的名字
###通过控件等得到的aspx文件。 ```HTML <%@ Page Language="C#" AutoEventWireup="true" CodeFile="days_20171107.aspx.cs" Inherits="days_20171107" %>
文本框选择:<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Text="加粗" />
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" Text="斜体" />
<asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="True" Text="下划线" />
复制代码
字体:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem Selected="True">12</asp:ListItem> asp:ListItem16</asp:ListItem> asp:ListItem25</asp:ListItem> asp:ListItem30</asp:ListItem> asp:ListItem36</asp:ListItem> </asp:DropDownList> 颜色:<asp:RadioButton ID="Red" runat="server" AutoPostBack="True" ForeColor="#FF5050" GroupName="color" Text="红色" /> <asp:RadioButton ID="Green" runat="server" AutoPostBack="True" ForeColor="Lime" GroupName="color" Text="绿色" /> <asp:RadioButton ID="Yellow" runat="server" AutoPostBack="True" ForeColor="Yellow" GroupName="color" Text="黄色" /> <asp:RadioButton ID="Blue" runat="server" AutoPostBack="True" Checked="True" ForeColor="Blue" GroupName="color" Text="蓝色" />
<asp:TextBox ID="TextBox1" runat="server" Height="385px" OnTextChanged="Page_Load" TextMode="MultiLine" Width="828px"></asp:TextBox>
</div>
</form>
复制代码
###这是C#相关代码
```C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
public partial class days_20171107 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (CheckBox1.Checked)
TextBox1.Font.Bold = true;
else
TextBox1.Font.Bold = false;
TextBox1.Font.Italic = CheckBox2.Checked;
TextBox1.Font.Underline = CheckBox3.Checked;
TextBox1.Font.Size = int.Parse(DropDownList1.Text);
if (Red.Checked)
TextBox1.ForeColor = Color.Red;
else if (Green.Checked)
TextBox1.ForeColor = Color.Green;
else if (Yellow.Checked)
TextBox1.ForeColor = Color.Yellow;
else
TextBox1.ForeColor = Color.Blue;
}
}
复制代码
###结果如下:
c#语法还有待深入,jsp和asp,真是。。。。。。。
###代码百度云