2015年11月5日 星期四

簡易計算基



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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            {
                label2.Text = Convert.ToString(double.Parse(textBox1.Text) + double.Parse(textBox2.Text));
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            label2.Text = Convert.ToString(double.Parse(textBox1.Text) - double.Parse(textBox2.Text));
        }

        private void button3_Click(object sender, EventArgs e)
        {
            label2.Text = Convert.ToString(double.Parse(textBox1.Text) * double.Parse(textBox2.Text));
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (double.Parse(textBox2.Text) == 0)
            {
                label2.Text = " ";
                MessageBox.Show("除數不可為 0");
                return;
            }
            label2.Text = Convert.ToString(double.Parse(textBox1.Text) / double.Parse(textBox2.Text));
        }

        private void button5_Click(object sender, EventArgs e)
        {

        }
    }
}

拉霸



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 WindowsFormsApplication2 { public partial class Form1 : Form { int c1 = 0, c2 = 0, c3 = 0, d1 = 0, d2 = 0, d3 = 0, radmoney1 = 100, radmoney2 = 100, radmoney3 = 100; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button4_Click(object sender, EventArgs e) { c1 = 0; c2 = 0; c3 = 0; d1 = 1; d2 = 2; d3 = 0; timer1.Enabled = true; timer2.Enabled = true; timer3.Enabled = true; Random rnd = new Random(); radmoney1 = rnd.Next(1, 101); radmoney2 = rnd.Next(1, 101); radmoney3 = rnd.Next(1, 101); button4.Text = radmoney1.ToString() + radmoney2.ToString() + radmoney3.ToString(); } private void timer1_Tick(object sender, EventArgs e) { c1 = c1 + 1; d1 = c1 % 2; if (c1 >= radmoney1) timer1.Enabled = false; button1.Text = d1.ToString(); } private void timer2_Tick(object sender, EventArgs e) { c2 = c2 + 1; d2 = c2 % 2; if (c2 >= radmoney2) timer2.Enabled = false; button2.Text = d2.ToString(); } private void timer3_Tick(object sender, EventArgs e) { c3 = c3 + 1; d3 = c3 % 2; if (c3 >= radmoney3) timer3.Enabled = false; button3.Text = d3.ToString(); } private void timer4_Tick(object sender, EventArgs e) { button4.Text = "start"; if (d1 == d2 && d2 == d3) { button5.Text = "win"; } else { button5.Text = "flaut"; } } } }

陣列數字排序



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 WindowsFormsApplication4 { public partial class Form1 : Form { Button[,] Buttons = new System.Windows.Forms.Button[5, 5]; int[] randomize = new int[5]; //宣告一個一維陣列 (用來存取變數的陣列) Random rnd = new Random(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { for (int i = 1; i < 5; i++) { for (int j = 1; j < 5; j++) { Buttons[i, j] = new Button(); Buttons[i, j].Size = new Size(50, 50); Buttons[i, j].Location = new Point(i * 50, j * 50); this.Controls.Add(Buttons[i, j]);//出現在畫面中 } } } private void button1_Click(object sender, EventArgs e) { int pro = 0, a = 0, b = 0, c = 0; for (int i = 1; i < 5; i++) { for (int j = 1; j < 5; j++) { pro = i; a = i + 4; b = i + 8; c = i + 12; Buttons[i, 1].Text = pro.ToString(); Buttons[i, 2].Text = a.ToString(); Buttons[i, 3].Text = b.ToString(); Buttons[i, 4].Text = c.ToString(); } } } } }

九宮格





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 WindowsFormsApplication1 { partial class Form1 { /// <summary> /// 設計工具所需的變數。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清除任何使用中的資源。 /// </summary> /// <param name="disposing">如果應該處置 Managed 資源則為 true,否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form 設計工具產生的程式碼 /// <summary> /// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器 /// 修改這個方法的內容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); this.button7 = new System.Windows.Forms.Button(); this.button8 = new System.Windows.Forms.Button(); this.button9 = new System.Windows.Forms.Button(); this.button10 = new System.Windows.Forms.Button(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(0, 0); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(86, 66); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; // // button2 // this.button2.Location = new System.Drawing.Point(83, 0); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(86, 66); this.button2.TabIndex = 1; this.button2.Text = "button2"; this.button2.UseVisualStyleBackColor = true; // // button3 // this.button3.Location = new System.Drawing.Point(166, 0); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(86, 66); this.button3.TabIndex = 2; this.button3.Text = "button3"; this.button3.UseVisualStyleBackColor = true; // // button4 // this.button4.Location = new System.Drawing.Point(0, 61); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(86, 66); this.button4.TabIndex = 3; this.button4.Text = "button4"; this.button4.UseVisualStyleBackColor = true; // // button5 // this.button5.Location = new System.Drawing.Point(83, 61); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(86, 66); this.button5.TabIndex = 4; this.button5.Text = "button5"; this.button5.UseVisualStyleBackColor = true; // // button6 // this.button6.Location = new System.Drawing.Point(166, 61); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(86, 66); this.button6.TabIndex = 5; this.button6.Text = "button6"; this.button6.UseVisualStyleBackColor = true; // // button7 // this.button7.Location = new System.Drawing.Point(0, 124); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(86, 66); this.button7.TabIndex = 6; this.button7.Text = "button7"; this.button7.UseVisualStyleBackColor = true; // // button8 // this.button8.Location = new System.Drawing.Point(83, 124); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(86, 66); this.button8.TabIndex = 7; this.button8.Text = "button8"; this.button8.UseVisualStyleBackColor = true; // // button9 // this.button9.Location = new System.Drawing.Point(166, 124); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(86, 66); this.button9.TabIndex = 8; this.button9.Text = "button9"; this.button9.UseVisualStyleBackColor = true; // // button10 // this.button10.Location = new System.Drawing.Point(338, 263); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(106, 82); this.button10.TabIndex = 10; this.button10.Text = "button10"; this.button10.UseVisualStyleBackColor = true; this.button10.Click += new System.EventHandler(this.button10_Click); // // pictureBox1 // this.pictureBox1.BackgroundImage = global::WindowsFormsApplication1.Properties.Resources._12202063_829626943802170_812264383_n; this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.pictureBox1.Location = new System.Drawing.Point(56, 227); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(220, 188); this.pictureBox1.TabIndex = 9; this.pictureBox1.TabStop = false; this.pictureBox1.UseWaitCursor = true; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(488, 448); this.Controls.Add(this.button10); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.button9); this.Controls.Add(this.button8); this.Controls.Add(this.button7); this.Controls.Add(this.button6); this.Controls.Add(this.button5); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.Windows.Forms.Button button5; private System.Windows.Forms.Button button6; private System.Windows.Forms.Button button7; private System.Windows.Forms.Button button8; private System.Windows.Forms.Button button9; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button button10; } }