文本框控件TextBox, TextMode:值SingleLine表示單行文本,MultiLine表示多行文本,等等。
textbox.jpg
下拉列表控件DropDownList,單項按鈕控件Radio,復選框控件CheckBox,等
以一個文本框的實現,來說明這些控件吧。
用vs2015建立完整,過程看圖。
新建------>網站
1.jpg
選擇C#,ASP.NET空網站
2.jpg
添加---->新添新項
3.jpg
選擇Web窗體
4.jpg
展開相關文件
5.jpg
工具箱,有服務器控件,點擊TextBox
6.jpg
編輯TextBox1的屬性
7.jpg
添加CheckBox控件
8.jpg
設置CheckBox的名字
9.jpg
10.jpg
通過控件等得到的aspx文件。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="days_20171107.aspx.cs" Inherits="days_20171107" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
文本框選擇:<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:ListItem>16</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>36</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="藍色" />
<br />
<asp:TextBox ID="TextBox1" runat="server" Height="385px" OnTextChanged="Page_Load" TextMode="MultiLine" Width="828px"></asp:TextBox>
</div>
</form>
</body>
</html>
這是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;
}
}
結果如下:
11.jpg
12.jpg
c#語法還有待深入,jsp和asp,真是。。。。。。。