Saturday, 23 November 2013
Friday, 22 November 2013
c# jigsaw puzzle
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;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Left = 0;
this.Top = 0;
this.Size = new Size(50 * nx + 100, 50 * ny + 100);
this.MaximizeBox = false;
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.Text = "jigsaw puzzle";
btn = new Button[nx, ny];
for (int i = 0; i < nx; i++)
{
for (int j = 0; j < ny; j++)
{
btn[i, j] = new Button();
btn[i, j].Width = 50;
btn[i, j].Height = 50;
btn[i, j].Left = 50 + 50 * i;
btn[i, j].Top = 50 + 50 * j;
btn[i, j].Tag = Convert.ToString(10*(i+1)+j+1);
btn[i, j].BackgroundImage = Image.FromFile(@"C:\Users\abc\Desktop\" + btn[i, j].Tag + ".png");
btn[i, j].BackgroundImageLayout = ImageLayout.Stretch;
this.Controls.Add(btn[i, j]);
}
}
btn[hx, hy].Visible = false; ;
}
private Button[,] btn;
private static int nx = 3, ny = 3;
private int hx = 0, hy = 0;
private void Form1_Load(object sender, EventArgs e)
{
}
private void leftpress()
{
string t; Image im;
if (hx < nx - 1)
{
t = btn[hx + 1, hy].Tag.ToString();
btn[hx + 1, hy].Tag = btn[hx, hy].Tag;
btn[hx, hy].Tag = t;
im = btn[hx + 1, hy].BackgroundImage;
btn[hx + 1, hy].BackgroundImage = btn[hx, hy].BackgroundImage;
btn[hx, hy].BackgroundImage = im;
btn[hx, hy].Visible = true;
btn[hx + 1, hy].Visible = false;
hx++;
}
}
private void rightpress()
{
string t; Image im;
if (hx > 0)
{
t = btn[hx - 1, hy].Tag.ToString();
btn[hx - 1, hy].Tag = btn[hx, hy].Tag;
btn[hx, hy].Tag = t;
im = btn[hx - 1, hy].BackgroundImage;
btn[hx - 1, hy].BackgroundImage = btn[hx, hy].BackgroundImage;
btn[hx, hy].BackgroundImage = im;
btn[hx, hy].Visible = true;
btn[hx - 1, hy].Visible = false;
hx--;
}
}
private void downpress()
{
string t; Image im;
if (hy > 0)
{
t = btn[hx, hy-1].Tag.ToString();
btn[hx, hy-1].Tag = btn[hx, hy].Tag;
btn[hx, hy].Tag = t;
im = btn[hx, hy-1].BackgroundImage;
btn[hx, hy-1].BackgroundImage = btn[hx, hy].BackgroundImage;
btn[hx, hy].BackgroundImage = im;
btn[hx, hy].Visible = true;
btn[hx, hy - 1].Visible = false;
hy--;
}
}
private void uppress()
{
string t; Image im;
if (hy < ny - 1)
{
t = btn[hx, hy + 1].Tag.ToString();
btn[hx, hy + 1].Tag = btn[hx, hy].Tag;
btn[hx, hy].Tag = t;
im = btn[hx, hy + 1].BackgroundImage;
btn[hx, hy + 1].BackgroundImage = btn[hx, hy].BackgroundImage;
btn[hx, hy].BackgroundImage = im;
btn[hx, hy].Visible = true;
btn[hx, hy + 1].Visible = false;
hy++;
}
}
private void textBox1_TextChanged(object sender, KeyEventArgs e)
{
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
string keyID = e.KeyCode.ToString();
switch (keyID)
{
case "Right": rightpress();
break;
case "Left": leftpress();
break;
case "Down": downpress();
break;
case "Up": uppress();
break;
default:
break;
}
}
}
}
Thursday, 21 November 2013
c# transmitter receiver
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
try
{
IPAddress ipAd = IPAddress.Parse("127.0.0.2");
TcpListener myList = new TcpListener(ipAd, 8001);
myList.Start();
Console.WriteLine("my local address:" + myList.LocalEndpoint);
Console.WriteLine("wait");
Socket s = myList.AcceptSocket();
Console.WriteLine("remote address: " + s.RemoteEndPoint);
int j = 0;
while(j!=10)
{
byte[] b = new byte[100];
int k = s.Receive(b);
Console.WriteLine("received");
for (int i = 0; i < k; i++)
{
Console.Write(Convert.ToChar(b[i]));
}
Console.WriteLine();
Console.WriteLine("replying");
string str = Console.ReadLine();
ASCIIEncoding asen = new ASCIIEncoding();
s.Send(asen.GetBytes(str));
}
}
catch { }
Console.ReadLine();
}
}
}
--------------------------------------------------------------------------------------
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("connecting to 127.0.0.2,8001");
tcpclnt.Connect("127.0.0.2",8001);
Console.WriteLine("connected");
int j = 0;
while (j!=10)
{
Console.WriteLine();
Console.WriteLine("sending");
string str = Console.ReadLine();
Stream stm = tcpclnt.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(str);
stm.Write(ba, 0, ba.Length);
byte[] bb = new byte[100];
Console.WriteLine("receiving");
int k = stm.Read(bb, 0, 100);
for (int i = 0; i < k; i++)
{
Console.Write(Convert.ToChar(bb[i]));
}
j++;
}
Console.ReadLine();
tcpclnt.Close();
}
catch(Exception e)
{
Console.WriteLine("error"+e.StackTrace);
}
}
}
}
Monday, 18 November 2013
c# all red square
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;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
nxny();
this.Left = 0;
this.Top = 0;
this.Size = new Size(50 * nx + 100, 50 * ny + 100);
this.MaximizeBox = false;
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.Text = "all red";
for (int i = 0; i < nx; i++)
{
for (int j = 0; j < ny; j++)
{
btn[i, j] = new Button();
btn[i, j].Width = 50;
btn[i, j].Height = 50;
btn[i, j].Left = 50 + 50 * i;
btn[i, j].Top = 50 + 50 * j;
btn[i, j].BackColor = Color.SeaGreen;
btn[i, j].Text = i.ToString() + j.ToString();
btn[i, j].Click += new EventHandler(btn_Click);
btn[i, j].Tag = 0;
this.Controls.Add(btn[i, j]);
}
}
}
private static int nx, ny;
private Button[,] btn;
private int count = 0;
private string step = "";
private string word(StreamReader sr, string find)
{
int i; sr.BaseStream.Seek(0, SeekOrigin.Begin);
while (!sr.EndOfStream)
{
string[] words = sr.ReadLine().Split();
if (words[0] == find)
{
for (i = 1; words[i] == ""; ) { i++; }
return words[i];
}
}
return "EOF";
}
private void nxny()
{
FileStream fs = new FileStream("myfile.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string txt;
txt = word(sr, "nx"); nx = Int32.Parse(txt);
txt = word(sr, "ny"); ny = Int32.Parse(txt);
btn = new Button[nx, ny];
}
private void btn_Click(object sender, EventArgs eArgs)
{
int txt = Convert.ToInt32(((Button)sender).Text);
int i, j;
if (ny < 10)
{
i = txt / 10; j = txt % 10;
}
else
{
i = txt / 100; j = txt % 100;
}
ChangeButtonState(i, j);
ChangeButtonState(i - 1, j);
ChangeButtonState(i + 1, j);
ChangeButtonState(i, j + 1);
ChangeButtonState(i, j - 1);
count++;
step += "(" + i + "," + j + ")" + " ";
if (Win() == true)
{
wingame();
}
}
private void ChangeButtonState(int i, int j)
{
if (i < 0) { i = nx - 1; }
if (j < 0) { j = ny - 1; }
if (i == nx) { i = 0; }
if (j == ny) { j = 0; }
if (Convert.ToInt32(btn[i, j].Tag) == 0)
{
btn[i, j].Tag = 1;
btn[i, j].BackColor = Color.Red;
}
else
{
btn[i, j].Tag = 0;
btn[i, j].BackColor = Color.SeaGreen;
}
}
private bool Win()
{
for (int i = 0; i < nx; i++)
{
for (int j = 0; j < ny; j++)
{
if (Convert.ToInt32(btn[i, j].Tag) == 0)
{ return false; }
}
}
return true;
}
private void wingame()
{
MessageBox.Show(count + " steps\n" + step);
for (int i = 0; i < nx; i++)
{
for (int j = 0; j < ny; j++)
{
btn[i, j].Click -= new EventHandler(btn_Click);
}
}
FileStream outputfile = null;
outputfile = new FileStream("step.txt", FileMode.Create, FileAccess.Write);
StreamWriter writer = new StreamWriter(outputfile);
writer.BaseStream.Seek(0, SeekOrigin.End);
writer.WriteLine(step);
writer.Flush();
writer.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Sunday, 17 November 2013
he is we
all about us
https://www.youtube.com/watch?v=POb9dMjDnKc
kiss it all better
https://www.youtube.com/watch?v=nXPx8b4rgko
https://www.youtube.com/watch?v=POb9dMjDnKc
kiss it all better
https://www.youtube.com/watch?v=nXPx8b4rgko
c# image format converter
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 Bitmap map = null;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog old = new OpenFileDialog();
old.Filter = comboBox1.Text + "|" + comboBox1.Text;
string filter = old.Filter;
old.InitialDirectory = System.Environment.CurrentDirectory;
old.Title = "打开";
old.ShowHelp = true;
if (old.ShowDialog() == DialogResult.OK)
{
string name = old.FileName;
map = new Bitmap(name);
pictureBox1.Image = map;
button2.Enabled = true;
}
}
private void button2_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "保存";
sfd.OverwritePrompt = true;
sfd.CheckPathExists = true;
sfd.Filter = comboBox2.Text + "|" + comboBox2.Text;
sfd.ShowHelp = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
string name = sfd.FileName;
map.Save(name);
}
}
}
}
Saturday, 16 November 2013
c# calculator
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 static double value1 = 0, value2=0, value3=1, cal=0, calold=0, valuecal;
private int deci = 0, decicount=10, operat=1, second=0, sign=0;
private void keyenable(bool x)
{
button1.Enabled = x;button6.Enabled=x; button10.Enabled=x; button11.Enabled=x; button12.Enabled=x;
button13.Enabled = x; button14.Enabled = x; button15.Enabled = x; button16.Enabled = x; button17.Enabled = x; button3.Enabled = x; button18.Enabled = x;
}
private void key(int x)
{
switch (second)
{
case 0:
if (deci == 0) { value1 = value1 * 10 + x; textBox1.Text = value1.ToString(); }
else if (deci == 1) { value1 = value1 + (double)x / decicount; textBox1.Text = value1.ToString(); decicount *= 10; }
calold = value1;
break;
case 1:
if (deci == 0) { value2 = value2 * 10 + x; textBox2.Text = value2.ToString(); }
else if (deci == 1) { value2 = value2 + (double)x / decicount; textBox2.Text = value2.ToString(); decicount *= 10; }
value3 = value2;
break;
default:
break;
}
}
private void calculate(int operat)
{
second = 1; value1 = calold; deci = 0; decicount = 10; sign = 0;
textBox2.Text = ""; textBox4.Text = "";
switch (operat)
{
case 1:
cal = value1 + value2;
break;
case 2:
cal = value1 - value2;
break;
case 3:
cal = value1 * value3;
break;
case 4:
cal = value1 / value3;
break;
case 5:
cal = Math.Pow(value1,value3);
break;
case 6:
cal = Math.Sin(value1/180*Math.PI);
break;
case 7:
cal = Math.Log(value1,value2);
break;
default:
break;
}
calold = cal; valuecal = value2; value3 = 1; value2 = 0;
}
//1
private void button1_Click(object sender, EventArgs e)
{
if (sign == 0) { key(1); } else if (sign == 1) { key(-1); }
}
//.
private void button3_Click(object sender, EventArgs e)
{
switch (second)
{
case 0:
{
if (deci == 1) { return; }
else if (deci == 0) { deci = 1; textBox1.Text += "."; }
break;
}
case 1:
{
if (deci == 1) { return; }
else if (deci == 0) { deci = 1; textBox2.Text += "."; }
break;
}
default:
break;
}
}
//+
private void button2_Click(object sender, EventArgs e)
{
keyenable(true);
textBox3.Text = "+";
calculate(operat);
operat = 1;
textBox1.Text = cal.ToString();
}
//clear
private void button4_Click(object sender, EventArgs e)
{
textBox2.Text = ""; textBox4.Text = ""; textBox1.Text = ""; textBox3.Text = "";
value1 = 0; value2=0; value3=1; cal=0; calold=0;
deci = 0; decicount = 10; operat = 1; second = 0; sign = 0; keyenable(true);
}
//=
private void button5_Click(object sender, EventArgs e)
{
keyenable(true); calculate(operat);
textBox4.Text = cal.ToString();
second = 0;
}
//2
private void button6_Click(object sender, EventArgs e)
{
if (sign == 0) { key(2); } else if (sign == 1) { key(-2); }
}
//-
private void button7_Click(object sender, EventArgs e)
{
keyenable(true);
textBox3.Text = "-";
calculate(operat);
operat = 2;
textBox1.Text = cal.ToString();
}
//*
private void button8_Click(object sender, EventArgs e)
{
keyenable(true);
textBox3.Text = "*";
calculate(operat);
operat = 3;
textBox1.Text = cal.ToString();
}
///
private void button9_Click(object sender, EventArgs e)
{
keyenable(true);
textBox3.Text = "/";
calculate(operat);
operat = 4;
textBox1.Text = cal.ToString();
}
//3
private void button10_Click(object sender, EventArgs e)
{
if (sign == 0) { key(3); } else if (sign == 1) { key(-3); }
}
private void button11_Click(object sender, EventArgs e)
{
if (sign == 0) { key(4); } else if (sign == 1) { key(-4); }
}
private void button12_Click(object sender, EventArgs e)
{
if (sign == 0) { key(5); } else if (sign == 1) { key(-5); }
}
private void button13_Click(object sender, EventArgs e)
{
if (sign == 0) { key(6); } else if (sign == 1) { key(-6); }
}
private void button14_Click(object sender, EventArgs e)
{
if (sign == 0) { key(7); } else if (sign == 1) { key(-7); }
}
private void button15_Click(object sender, EventArgs e)
{
if (sign == 0) { key(8); } else if (sign == 1) { key(-8); }
}
private void button16_Click(object sender, EventArgs e)
{
if (sign == 0) { key(9); } else if (sign == 1) { key(-9); }
}
private void button17_Click(object sender, EventArgs e)
{
key(0);
}
//+/-
private void button18_Click(object sender, EventArgs e)
{
if (sign == 0) { sign = 1; }
else if (sign == 1) { sign = 0; }
if (second == 0)
{
value1 = -value1; calold = -calold; textBox1.Text = calold.ToString();
}
else if (second == 1)
{
value2 = -value2; value3 = -value3; textBox2.Text = value2.ToString();
}
}
//次方
private void button19_Click(object sender, EventArgs e)
{
keyenable(true);
textBox3.Text = "次方";
calculate(operat);
operat = 5;
textBox1.Text = cal.ToString();
}
private void button20_Click(object sender, EventArgs e)
{
keyenable(false);
textBox3.Text = "sin";
calculate(operat);
operat = 6;
textBox1.Text = cal.ToString();
}
private void button21_Click(object sender, EventArgs e)
{
keyenable(true);
textBox3.Text = "log";
calculate(operat);
operat = 7;
textBox1.Text = cal.ToString();
}
private void button22_Click(object sender, EventArgs e)
{
keyenable(false);
switch (second)
{
case 0:
value1 = Math.Exp(1); textBox1.Text = value1.ToString(); calold = value1;
break;
case 1:
value2 = Math.Exp(1); textBox2.Text = value2.ToString(); value3 = value2;
break;
default:
break;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Friday, 15 November 2013
c# flying window
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 Form2 gift;
public Form1()
{
InitializeComponent();
gift = new Form2();
gift.Hide();
}
private static int up=1, down=0, left=1, right=0;
private static Point q = new Point(200, 200);
private void timer1_Tick(object sender, EventArgs e)
{
Point p = new Point(this.DesktopLocation.X, this.DesktopLocation.Y);
if (up == 1)
{
q.Y = p.Y - 1;
if (q.Y == 0) { up = 0; down = 1; }
this.DesktopLocation = q;
}
else if (down == 1)
{
q.Y = p.Y + 1;
if (q.Y == 300) { up = 1; down = 0; }
this.DesktopLocation = q;
}
if (right == 1)
{
q.X = p.X - 1;
if (q.X == 0) { left = 1; right = 0; }
this.DesktopLocation = q;
}
else if (left == 1)
{
q.X = p.X + 1;
if (q.X == 300) { right = 1; left = 0; }
this.DesktopLocation = q;
}
}
private void Form1_Load(object sender, EventArgs e)
{
Point p = new Point(200, 200);
this.DesktopLocation = p;
}
private void label1_Click(object sender, EventArgs e)
{
this.Hide();
gift.Show();
}
}
}
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 Form2 gift;
public Form1()
{
InitializeComponent();
gift = new Form2();
gift.Hide();
}
private static int up=1, down=0, left=1, right=0;
private static Point q = new Point(200, 200);
private void timer1_Tick(object sender, EventArgs e)
{
Point p = new Point(this.DesktopLocation.X, this.DesktopLocation.Y);
if (up == 1)
{
q.Y = p.Y - 1;
if (q.Y == 0) { up = 0; down = 1; }
this.DesktopLocation = q;
}
else if (down == 1)
{
q.Y = p.Y + 1;
if (q.Y == 300) { up = 1; down = 0; }
this.DesktopLocation = q;
}
if (right == 1)
{
q.X = p.X - 1;
if (q.X == 0) { left = 1; right = 0; }
this.DesktopLocation = q;
}
else if (left == 1)
{
q.X = p.X + 1;
if (q.X == 300) { right = 1; left = 0; }
this.DesktopLocation = q;
}
}
private void Form1_Load(object sender, EventArgs e)
{
Point p = new Point(200, 200);
this.DesktopLocation = p;
}
private void label1_Click(object sender, EventArgs e)
{
this.Hide();
gift.Show();
}
}
}
Thursday, 14 November 2013
c# window layout
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 static int count = 0;
private void bToolStripMenuItem_Click(object sender, EventArgs e)
{
Form x = new Form();
x.MdiParent = this;
x.Text = "window#" + count.ToString();
count++;
x.Show();
}
private void cToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void dToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.Cascade);
}
private void eToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileHorizontal);
}
private void fToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileVertical);
}
}
}
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 static int count = 0;
private void bToolStripMenuItem_Click(object sender, EventArgs e)
{
Form x = new Form();
x.MdiParent = this;
x.Text = "window#" + count.ToString();
count++;
x.Show();
}
private void cToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void dToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.Cascade);
}
private void eToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileHorizontal);
}
private void fToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileVertical);
}
}
}
Tuesday, 12 November 2013
c# timer
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;
using System.Timers;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string GetTime()
{
string time = "";
int hour = DateTime.Now.Hour;
int min = DateTime.Now.Minute;
int sec = DateTime.Now.Second;
time = (hour < 10) ? "0" + hour.ToString() : hour.ToString();
time += ":" + ((min < 10) ? "0" + min.ToString() : min.ToString());
time += ":" + ((sec < 10) ? "0" + sec.ToString() : sec.ToString());
return time;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (sender == timer1)
{ label1.Text = GetTime(); }
}
}
}
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;
using System.Timers;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string GetTime()
{
string time = "";
int hour = DateTime.Now.Hour;
int min = DateTime.Now.Minute;
int sec = DateTime.Now.Second;
time = (hour < 10) ? "0" + hour.ToString() : hour.ToString();
time += ":" + ((min < 10) ? "0" + min.ToString() : min.ToString());
time += ":" + ((sec < 10) ? "0" + sec.ToString() : sec.ToString());
return time;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (sender == timer1)
{ label1.Text = GetTime(); }
}
}
}
c# mouse position
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 Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
string prompt = "position("+e.X.ToString()+","+e.Y.ToString()+")";
toolStripStatusLabel1.Text = prompt;
}
}
}
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 Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
string prompt = "position("+e.X.ToString()+","+e.Y.ToString()+")";
toolStripStatusLabel1.Text = prompt;
}
}
}
c# load picture
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, System.EventArgs e)
{
OpenFileDialog x = new OpenFileDialog();
x.Title = "pic selection";
x.InitialDirectory = "c:\\";
x.Filter = "all files (*.*)|*.*|image files(*.jpg,*.bmp,*.gif)|*.jpg;*.bmp;*.gif";
x.FilterIndex = 2;
if (x.ShowDialog() == DialogResult.OK)
{ pictureBox1.Image = Image.FromFile(x.FileName); }
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
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, System.EventArgs e)
{
OpenFileDialog x = new OpenFileDialog();
x.Title = "pic selection";
x.InitialDirectory = "c:\\";
x.Filter = "all files (*.*)|*.*|image files(*.jpg,*.bmp,*.gif)|*.jpg;*.bmp;*.gif";
x.FilterIndex = 2;
if (x.ShowDialog() == DialogResult.OK)
{ pictureBox1.Image = Image.FromFile(x.FileName); }
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
Subscribe to:
Posts (Atom)