利用Lable控件輸出九九乘法表,具體內(nèi)容如下
首先建立一個(gè)空網(wǎng)站,之后選擇添加新項(xiàng),添加一個(gè)Web窗體。
進(jìn)入.aspx文件之后,在設(shè)計(jì)界面中添加9個(gè)Lable控件。Lable控件在標(biāo)準(zhǔn)組中。得到的源代碼是這樣的。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm4.aspx.cs" Inherits="WebForm4" %> <!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:Table ID = "Table1" runat = "server" > </ asp:Table > < asp:Table ID = "Table2" runat = "server" > </ asp:Table > < asp:Table ID = "Table3" runat = "server" > </ asp:Table > < asp:Table ID = "Table4" runat = "server" > </ asp:Table > < asp:Table ID = "Table5" runat = "server" > </ asp:Table > < asp:Table ID = "Table6" runat = "server" > </ asp:Table > < asp:Table ID = "Table7" runat = "server" > </ asp:Table > < asp:Table ID = "Table8" runat = "server" > </ asp:Table > < asp:Table ID = "Table9" runat = "server" > </ asp:Table > </ div > </ form > </ body > </ html > |
接著,要實(shí)現(xiàn)九九乘法表的創(chuàng)建,還需要在.aspx.cs文件添加代碼。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class WebForm4 : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { if (!IsPostBack) { Table table = new Table(); for ( int r = 0; r < 9; r++) { TableRow tr = new TableRow(); table.Rows.Add(tr); for ( int c = 0; c < r + 1; c++) { TableCell tc = new TableCell(); tr.Cells.Add(tc); if (c <= r) table.Rows[r].Cells[c].Text = ((r + 1)).ToString() + '×' + ((c + 1)).ToString() + '=' + (((r + 1) * (c + 1))).ToString(); } } form1.Controls.Add(table); } } } |
運(yùn)行程序,得到的效果圖如下:
這樣,一個(gè)九九乘法表就輸出來啦!
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:http://blog.csdn.net/chinnell/article/details/78449062