电子商务马志伟C#实验报告

 

 

河北科技大学理工学院

 

电子商务马志伟C#语言课程设计

 

 

 

专 业 班 级  电子商务L112         

学 生 姓 名    马志伟            

学       号   11L0207207         

指 导 教 师王玉恒陈军霞李庆恒 董绍辉 

 

 

2013 年 2 月  

 

 

 


目录

 

 

 

题目1:ListBox使用示例………………………………………………1

 

 

 

题目2:Timer使用示例…………………………………………………3

 

 

 

题目3:HscrollBar使用示例…………………………………………5

 

 

 

题目4:MessageBox使用示例…………………………………………8

 

 

 

 

 


题目1:ListBox

用户从列表框中选择月份,同时在文本框中显示选择的月份,单击按钮后判断显示该月份属于哪个季节。

 

                  各控件属性设置

控件类型

原控件名

属性

设置结果

Form

Form1

Name

frmMonth

Text

Month

TextBox

TextBox1

Name

txtMonth

ReadOnly

True

TextBox2

Name

txtSeason

ReadOnly

True

ListBox

ListBox1

Name

lstMonth

Items

一次添加“1”,“2”,“3”,“4”,“5”,“6”,“7“,”8“,”9“,”10“,”11“,”12“

Button

Button1

Name

btnSeason

Text

对应季节

 

代码如下:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

 

namespaceListBox

{

    public partial class frmMonth : Form

    {

       public frmMonth()

       {

           InitializeComponent();

       }

 

       

 

        private void lstMonth_SelectedIndexChanged(object sender, EventArgse)

       {

           txtMonth.Text = lstMonth.SelectedItem.ToString();

       }

 

       private voidbtnSeason_Click(object sender, EventArgs e)

       {

           switch(lstMonth.SelectedIndex)

           {

                case0:

                case1:

                case2:

                    txtSeason.Text ="您所选择的月份是春季";

                    break;

                case3:

 

                case4:

                case5:

                    txtSeason.Text = "您所选择的月份是夏季";

                    break;

                case6:

                case7:

                case8:

                    txtSeason.Text = "您所选择的月份是秋季";

                    break;

                default:

                    txtSeason.Text = "您所选择的月份是冬季";

                    break;

           }

 

       }

 

    }

}

 

 

 

运行结果:

 

题目2:Timer

设计一个时钟程序,将系统时间显示在文本框中,要求每秒钟更新一次时间。

                   各控件属性设置

控件类型

控件名称

属性

设置结果

Form

Form1

Name

frmShowTime

Text

Timer

Label

Label1

Text

当前时间:

TextBox

TextBox1

Name

txtShowTime

Timer

Timer1

Name

tmrShowTime

Interval

1000(即1秒)

 

代码如下:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

 

namespaceWindowsApplication3

{

    public partial class frmShowTime : Form

    {

       public frmShowTime()

       {

           InitializeComponent();

       }

 

       private voidlabel1_Click(object sender, EventArgs e)

       {

 

       }

 

       private voidfrmShowTime_Load(object sender, EventArgs e)

       {

           tmrShowTime.Enabled = true;

       }

 

       private voidtmrShowTime_Tick(object sender, EventArgs e)

       {

           txtShowTime.Text = System.DateTime.Now.ToString();

       }

    }

}

 

 

 

 

运行结果:

 

 

 

题目3:HscrollBar

设计一个调色板,用户单击三个滚动条两端的箭头按钮、直接拖动滚动条的滑块或单击滚动条滑竿时,均可以调整FormArgb()方法中对应的颜色值,从而使“颜色效果”区域中显示不同颜色。

 

                    各控件属性设置

控件类型

控件名称

属性

设置结果

From

From1

Text

frmColor

Text

HScrollBar

GroupBox

GroupBox1

Text

颜色效果

Label

Label1

Name

lblShowColor

Text

清空

AutoSize

False

BorderStyle

Fixed3D

Size

大致略小于框架控件

 

Label2

Name

lblRed

Text

红色值:

Label3

Name

lblGreen

Text

绿色值:

Label4

Name

lblBlue

Text

蓝色值:

HScrollBar

HScrollBar1

Name

hsRed

Minimum

0

Maximum

225

SmallChange

1

LargeChange

1

HScrollBar2

Name

hsGreen

Minimum

0

Maximum

225

SmallChange

1

LargeChange

1

HScrollBar3

Name

hsBlue

Minimum

0

Maximum

225

SmallChange

1

LargeChange

1

 

代码如下:usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

 

namespaceHScrollBar

{

    public partial class frmCorlor : Form

    {

        publicfrmCorlor()

       {

           InitializeComponent();

       }

       private voidfrmColor_Load(object sender, EventArgs e)

       {

           lblRed.Text = "红色值:" +hsbRed.Value.ToString();

           lblGreen.Text = "绿色值:" +hsbGreen.Value.ToString();

           lblBlue.Text = "蓝色值:"+hsbBlue.Value.ToString();

           changecolor();

       }

       void changecolor()

       {

           Color color = newColor();

           color = System.Drawing.Color.FromArgb

           (hsbRed.Value, hsbGreen.Value, hsbBlue.Value);

           lblShowColor.BackColor = color;

       }

 

       private voidhsbRed_Scroll(object sender, ScrollEventArgs e)

       {

           lblRed.Text = "红色值:" +hsbRed.Value.ToString();

           changecolor();

       }

 

       private voidhsbGreen_Scroll(object sender, ScrollEventArgs e)

       {

           lblGreen.Text = "绿色值:" +hsbGreen.Value.ToString();

           changecolor();

       }

 

       private voidhsbBlue_Scroll(object sender, ScrollEventArgs e)

       {

           lblBlue.Text = "蓝色值:" +hsbBlue.Value.ToString();

           changecolor();

       }

       

    }

}


题目4:MessageBox

在文本框中输入圆的半径和圆柱的高,然后再判断输入的数值是否正确,若输入的数值大于0,则计算圆柱的体积并使用消息框输出,若输入的数值小于0,则使用消息框询问是否重新输入,如果选择“是”,则清空文本框,等待重新输入,否则不作任何处理。

                    各控件属性设置

控件类型

控件名称

属性

设置结果

Form

Form1

Name

frmMessageBox

Text

UseMessageBox

Label

Label1

Text

输入圆的半径:

Label2

Text

输入圆柱的高:

TextBox

TextBox1

Name

txtRadius

TextBox2

Name

txtgao

Button

Button1

Name

btnShowResult

Text

查看结果

代码如下:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

 

namespaceUseMassageBox

{

    public partial class frmMessageBox :Form

    {

       public frmMessageBox()

       {

           InitializeComponent();

       }

       private voidbutton1_Click(object sender, EventArgs e)

       {

           float radius;

           float gao;

           float area;

           constfloat PI = 3.14F;

           gao = float.Parse(txtgao.Text);

           radius = float.Parse(txtRadius.Text);

           if (radius > 0 & gao > 0)

           {

                area = PI * radius * radius *gao;

                MessageBox.Show("圆柱的体积为:" + area.ToString(), "输出结果");

 

           }

           else

           {

                if(MessageBox.Show("输入的数字有误,重新输入?","输入错误",

                MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)

                {

                   txtRadius.Text = "";

                    txtgao.Text = "";

                    txtRadius.Focus();

                }

 

           }

       }

 

    }

}

 

运行结果:

       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值