ASP.NET 学习中。。。

开始学习C#了,做的第一款垃圾软件:

http://download.csdn.net/detail/zhoujiachengdhy/7226423

源码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PictureViewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void showButton_Click(object sender, EventArgs e)
        {
            /* Show the Open File dialog. If the user clicks OK, load the
             picture that the user chose.
             */
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Load(openFileDialog1.FileName);
            }
        }

        private void clearButton_Click(object sender, EventArgs e)
        {
            // Clear the picture.
            pictureBox1.Image = null;
        }

        private void backgroundButton_Click(object sender, EventArgs e)
        {
            // Show the color dialog box. If the user clicks OK, change the
            // PictureBox control's background to the color the user chose.
            if (colorDialog1.ShowDialog() == DialogResult.OK)
                pictureBox1.BackColor = colorDialog1.Color;
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            // Close the form.
            this.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            // If the user selects the Stretch check box, 
            // change the PictureBox's
            // SizeMode property to "Stretch". If the user clears 
            // the check box, change it to "Normal".
            if (checkBox1.Checked)
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            else
                pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
        }

    }
}

第二款垃圾软件

http://download.csdn.net/detail/zhoujiachengdhy/7228407

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Math_Quiz
{
    public partial class Form1 : Form
    {
        Random randomizer = new Random();//随机数生成器
        int addend1, addend2;
        int minu1, minu2;
        int mul1, mul2;
        int div1, div2;
        int timeleft;
        public void StartTheQuiz()
        {
            //+
            addend1 = randomizer .Next(51);
            addend2 = randomizer.Next(51);
            plusLeftLabel.Text = addend1.ToString();//将数字转换为文本
            plusRightLabel.Text = addend2.ToString();
            sum.Value = 0;

            //-
            minu1 = randomizer.Next(1, 101);
            minu2 = randomizer.Next(1, minu1);
            minusLeftLabel.Text = minu1.ToString();
            minusRightLabel.Text = minu2.ToString();
            difference.Value = 0;

            //*
            mul1 = randomizer .Next(51);
            mul2 = randomizer.Next(51);
            mulLeftLabel.Text = mul1.ToString();
            mulRightLabel.Text = mul2.ToString();
            product.Value = 0;

            // /
            div1 = randomizer.Next(2, 51);
            int temp = randomizer.Next(2, 51);
            div2 = div1 * temp;
            dividedRightLabel.Text = div1.ToString();
            dividedLeftLabel.Text = div2.ToString();
            quotient.Value = 0;

            //timer
            timeleft = 10;
            timeLabel.Text = "10 seconds";
            timer1.Start();
        }
        /*
         在此示例中,您调用了 randomizer.Next(51)。 您使用了 51 而不是 50,
         以便两个随机数相加所得的答案介于 0 到 100 之间。 如果将 50 传递给 Next() 方法,
         则此方法会选择一个介于 0 到 49 之间的数字,因此可能得到的最大答案是 98,而不是
         100。 在执行此方法中的前两个语句后,这两个整型变量(addend1 和 addend2)都将保
         留一个 0 到 50 之间的随机数。
        */
        private bool Checkans()
        {
            if( (addend1 + addend2 == sum.Value)&&(minu1 - minu2 == difference .Value)&&(mul1*mul2==product .Value)&&(div2==div1*quotient.Value)) 
                return true;
            else return false;
        }
        

        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void sum_ValueChanged(object sender, EventArgs e)
        {

        }

        private void startButton_Click(object sender, EventArgs e)
        {
            StartTheQuiz();
            startButton.Enabled = false; //使测验对象在测验期间不能选择此按钮。
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Checkans())
            {
                timer1.Stop();
                MessageBox.Show("You got all the answer right !", "Congratulations !");
                startButton.Enabled = true;
            }
            else if (timeleft > 0)
            {
                timeleft--;
                timeLabel.Text = timeleft + " seconds";
            }
            else
            {
                timer1.Stop();
                timeLabel.Text = "Time is up !";
                MessageBox.Show("You didn't finish in time.", "Sorry");
                sum.Value = addend1 + addend2;
                difference.Value = minu1 - minu2;
                product.Value = mul1 * mul2;
                quotient.Value = div2 / div1;
                startButton.Enabled = true;
            }
        }

        private void answer_Enter(object sender, EventArgs e)
        {
            NumericUpDown answerBox = sender as NumericUpDown;
            if (answerBox != null)
            {
                int lengthOfAnswer = answerBox.Value.ToString().Length;
                answerBox.Select(0, lengthOfAnswer);
            }
        }
    }
}


第三款垃圾软件

http://download.csdn.net/detail/zhoujiachengdhy/7233765

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
/*
1. 当玩家单击其中一个带有隐藏图标的方块时,程序通过将图标颜色更改为黑色来向玩家显示该图标。
2. 然后玩家单击另一个隐藏的图标。
3. 如果图标互相匹配,则它们保持可见。 如果不匹配,则两个图标都会再次隐藏。 
 */

namespace Matching
{
    public partial class Form1 : Form
    {

        int timespent;

        Random random = new Random();
        List<string> icons = new List<string>()
        {
            "!","N",",","k","b","v","w","z",
            "!","N",",","k","b","v","w","z"
        };
        /*
         列表中的项目称为“元素”,每个列表只包含一种元素。 所以数字列表只包含数字 - 您不能向其中添加文本。 同样,您也不能向 true/false 值列表添加数字。
         */
        private void iTOsquares()//
        {
            foreach (Control control in tableLayoutPanel1.Controls)//使用 foreach 循环重复执行相同操作
            {
                Label iconLabel = control as Label;
                if (iconLabel != null)
                {
                    int ranNum = random.Next(icons.Count);
                    iconLabel.Text = icons[ranNum];
                    iconLabel.ForeColor = tableLayoutPanel1.BackColor;
                    iconLabel.BackColor = Color.Transparent;
                    icons.RemoveAt(ranNum);
                }
            }
        }

        //确定前两个被点击的标签,并一起消失;
        Label fisChick = null,secChick = null;
        public Form1()
        {
            InitializeComponent();
            iTOsquares();
            MessageBox.Show("将所有图标两两匹配后即可...", "游戏规则");
        }

        private void lable_chick(object sender, EventArgs e)
        {
            if (timer1.Enabled ==true) return;

            Label chick =sender  as Label;
            if (chick != null)
            {
                if (chick.ForeColor == Color.Black) return;
                //如果已经为黑色,则该图标已被单击,因此该方法完成。
                if (fisChick == null)
                {
                    fisChick = chick;
                    fisChick.ForeColor = Color.Black;
                    return;
                }
                //如果该图标尚未被单击,它会将其文本颜色更改为黑色。

                secChick = chick;
                secChick.ForeColor = Color.Black;

                CheckForWiner();

                if (fisChick.Text == secChick.Text)
                {
                    fisChick = null;
                    secChick = null;
                    return;
                }

                timer1.Start();
            }
            
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            fisChick.ForeColor = tableLayoutPanel1.BackColor;
            secChick.ForeColor = tableLayoutPanel1.BackColor;
            //两个图标都藏起来

            fisChick = null;
            secChick = null;
        }
        private void CheckForWiner()
        {
            foreach (Control control in tableLayoutPanel1.Controls)
            {
                Label iconLabel = control as Label;
                if (iconLabel != null)
                {
                    if (iconLabel.ForeColor == tableLayoutPanel1.BackColor) return;
                }
            }
            MessageBox.Show("You matched all the icons !", "Congratulations !");
            Close();
        }

        private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
        {
           // 单元格重绘 
           Pen pp = new Pen(Color.Black); 
            e.Graphics.DrawRectangle(pp, e.CellBounds.X, e.CellBounds.Y, e.CellBounds.X + e.CellBounds.Width - 1, e.CellBounds.Y + e.CellBounds.Height - 1); 

        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void timeLabel_Click(object sender, EventArgs e)
        {

        }
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值