檔案連結
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace WindowsGame1
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
Texture2D ball;
Texture2D background;
AnimatedTexture aniTex;
Vector2 ballPosition;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
spriteBatch = new SpriteBatch(GraphicsDevice);
ballPosition = new Vector2(20, 20);
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("spritefont1");
spriteBatch = new SpriteBatch(GraphicsDevice);
ball = Content.Load<Texture2D>("ball");
spriteBatch = new SpriteBatch(GraphicsDevice);
background = Content.Load<Texture2D>("B1_nebula01");
spriteBatch = new SpriteBatch(GraphicsDevice);
aniTex = new AnimatedTexture(Content.Load<Texture2D>("doing_magic"), 3, 80);
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
aniTex.Update(gameTime);
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(background, Vector2.Zero, Color.White);
spriteBatch.Draw(ball, ballPosition, Color.White);
aniTex.Render(spriteBatch, Vector2.Zero, Color.White);
spriteBatch.DrawString(font, "kuo chi yuan <kax0205x@hotmail.com>", new Vector2(90, 500), Color.Black);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
class1 中
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace WindowsGame1
{
class AnimatedTexture
{
private Texture2D aniTex;
private int CurrentFrame = 0;
private int numberOfFrames = 0;
private int msBetweenFrames = 0;
private Rectangle rect;
private int width = 0;
private int height = 0;
float timer = 0;
public AnimatedTexture(Texture2D texture, int numFrames, int msBetweenFrames)
{
this.aniTex = texture; this.numberOfFrames = numFrames;
this.msBetweenFrames = msBetweenFrames;
this.width = texture.Width / numberOfFrames;
this.height = texture.Height;
// Init rectangle
rect.X = 0;
rect.Y = 0;
rect.Width = width;
rect.Height = height;
}
public void Update(GameTime gametime)
{
timer += gametime.ElapsedGameTime.Milliseconds;
if (timer >= msBetweenFrames)
{
timer = 0;
if (CurrentFrame++ == numberOfFrames - 1)
CurrentFrame = 0;
rect.X = CurrentFrame * width;
rect.Y = 0;
}
}
public void Render(SpriteBatch sb, Vector2 position, Color color)
{
sb.Draw(aniTex, position, rect, color, 0, Vector2.Zero, 2.0f, SpriteEffects.None, 0);
}
}
}
2010年11月26日 星期五
2010年11月18日 星期四
2010-11-18 考試 紅綠燈
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
int i;
int j;
public Form1()
{
InitializeComponent();
i=0;
j = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
i++;
i = i % 6;
label1.Text = Convert.ToString(i);
j++;
j=j%6;
switch(j)
{
case 0:
button1.Enabled=true;
button2.Enabled = false;
button3.Enabled = false;
break;
case 1:
button1.Enabled = false;
button2.Enabled=true;
button3.Enabled = false;
break;
case 2:
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled=true;
break;
case 3:
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
break;
case 4:
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
break;
case 5:
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
break;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int i;
int j;
public Form1()
{
InitializeComponent();
i=0;
j = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
i++;
i = i % 6;
label1.Text = Convert.ToString(i);
j++;
j=j%6;
switch(j)
{
case 0:
button1.Enabled=true;
button2.Enabled = false;
button3.Enabled = false;
break;
case 1:
button1.Enabled = false;
button2.Enabled=true;
button3.Enabled = false;
break;
case 2:
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled=true;
break;
case 3:
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
break;
case 4:
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
break;
case 5:
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
break;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
2010年11月12日 星期五
11-12 計算機 正確
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public string str = ""; //把數字鍵字串存起來
public double ans = 0;//佔存變數
public int how = 0;//判斷按下+ - * /
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button16_Click(object sender, EventArgs e)
{
str = ""; //顯示0
textBox1.Text = "0";
}
private void button1_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵1
str += "1";
textBox1.Text = str;//顯示字串內容
}
private void button2_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵2
str += "2";
textBox1.Text = str;
}
private void button3_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵3
str += "3";
textBox1.Text = str;
}
private void button4_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "4";
textBox1.Text = str;
}
private void button5_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "5";
textBox1.Text = str;
}
private void button6_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "6";
textBox1.Text = str;
}
private void button7_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "7";
textBox1.Text = str;
}
private void button8_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "8";
textBox1.Text = str;
}
private void button9_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "9";
textBox1.Text = str;
}
private void button15_Click(object sender, EventArgs e)
{
if (str != "")//點擊=鍵
{
if (how == 1) { ans += Convert.ToDouble(str); }//轉換成浮點數
else if (how == 2) { ans -= Convert.ToDouble(str); }
else if (how == 3) { ans *= Convert.ToDouble(str); }
else if (how == 4) { ans /= Convert.ToDouble(str); }
else if (ans == 0) { ans = Convert.ToDouble(str); }
else ans = Convert.ToDouble(str);
}
how = 0;//再儲存使用者所按下的運算元
str = Convert.ToString(ans);
textBox1.Text = str;
label1.Text = "=";
}
private void button11_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 1;
str = "";
}
private void button12_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 2;
str = "";
}
private void button13_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 3;
str = "";
}
private void button14_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 4;
str = "";
}
private void button10_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "0";
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public string str = ""; //把數字鍵字串存起來
public double ans = 0;//佔存變數
public int how = 0;//判斷按下+ - * /
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button16_Click(object sender, EventArgs e)
{
str = ""; //顯示0
textBox1.Text = "0";
}
private void button1_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵1
str += "1";
textBox1.Text = str;//顯示字串內容
}
private void button2_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵2
str += "2";
textBox1.Text = str;
}
private void button3_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵3
str += "3";
textBox1.Text = str;
}
private void button4_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "4";
textBox1.Text = str;
}
private void button5_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "5";
textBox1.Text = str;
}
private void button6_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "6";
textBox1.Text = str;
}
private void button7_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "7";
textBox1.Text = str;
}
private void button8_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "8";
textBox1.Text = str;
}
private void button9_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "9";
textBox1.Text = str;
}
private void button15_Click(object sender, EventArgs e)
{
if (str != "")//點擊=鍵
{
if (how == 1) { ans += Convert.ToDouble(str); }//轉換成浮點數
else if (how == 2) { ans -= Convert.ToDouble(str); }
else if (how == 3) { ans *= Convert.ToDouble(str); }
else if (how == 4) { ans /= Convert.ToDouble(str); }
else if (ans == 0) { ans = Convert.ToDouble(str); }
else ans = Convert.ToDouble(str);
}
how = 0;//再儲存使用者所按下的運算元
str = Convert.ToString(ans);
textBox1.Text = str;
label1.Text = "=";
}
private void button11_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 1;
str = "";
}
private void button12_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 2;
str = "";
}
private void button13_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 3;
str = "";
}
private void button14_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 4;
str = "";
}
private void button10_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "0";
}
}
}
11-12 小算盤
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public string str = ""; //把數字鍵字串存起來
public double ans = 0;//佔存變數
public int how = 0;//判斷按下+ - * /
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button16_Click(object sender, EventArgs e)
{
str = ""; //顯示0
textBox1.Text = "0";
}
private void button1_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵1
str += "1";
textBox1.Text = str;//顯示字串內容
}
private void button2_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵2
str += "2";
textBox1.Text = str;
}
private void button3_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵3
str += "3";
textBox1.Text = str;
}
private void button4_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "4";
textBox1.Text = str;
}
private void button5_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "5";
textBox1.Text = str;
}
private void button6_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "6";
textBox1.Text = str;
}
private void button7_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "7";
textBox1.Text = str;
}
private void button8_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "8";
textBox1.Text = str;
}
private void button9_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "9";
textBox1.Text = str;
}
private void button15_Click(object sender, EventArgs e)
{
if (str != "")//點擊=鍵
{
if (how == 1) { ans += Convert.ToDouble(str); }//轉換成浮點數
else if (how == 2) { ans -= Convert.ToDouble(str); }
else if (how == 3) { ans *= Convert.ToDouble(str); }
else if (how == 4) { ans /= Convert.ToDouble(str); }
else if (ans == 0) { ans = Convert.ToDouble(str); }
else ans = Convert.ToDouble(str);
}
how = 0;//再儲存使用者所按下的運算元
str = Convert.ToString(ans);
textBox1.Text = str;
}
private void button11_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 1;
str = "";
}
private void button12_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 2;
str = "";
}
private void button13_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 3;
str = "";
}
private void button14_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 4;
str = "";
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public string str = ""; //把數字鍵字串存起來
public double ans = 0;//佔存變數
public int how = 0;//判斷按下+ - * /
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button16_Click(object sender, EventArgs e)
{
str = ""; //顯示0
textBox1.Text = "0";
}
private void button1_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵1
str += "1";
textBox1.Text = str;//顯示字串內容
}
private void button2_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵2
str += "2";
textBox1.Text = str;
}
private void button3_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//數字鍵3
str += "3";
textBox1.Text = str;
}
private void button4_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "4";
textBox1.Text = str;
}
private void button5_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "5";
textBox1.Text = str;
}
private void button6_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "6";
textBox1.Text = str;
}
private void button7_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "7";
textBox1.Text = str;
}
private void button8_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "8";
textBox1.Text = str;
}
private void button9_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "9";
textBox1.Text = str;
}
private void button15_Click(object sender, EventArgs e)
{
if (str != "")//點擊=鍵
{
if (how == 1) { ans += Convert.ToDouble(str); }//轉換成浮點數
else if (how == 2) { ans -= Convert.ToDouble(str); }
else if (how == 3) { ans *= Convert.ToDouble(str); }
else if (how == 4) { ans /= Convert.ToDouble(str); }
else if (ans == 0) { ans = Convert.ToDouble(str); }
else ans = Convert.ToDouble(str);
}
how = 0;//再儲存使用者所按下的運算元
str = Convert.ToString(ans);
textBox1.Text = str;
}
private void button11_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 1;
str = "";
}
private void button12_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 2;
str = "";
}
private void button13_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 3;
str = "";
}
private void button14_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };ans += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };ans -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };ans *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };ans /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } ans = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(ans);
how = 4;
str = "";
}
}
}
2010年11月11日 星期四
11-12 亂數陣列
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
int[] arry=new int[10];
public Form1()
{
InitializeComponent();
for (int i = 0; i < 9; i++)
arry[i] = i + 1;
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button5.Text = Convert.ToString(arry[4]);
button6.Text = Convert.ToString(arry[5]);
button7.Text = Convert.ToString(arry[6]);
button8.Text = Convert.ToString(arry[7]);
button9.Text = Convert.ToString(arry[8]);
}
private void button10_Click(object sender, EventArgs e)
{
Random rd = new Random();
int temp; int rdno;
for (int i = 0; i < 10; i++)
{
rdno = rd.Next(0, 10);
temp = arry[i];
arry[i] = arry[rdno];
arry[rdno] = temp;
}
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button5.Text = Convert.ToString(arry[4]);
button6.Text = Convert.ToString(arry[5]);
button7.Text = Convert.ToString(arry[6]);
button8.Text = Convert.ToString(arry[7]);
button9.Text = Convert.ToString(arry[8]);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int[] arry=new int[10];
public Form1()
{
InitializeComponent();
for (int i = 0; i < 9; i++)
arry[i] = i + 1;
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button5.Text = Convert.ToString(arry[4]);
button6.Text = Convert.ToString(arry[5]);
button7.Text = Convert.ToString(arry[6]);
button8.Text = Convert.ToString(arry[7]);
button9.Text = Convert.ToString(arry[8]);
}
private void button10_Click(object sender, EventArgs e)
{
Random rd = new Random();
int temp; int rdno;
for (int i = 0; i < 10; i++)
{
rdno = rd.Next(0, 10);
temp = arry[i];
arry[i] = arry[rdno];
arry[rdno] = temp;
}
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button5.Text = Convert.ToString(arry[4]);
button6.Text = Convert.ToString(arry[5]);
button7.Text = Convert.ToString(arry[6]);
button8.Text = Convert.ToString(arry[7]);
button9.Text = Convert.ToString(arry[8]);
}
}
}
2010年11月5日 星期五
11-05 圈圈叉叉作業
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
System.Windows.Forms.Button[] Buttons;
System.Windows.Forms.TextBox[] TextBoxs;
int nobtpressed = 0;
int[] recordbutn = new int[9] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
int temp;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Buttons = new System.Windows.Forms.Button[9];
TextBoxs = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
Buttons[i].Size = new Size(90, 90);
Buttons[i].Click += new System.EventHandler(Buttons_Click);
this.Controls.Add(Buttons[i]);
if (i <= 2)
Buttons[i].Location = new System.Drawing.Point(10 + i * 120, 110);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 120, 140 + 70);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 120, 170 + 150);
}
for (int i = 0; i < 9; ++i)
{
TextBoxs[i] = new TextBox();
if (i <= 2)
TextBoxs[i].Location = new System.Drawing.Point(10 + i * 110, 10);
else if (i > 2 && i <= 5)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 110, 40);
else if (i > 5 && i <= 9)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 110, 70);
}
TextBoxs[0].Text = "0";
TextBoxs[1].Text = "1";
TextBoxs[2].Text = "2";
TextBoxs[3].Text = "3";
TextBoxs[4].Text = "4";
TextBoxs[5].Text = "5";
TextBoxs[6].Text = "6";
TextBoxs[7].Text = "7";
TextBoxs[8].Text = "8";
}
public void Buttons_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
int bno = 0;
String tnum = sender.ToString();
int tlen = tnum.Length;
String no = tnum.Substring(tlen - 1);
for (int i = 0; i < 9; i++)
{
if (Buttons[i].Text == no)
bno = i;
}
switch (bno)
{
case 0:
//MessageBox.Show("0");
Buttons[0].Image = pictureBox1.Image;
break;
case 1:
//MessageBox.Show("1");
Buttons[1].Image = pictureBox1.Image;
break;
case 2:
//MessageBox.Show("2");
Buttons[2].Image = pictureBox1.Image;
break;
case 3:
//MessageBox.Show("3");
Buttons[3].Image = pictureBox1.Image;
break;
case 4:
//MessageBox.Show("4");
Buttons[4].Image = pictureBox1.Image;
break;
case 5:
//MessageBox.Show("5");
Buttons[5].Image = pictureBox1.Image;
break;
case 6:
//MessageBox.Show("6");
Buttons[6].Image = pictureBox1.Image;
break;
case 7:
//MessageBox.Show("7");
Buttons[7].Image = pictureBox1.Image;
break;
case 8:
//MessageBox.Show("8");
Buttons[8].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp=recordbutn[8];
recordbutn[8] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 9; i++)
{
Buttons[i].Text = Convert.ToString(TextBoxs[i].Text);
}
Random Rd = new Random();
int Rdno=Rd.Next(9-nobtpressed);
label2.Text = "" + Rdno;
Buttons[recordbutn[Rdno]].Image = pictureBox2.Image;
nobtpressed = nobtpressed + 1;
label2.Text=""+nobtpressed;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
System.Windows.Forms.Button[] Buttons;
System.Windows.Forms.TextBox[] TextBoxs;
int nobtpressed = 0;
int[] recordbutn = new int[9] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
int temp;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Buttons = new System.Windows.Forms.Button[9];
TextBoxs = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
Buttons[i].Size = new Size(90, 90);
Buttons[i].Click += new System.EventHandler(Buttons_Click);
this.Controls.Add(Buttons[i]);
if (i <= 2)
Buttons[i].Location = new System.Drawing.Point(10 + i * 120, 110);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 120, 140 + 70);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 120, 170 + 150);
}
for (int i = 0; i < 9; ++i)
{
TextBoxs[i] = new TextBox();
if (i <= 2)
TextBoxs[i].Location = new System.Drawing.Point(10 + i * 110, 10);
else if (i > 2 && i <= 5)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 110, 40);
else if (i > 5 && i <= 9)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 110, 70);
}
TextBoxs[0].Text = "0";
TextBoxs[1].Text = "1";
TextBoxs[2].Text = "2";
TextBoxs[3].Text = "3";
TextBoxs[4].Text = "4";
TextBoxs[5].Text = "5";
TextBoxs[6].Text = "6";
TextBoxs[7].Text = "7";
TextBoxs[8].Text = "8";
}
public void Buttons_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
int bno = 0;
String tnum = sender.ToString();
int tlen = tnum.Length;
String no = tnum.Substring(tlen - 1);
for (int i = 0; i < 9; i++)
{
if (Buttons[i].Text == no)
bno = i;
}
switch (bno)
{
case 0:
//MessageBox.Show("0");
Buttons[0].Image = pictureBox1.Image;
break;
case 1:
//MessageBox.Show("1");
Buttons[1].Image = pictureBox1.Image;
break;
case 2:
//MessageBox.Show("2");
Buttons[2].Image = pictureBox1.Image;
break;
case 3:
//MessageBox.Show("3");
Buttons[3].Image = pictureBox1.Image;
break;
case 4:
//MessageBox.Show("4");
Buttons[4].Image = pictureBox1.Image;
break;
case 5:
//MessageBox.Show("5");
Buttons[5].Image = pictureBox1.Image;
break;
case 6:
//MessageBox.Show("6");
Buttons[6].Image = pictureBox1.Image;
break;
case 7:
//MessageBox.Show("7");
Buttons[7].Image = pictureBox1.Image;
break;
case 8:
//MessageBox.Show("8");
Buttons[8].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp=recordbutn[8];
recordbutn[8] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 9; i++)
{
Buttons[i].Text = Convert.ToString(TextBoxs[i].Text);
}
Random Rd = new Random();
int Rdno=Rd.Next(9-nobtpressed);
label2.Text = "" + Rdno;
Buttons[recordbutn[Rdno]].Image = pictureBox2.Image;
nobtpressed = nobtpressed + 1;
label2.Text=""+nobtpressed;
}
}
}
訂閱:
文章 (Atom)