Code LTGD
Code LTGD
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 DoanXucXac
{
public partial class Form1 : Form
{
String pathImg;
Random rand = new Random();
//nchoose: nguoi dung chon, count so lan doan, win: so lan thang
//lose: so lan thua
int nChoose, nCount, nWin, nlose;
string kq = " ";
private void bt1_Click(object sender, EventArgs e)
{
Button bt = (Button) sender;
nChoose = int.Parse(bt.Text);
picSo1.Image = Image.FromFile(pathImg + bt.Text + ".jpg");
}
private void QuaySo()
{
int n = rand.Next(1, 7);
picSo2.Image = Image.FromFile(pathImg + n.ToString() + ".jpg");
if(n == nChoose)
{
nWin++;
}
else
{
nlose++;
}
label1.Text = String.Format("Lan doan: {0} ", nCount);
label2.Text = String.Format("Lan thang: {0} ({1:0.##}%", nWin, (double)nWin *
100 / nCount);
label3.Text = String.Format("Lan thua: {0} ({1:0.##}%", nlose, (double)nlose
* 100 / nCount);
libKetQua.Items.Add ( String.Format("{0} . {1} (Doan {2} ra {3}).", nCount,
kq, nChoose, n));
}
public Form1()
{
InitializeComponent();
}
Quay số
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 QuaySo
{
public partial class Form1 : Form
{
Random r = new Random();
string path; //đường dẫn đến file hình
public Form1()
{
InitializeComponent();
}
private void btQuaySo_Click(object sender, EventArgs e)
{
int so1, so2, so3;
//sinh số ngẫu nhiên cho 3 số
so1 = r.Next(1, 7);
so2 = r.Next(1, 7);
so3 = r.Next(1, 7);
pic1.Image = Image.FromFile(path + so1.ToString() + ".jpg");
pic2.Image = Image.FromFile(path + so2.ToString() + ".jpg");
pic3.Image = Image.FromFile(path + so3.ToString() + ".jpg");
lbKetQua.Text = (so1 + so2 + so3).ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
//đường dẫn vào debug và vào các hình, mỗi xuyệt là đi 1 cấp thư mục
path = Application.StartupPath + @"\hinhxucxac\";
namespace QLNV
{
public partial class FrmDangNhap : Form
{
public FrmDangNhap()
{
InitializeComponent();
}
namespace QLNV
{
public partial class FrmMain : Form
{
public static string Tendangnhap = "";
public bool bClose;
public FrmMain()
{
FrmDangNhap f = new FrmDangNhap();
//làm việc trên frmDangNhap xong thì mới có thể làm trên form khác
f.ShowDialog();
InitializeComponent();
}
namespace BTHC5
{
public partial class Form1 : Form
{
int count = 0;
Point bold; //biến lưu vị trí nhấn chuột
Random rand = new Random();
string []arrfiles;
int ImgWidth = 90;// kích thước hình
public Form1()
{
InitializeComponent();
}
}
private void AddNewPicture()
{
count++;
string file = arrfiles[rand.Next(arrfiles.Length)];//random trong mảng các
hình
Image img = Image.FromFile(file);
//tạo picturebox
PictureBox pic = new PictureBox();
pic.Name = count.ToString();
pic.Image = img;
pic.Location = new Point(0, 0);
pic.Width = pic.Height = ImgWidth;
pic.SizeMode = PictureBoxSizeMode.StretchImage;
//cài sự kiện trên PictureBox
pic.MouseDown += Pic_MouseDown;
pic.MouseMove += Pic_MouseMove;
pic.MouseUp += Pic_MouseUp;
this.Controls.Add(pic); // add picturebox vào Form
//Sắp xếp lại pnBound
this.Controls.SetChildIndex(pnBound, this.Controls.Count - 1);
}
}
private void Pic_MouseMove(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left) // giữ chuột trái khi di chuyển
{
PictureBox pic = (PictureBox)sender;
int dx = e.X - bold.X; //khoảng cách dịch chuyển
int dy = e.Y - bold.Y;
pic.Left += dx;
pic.Top += dy;
}
}
}
}
/////////////////////////////////////////////
BTHC6
Chuỗi
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 BTH06_BT1
{
public partial class Form1 : Form
{
string str = "Khoa CNTT, Đại học Mở TP.HCM";
public Form1()
{
InitializeComponent();
}
}
txtS1.Text = String.Join(" ", arr);
}
}
}
}
Mảng
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 BTHC6B2
{
public partial class Form1 : Form
{
int[] arrInt; // mảng ban đầu
int[] arrTang;
int[] arrGiam;
int[] arrDao;
int[] arrChanLe;
public Form1()
{
InitializeComponent();
}
}
//Hàm hiển thị phần tử của mảng lên textbox
private void ShowArray(int[]a, TextBox textbox)
{
textbox.Text = String.Empty;//khởi tạo chuỗi rỗng
for(int i = 0; i < a.Length; i++)
textbox.Text += a[i].ToString() + " , ";// + dồn a[i] đã chuyển thành
chuỗi
textbox.Text = textbox.Text.TrimEnd();
}
}
ShowArray(arrChanLe, txtSoMangChanLe);
}
private void swap (ref int a, ref int b)
{
int tam = a;
a = b;
b = tam;
}
}
}
/////////////////////////////////////////////////////////////////
BTHC7
Cây thư mục
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;//phải tự thêm
namespace BTHC7._1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
QLNV
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BTH7._2
{
class Employee
{
string name;
int age;
string address;
public string Name
{
get { return name; }
set { name = value; }
}
public int Age
{
get { return age; }
set { age = (value < 18 ? 18 : value); }
}
public string Address
{
get { return address; }
set { address = value; }
}
public Employee() {
}
public Employee(string name, int age, string address)
{
this.name = name;
this.age = age;
this.address = address;
}
}
}
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 BTH7._2
{
public partial class Form1 : Form
{
Employee[] ds = new Employee[100];
int i = 0;
public Form1()
{
InitializeComponent();
}
private void InsertNV(Employee nv)
{
//thêm dòng vào listV
ListViewItem item = new ListViewItem(nv.Name);
item.SubItems.Add(nv.Age.ToString());
item.SubItems.Add(nv.Address);
listV.Items.Add(item);
}
private void Form1_Load(object sender, EventArgs e)
{
//thêm cột vào listV
listV.Columns.Add("Name", 200);
listV.Columns.Add("Age", 100);
listV.Columns.Add("Address", 200);
listV.View = View.Details;
}
w.Close();
}
}
namespace BTHC8
{
public partial class FrmDrawByMouse : Form
{
public FrmDrawByMouse()
{
InitializeComponent();
}
int penWidth;//độ dài nét vẽ
Color color;//màu vẽ
//thông tin điểm vẽ cũ
Point pOld;
//Khung tạo khu vực vẽ
Bitmap bmpTemp;
namespace BTHC8
{
public partial class FrmText : Form
{
public FrmText()
{
InitializeComponent();
}
namespace BTHC8
{
public partial class FrmDrawImage : Form
{
public FrmDrawImage()
{
InitializeComponent();
}
namespace BTHC8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string path1 = Application.StartupPath + "\\1.png";
string path2 = Application.StartupPath + "\\2.png";
string path3 = Application.StartupPath + "\\3.png";
string path4 = Application.StartupPath + "\\4.png";
string path5 = Application.StartupPath + "\\5.png";
string path6 = Application.StartupPath + "\\6.png";
string path = Application.StartupPath;
int[] result = new int[3];
int Bet = 0;
Random rd = new Random();
int Money = 0;
int Reward = 0;
// Thread thr = new Thread();
}
}
}
////////////////////////////////////////////////////////////////////
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
FileStream stream = null;
BinaryFormatter binary = new BinaryFormatter();
arrEmp.Clear();
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Jpeg file(*.jpg)|*.jpg" +
"|Gip file(*.gif)|*.gif" +
"|Png file(*.png)|*.png" +
"|Bitmap file(*.bmp)|*bmp";
if (dlg.ShowDialog() == DialogResult.OK)
{
stream = new FileStream(dlg.FileName, FileMode.Create,
FileAccess.Write);
}
}
catch
{
}
}
////////////////////////////////////////////////////////////////////
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 De3
{
public partial class FrmList : Form
{
public FrmList()
{
InitializeComponent();
}
}
}
}
//////////////////////////////////////////////////////////////////
private void FrmVe_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle(200,200,300,300);
LinearGradientBrush r = new LinearGradientBrush(rect, Color.Orange,
Color.White, 45);
e.Graphics.FillRectangle(r, rect);
Font font = new Font("Arial", 48, FontStyle.Bold);
//Định dạng nằm ở lề phải
StringFormat format = new StringFormat();
//LinearGradientBrush br4 = new LinearGradientBrush(rect, Color.Pink,
Color.White, 45);
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString("Nguyễn Văn A", font, new SolidBrush(Color.Red), rect,
format);
}