?? 19vb.aspx
字號:
<%@ Page Language="VB" Debug="true"%>
<%@ Import Namespace="System.Data" %>
<html>
<title>第十九例 LinkButton ImageButton ListBox Label控件的使用</title>
<head>
<script language="VB" runat="server">
Dim Shared a As Integer
Dim Shared b As Integer
Dim Shared c As Integer
Dim Shared d As Integer
'定義四個靜態全局變量,用以代表四個隨機數
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack then
Dim dt As ArrayList = new ArrayList()
dt.Add("+")
dt.Add("-")
ListBox1.DataSource = dt
ListBox1.DataBind
ListBox2.DataSource = dt
ListBox2.DataBind
ListBox3.DataSource = dt
ListBox3.DataBind
End If
End Sub '頁面初始化,對各ListBox控件綁定數據
Function Cal1(sender As ListBox,a As Integer,b As Integer) As Integer
If sender.SelectedIndex=0 then
Return a+b
Else
Return a-b
End If
End Function '定義了一個運算函數
Sub ImageButton_Click(sender as object,e as ImageClickEventArgs)
Label6.text=""
Randomize
a = int(9*rnd()+1)
b = int(9*rnd()+1)
c = int(9*rnd()+1)
d= int(9*rnd()+1)
Label1.Text = a.toString
Label2.Text = b.toString
Label3.Text = c.toString
Label4.Text = d.toString
If a+b+c+d <24 then
Label5.text="無解!"
return
Else If a+b+c+d>24 then
If a+b+c-d <> 24 then
Label5.text="無解!"
return
Else If a+b-c+d <> 24 then
Label5.text="無解!"
return
Else If a-b+c+d <> 24 then
Label5.text="無解!"
return
End If
End If
Label5.text=" = 24"
ImageButton1.visible=false
End Sub 'ImageButton事件,用來生成隨機數,并進行校驗
Sub s1(sender as object,e as EventArgs)
If Cal1(Listbox3,Cal1(Listbox2,Cal1(Listbox1,a,b),c),d)=24 then
ImageButton1.visible=true
Label6.text="輸入正確!"
Else
ImageButton1.visible=false
Label6.text="輸入錯誤,請重新輸入!"
end If
End Sub '當有解時,看輸入是否正確
</script>
</head>
<body>
<form runat="server">
<h3><font face="Verdana">第十九例 LinkButton ImageButton ListBox Label控件的使用</font></h3>
<asp:Label id="Label1" Font-Size="14pt" runat="server"/>
<asp:ListBox id="ListBox1" Rows="1" Width="50px" SelectionMode="Single" runat="server"/>
<asp:Label id="Label2" Font-Size="14pt" runat="server"/>
<asp:ListBox id="ListBox2" Rows="1" Width="50px" SelectionMode="Single" runat="server"/>
<asp:Label id="Label3" Font-Size="14pt" runat="server"/>
<asp:ListBox id="ListBox3" Rows="1" Width="50px" SelectionMode="Single" runat="server"/>
<asp:Label id="Label4" Font-Size="14pt" runat="server"/>
<asp:Label id="Label5" runat="server"> = 24</asp:label>
<asp:LinkButton id="LinkButton1" Text="提交" Font-Name="Verdana" Font-Size="14pt" runat="server" onclick="s1"/>
<asp:ImageButton id="imagebutton1" runat="server" AlternateText="ImageButton 1" ImageAlign="left" ImageUrl="button1-1.gif" onmouseover="this.src='button1-2.gif';" onmouseout="this.src='button1-1.gif';" OnClick="ImageButton_Click"/>
<br>
<asp:Label id="Label6" runat="server"/>
</form>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -