web控件实验报告 含代码.doc_第1页
web控件实验报告 含代码.doc_第2页
web控件实验报告 含代码.doc_第3页
web控件实验报告 含代码.doc_第4页
web控件实验报告 含代码.doc_第5页
已阅读5页,还剩8页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验名称基本控件实验实验目的熟练掌握各种控件的使用及事件的代码编写,能够掌握老师上课所讲的内容。实验设备Microsoft Visual Studio 2010实验过程(要求根据实现进行的过程,常用文字、图、表等描述,可另附页)1、 创建Web窗体,使用Label控件显示文字“现在的时间是:”以及具体时间,自行设置其文字颜色、字体、字号、背景色等属性;增加一个Button按钮,要求当按下该按钮后能改变Label控件上文字的字体、字号、颜色和边框样式。如:代码为: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 void Page_Load(object sender, EventArgs e) Label1.Text = 现在的时间是 + DateTime.Now.ToString(); protected void Button1_Click(object sender, EventArgs e) Label1.Font.Name = 宋体; Label1.Font.Size = 12; Label1.BorderStyle = BorderStyle.Dotted; Label1.BorderColor =System.Drawing.Color.Blue; Label1.BackColor = System.Drawing.ColorTranslator.FromHtml(#cc00ff); Label1.ForeColor = System.Drawing.Color.Brown; Button1.Text = 已改变样式; Button1.Enabled = false; 运行结果为:2、 创建Web窗体,该窗体上有一个TextBox控件和一个Button控件,要求每当用户单击按钮时,文本框会显示数据反映单击的次数。如: 代码为:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default2 : System.Web.UI.Page static int i; protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) TextBox1.Text = 0; protected void Button1_Click(object sender, EventArgs e) i = i + 1; TextBox1.Text = i.ToString(); 运行结果为:3、 创建Web窗体,其中包含三种不同类型的TextBox,分别为单行、密码和多行文本框,如果用户在密码框中输入的密码少于8位或大于15位,就弹出错误提示对话框,运行效果如下:代码为:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default3 : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) protected void TextBox2_TextChanged(object sender, EventArgs e) if (TextBox2.Text.Length 15) Response.Write(alert(密码?必?须?在8位?到?15位?之?间?); protected void Button1_Click(object sender, EventArgs e) protected void TextBox3_TextChanged(object sender, EventArgs e) 运行结果为:4、4、利用image控件、button控件实现图片的更换,显示比例的调整。代码为:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default4 : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) protected void Button1_Click(object sender, EventArgs e) if (Image1.ImageUrl = /image/1.jpg) Image1.ImageUrl = /image/2.jpg; else Image1.ImageUrl = /image/1.jpg; protected void TextBox1_TextChanged(object sender, EventArgs e) protected void Button2_Click(object sender, EventArgs e) double h = Image1.Height.Value; double w = Image1.Width.Value; double bl = Convert.ToDouble(TextBox1.Text); Image1.Height = new Unit(h * bl); Image1.Width = new Unit(w * bl); 运行结果为:5、 利用linkbutton控件的command事件实现图像的变换。代码为:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default5 : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) protected void LinkButton_Command(object sender, CommandEventArgs e) Image1.ImageUrl = /image/ + e.CommandName.ToString() + .jpg; protected void LinkButton2_Click(object sender, EventArgs e) 运行结果为:6、使用CheckBox和RadioButton控件进行男女生喜欢的手机品牌调查,单击“确定”按钮后,将用户选择的信息显示出来,如:代码为:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default6 : System.Web.UI.Page protected void Button1_Click(object sender, EventArgs e) if (RadioButton1.Checked) Label1.Text = 你?是?男D生,?; else Label1.Text = 你?是?女?生,?; String s1,s2,s3; if (CheckBox1.Checked = true ) s1 = iphone; else s1 = ; if (CheckBox2.Checked = true) s2 = 三y星?; else s2 = ; if (CheckBox3.Checked = true) s3 = 小?米; else s3 = ; Label2.Text = 你?喜2欢?的?手?机是?:o+ s1 + s2 + s3; protected void RadioButton1_CheckedChanged(object sender, EventArgs e) protected void RadioButton2_CheckedChanged(object sender, EventArgs e) protected void CheckBox1_CheckedChanged(object sender, EventArgs e) protected void CheckBox2_CheckedChanged(object sender, EventArgs e) protected void CheckBox3_CheckedChanged(object sender, EventArgs e) 运行结果为:7、 使用CheckBoxList控件显示班长候选人,单击“投票”按钮,将选择的候选人的名字显示在Label控件中,运行效果如下:代码为:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default7 : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) protected void Button1_Click(object sender, Ev

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论