0% found this document useful (0 votes)
18 views30 pages

lập trình giao diện

The document describes code for a photo album application in C#. It includes code to initialize a tree view to display drives and folders, load folder paths, and handle expanding nodes to display subfolders. When a tree node is expanded, it clears any existing child nodes, changes the icon, and loads the actual subfolders under that path.

Uploaded by

Nguyễn Hòa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views30 pages

lập trình giao diện

The document describes code for a photo album application in C#. It includes code to initialize a tree view to display drives and folders, load folder paths, and handle expanding nodes to display subfolders. When a tree node is expanded, it clears any existing child nodes, changes the icon, and loads the actual subfolders under that path.

Uploaded by

Nguyễn Hòa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

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 Chuong4_Laptrinhgiaodien
{
public partial class FrmMain : Form
{
public static string tenDangNhap="";
bool bClose;
public FrmMain()
{
FrmDangnhap f = new FrmDangnhap();
f.ShowDialog();
InitializeComponent();
}

private void FrmMain_Load(object sender, EventArgs e)


{
lbTenDangnhap.Text = tenDangNhap;
bClose = false;
}

private void btThem_Click(object sender, EventArgs e)


{
if (txtHoten.Text == "") return;
ListViewItem item = new ListViewItem(txtHoten.Text);
item.SubItems.Add(dtNgaysinh.Value.ToString("dd/MM/yyyy"));
item.SubItems.Add(rdNam.Checked ? "Nam" : "Nữ");
item.ImageIndex = rdNam.Checked ? 0 : 0 ;
listNv.Items.Add(item);
txtHoten.Text = "";
txtHoten.Focus(); //Đặt nháy vào txtHoten
}

private void btXoa_Click(object sender, EventArgs e)


{
foreach (ListViewItem item in listNv.SelectedItems)
listNv.Items.Remove(item);
}

private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)


{
if (!bClose)
{
e.Cancel = true;
timer1.Enabled = true;
}
}

private void timer1_Tick(object sender, EventArgs e)


{
this.Opacity -= 0.1;
if(this.Opacity <= 0)
{
bClose = true;
Application.Exit();
}
}

private void label1_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 Chuong4_Laptrinhgiaodien
{
public partial class FrmDangnhap : Form
{
public FrmDangnhap()
{
InitializeComponent();
//this.AcceptButton = btDangnhap;
}

private void FrmDangnhap_Load(object sender, EventArgs e)


{

private void btDangnhap_Click(object sender, EventArgs e)


{
if (txtDangnhap.Text == "" || txtMatkhau.Text != "admin")
Application.Exit();
else
{
FrmMain.tenDangNhap = txtDangnhap.Text;
this.Close();
}
}

private void btDong_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void FrmDangnhap_FormClosing(object sender, FormClosingEventArgs e)


{
if (FrmMain.tenDangNhap == "")
Application.Exit();
}

protected override bool ProcessDialogKey(Keys keyData)


{
switch (keyData)
{
case Keys.Enter:
if (txtDangnhap.Text == "" || txtMatkhau.Text != "admin")
Application.Exit();
else
{
FrmMain.tenDangNhap = txtDangnhap.Text;
this.Close();
}
break;
case Keys.Escape:
Close(); break;

}
return false;
}
}
}
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 Chuong4_Laptrinhgiaodien
{
public partial class QuaySo : Form
{
Random rand = new Random();
string pathImg;
public QuaySo()
{
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)


{
lbName.Text = lbName.Text.Substring(1) + lbName.Text.Substring(0, 1);
}
private void Init()
{
pathImg = Application.StartupPath + @"\HinhXucXac\";
picSo1.Image = Image.FromFile(pathImg + "1.png");
picSo2.Image = Image.FromFile(pathImg + "1.png");
picSo3.Image = Image.FromFile(pathImg + "1.png");
}
private void QuaySo_Load(object sender, EventArgs e)
{
Init();
}

private void btPlay_Click(object sender, EventArgs e)


{
int s1, s2, s3;
s1 = rand.Next(1, 7);
s2 = rand.Next(1, 7);
s3 = rand.Next(1, 7);

picSo1.Image = Image.FromFile(pathImg + s1.ToString() + ".png");


picSo2.Image = Image.FromFile(pathImg + s2.ToString() + ".png");
picSo3.Image = Image.FromFile(pathImg + s3.ToString() + ".png");

int kq = s1 + s2 + s3;

lbResult.Text = kq.ToString();
}

private void btClose_Click(object sender, EventArgs e)


{
this.Close();
}

private void QuaySo_FormClosing(object sender, FormClosingEventArgs e)


{
DialogResult rs = MessageBox.Show("Bạn muốn thoát?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(rs == DialogResult.No)
{
e.Cancel = true;
}
}
}
}

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 Chuong4_Laptrinhgiaodien
{
public partial class TraiBanh : Form
{
int dx = 5;
int dy = 7;
public TraiBanh()
{
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)


{
if (picBall.Left <= 0 || picBall.Right >= ClientRectangle.Width)
{
dx = -dx;
this.BackColor = Color.Aqua;
}
if (picBall.Top <= 0 || picBall.Bottom >= ClientRectangle.Height)
{
dy = -dy;
this.BackColor = Color.Pink;
}
picBall.Left += dx;
picBall.Top += dy;
}

private void TraiBanh_Load(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 Chuong4_Laptrinhgiaodien
{
public partial class XucXac : Form
{
string imgPath;
int nChoose;
int nCount;
int nWin;
int nLose;
bool bClose;
Random rand = new Random();
public XucXac()
{
InitializeComponent();
}

private void XucXac_Load(object sender, EventArgs e)


{
bClose = false;
Init();
}
private void Init()
{
imgPath = Application.StartupPath + @"\HinhXucXac\";
nChoose = 1;
nCount = nWin = nLose = 0;
picChoose.Image = Image.FromFile(imgPath + "1.png");
picResult.Image = null;
lbCount.Text = lbLose.Text = lbWin.Text = "";
listResult.Items.Clear();
}

private void bt1_Click(object sender, EventArgs e)


{
Button bt = (Button)sender;
nChoose = int.Parse(bt.Text);
picChoose.Image = Image.FromFile(imgPath + nChoose.ToString() + ".png");
}

private void Play()


{
int n = rand.Next(1, 7);
picResult.Image = Image.FromFile(imgPath + n.ToString() + ".png");
nCount++;
string kq;
if (n == nChoose)
{
nWin++;
kq = "Thắng";
}
else
{
nLose++;
kq = "Thua";
}
lbCount.Text = String.Format("Lần đoán: {0}", nCount);
lbWin.Text = String.Format("Lần thắng: {0} ({1:0.00})", nWin, (double)nWin * 100 / nCount);
lbLose.Text = String.Format("Lần thua: {0} ({1:0.00})", nLose, (double)nLose * 100 / nCount);
listResult.Items.Add(String.Format("{0}. {1}, đoán {2} ra {3}", nCount, kq, nChoose, n));
}
private void btPlay_Click(object sender, EventArgs e)
{
Play();
}

protected override bool ProcessDialogKey(Keys keyData)


{
switch (keyData)
{
case Keys.Enter: Play(); break;
case Keys.Escape: Init(); break;
}
return false;
}

private void btReset_Click(object sender, EventArgs e)


{
Init();
}

private void timer1_Tick(object sender, EventArgs e)


{
this.Opacity -= 0.1;
if(this.Opacity <= 0)
{
bClose = true;
Application.Exit();
}
}

private void XucXac_FormClosing(object sender, FormClosingEventArgs e)


{
if (!bClose)
{
e.Cancel = true;
timer1.Enabled = true;
}
}
}
}

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 Chuong6_Laptrinhgiaodien
{
public partial class PhotoAlbum : Form
{
public PhotoAlbum()
{
InitializeComponent();
}

private void PhotoAlbum_Load(object sender, EventArgs e)


{
InitTree();
}

private void InitTree()


{
//Lấy danh sách các ổ đĩa
string[] drives = Directory.GetLogicalDrives();
TreeNode node = null;
foreach(string drv in drives)
{
//Duyệt từng phần tử (tên ổ đĩa), thêm vào TreeView
node = new TreeNode(drv); //Tạo Node mới với tên ổ đĩa
treeFolder.Nodes.Add(node); //Add vào TreeView
node.Nodes.Add("temp"); //Add một node tạm
}
}

private void treeFolder_BeforeExpand(object sender, TreeViewCancelEventArgs e)


{
TreeNode node = e.Node; //Node được chọn
node.Nodes.Clear(); //Xóa các node con (Node temp)
node.ImageIndex = 1; //Chuyển sang icon mở
//Load các danh sách thư mục con
try
{
//Duyệt qua các thư mục con
foreach(string dir in Directory.GetDirectories(node.FullPath))
{
//Thêm các thư mục con vào tập nodes của node hiện tại
TreeNode n = node.Nodes.Add(Path.GetFileName(dir));
n.Nodes.Add("temp");
}
} catch { };
}

private void treeFolder_BeforeCollapse(object sender, TreeViewCancelEventArgs e)


{
e.Node.ImageIndex = 0;
}

private void treeFolder_AfterSelect(object sender, TreeViewEventArgs e)


{
try
{
//Load các file hình lên danh sách
picView.Image = null;
//Lấy danh sách các file trong thư mục Path
string[] arrFiles = Directory.GetFiles(e.Node.FullPath);
pnThum.Controls.Clear(); //Xóa các phần tử trong Flow Panel
foreach(string files in arrFiles)
{
//Duyệt qua các file, chỉ chọn những file ảnh
if(files.ToLower().EndsWith(".jpg") ||
files.ToLower().EndsWith(".gif") ||
files.ToLower().EndsWith(".png") ||
files.ToLower().EndsWith(".bmp") ||
files.ToLower().EndsWith(".jpeg"))
{
//Tạo động PictureBox
PictureBox pic = new PictureBox();
//Thiết lập các thuộc tính cho pic
pic.SizeMode = PictureBoxSizeMode.StretchImage;
pic.Image = Image.FromFile(files);
pic.Height = pnThum.Height - 10;
//Chiều rộng bằng 5 phần 4 chiều cao
pic.Width = pic.Height * 5 / 4;
//Con trỏ hình bàn tay khi trỏ vào hình
pic.Cursor = Cursors.Hand;
pnThum.Controls.Add(pic);
//Tạo hàm sự kiện khi Click lên pic
pic.Click += new EventHandler(pictureBox_Click);
}
}
} catch(Exception ex) {
MessageBox.Show(ex.Message);
};
}

private void pictureBox_Click(object sender, EventArgs e)


{
PictureBox pic = (PictureBox)sender;
picView.Image = pic.Image;

}
}

}
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.Drawing.Drawing2D;

namespace Chuong7_Laptrinhgiaodien
{
public partial class FrmDrawImage : Form
{
public FrmDrawImage()
{
InitializeComponent();
}

private void FrmDrawImage_Paint(object sender, PaintEventArgs e)


{
Rectangle rc1 = new Rectangle(0, 0, ClientRectangle.Width / 2, ClientRectangle.Height / 2);
Rectangle rc2 = new Rectangle(0, ClientRectangle.Height / 2, ClientRectangle.Width / 2, ClientRectangle.Height / 2);
Rectangle rc3 = new Rectangle(ClientRectangle.Width / 2, 0, ClientRectangle.Width / 2, ClientRectangle.Height);
DrawImage(rc1, e.Graphics);
DrawText(rc2, e.Graphics);
DrawPolygon(rc3, e.Graphics);
}

private void DrawImage(Rectangle rc, Graphics g)


{
Image img = Image.FromFile(Application.StartupPath + @"\spring.jpg");
g.DrawImage(img, rc);
//Vẽ chữ
Font f = new Font("Arial", 24, FontStyle.Bold);
SolidBrush br = new SolidBrush(Color.FromArgb(50, 255, 255, 0));
StringFormat fm = new StringFormat();
fm.LineAlignment = StringAlignment.Far;
g.DrawString("Spring", f, br, rc, fm);
}
private void DrawText(Rectangle rc, Graphics g)
{
LinearGradientBrush br = new LinearGradientBrush(rc, Color.Black, Color.White, 45);
g.FillRectangle(br, rc);
LinearGradientBrush lbr = new LinearGradientBrush(new Rectangle(0, 0, 40, 40),
Color.Red, Color.Yellow, LinearGradientMode.BackwardDiagonal);
StringFormat fm = new StringFormat();
fm.Alignment = StringAlignment.Center;
fm.LineAlignment = StringAlignment.Center;
Font f = new Font("Arial", 48, FontStyle.Bold | FontStyle.Italic);
g.DrawString("HELLO", f, lbr, rc, fm);
}
private void DrawPolygon(Rectangle rc, Graphics g)
{
Point[] arrP = {new Point(rc.Left, rc.Height/4),
new Point(rc.Left + rc.Width/2, 0),
new Point(rc.Left + rc.Width, rc.Height/4),
new Point(rc.Left + rc.Width/2, rc.Height)};
GraphicsPath path = new GraphicsPath();
path.AddPolygon(arrP);
PathGradientBrush br = new PathGradientBrush(path);
br.CenterColor = Color.White;
Color[] arrC = { Color.Red, Color.Yellow, Color.Cyan };
br.SurroundColors = arrC;
g.FillPolygon(br, arrP);
}

private void FrmDrawImage_SizeChanged(object sender, EventArgs e)


{
Invalidate();
}

private void FrmDrawImage_Load(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;
using System.Drawing.Drawing2D;
using System.IO;

namespace Chuong7_Laptrinhgiaodien
{
public partial class FrmDrawText : Form
{
public FrmDrawText()
{
InitializeComponent();
}

private void FrmDrawText_Paint(object sender, PaintEventArgs e)


{
Font f = new Font("Arial", 36, FontStyle.Bold);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Far;
e.Graphics.DrawString("HELLO", f, Brushes.Green, ClientRectangle, format);

string imagePath = Application.StartupPath + @"\sky-cloud.jpg";


if (File.Exists(imagePath))
{
// Tạo TextureBrush từ hình ảnh
using (TextureBrush tbr = new TextureBrush(Image.FromFile(imagePath)))
{
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Far;
// Vẽ văn bản với TextureBrush
e.Graphics.DrawString("HELLO", f, tbr, ClientRectangle, format);
}
}
else
{
MessageBox.Show("Không tìm thấy hình ảnh.");
}

HatchBrush hbr = new HatchBrush(HatchStyle.DarkHorizontal, Color.Orange, Color.Yellow);


format.FormatFlags = StringFormatFlags.DirectionVertical;
format.LineAlignment = StringAlignment.Near;
e.Graphics.DrawString("HELLO", f, hbr, ClientRectangle, format);

LinearGradientBrush lbr = new LinearGradientBrush(new Rectangle(50, 50, 10, 10),


Color.Blue, Color.White, 45);
format.Alignment = StringAlignment.Far;
format.LineAlignment = StringAlignment.Far;
e.Graphics.DrawString("HELLO", f, lbr, ClientRectangle, format);
}

private void FrmDrawText_SizeChanged(object sender, EventArgs e)


{
Invalidate();
}

private void FrmDrawText_Load(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 Chuong7_Laptrinhgiaodien
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}

private void menuExit_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void menuDrawText_Click(object sender, EventArgs e)


{
FrmDrawText f = new FrmDrawText();
f.MdiParent = this;
f.Show();
}

private void menuDrawImage_Click(object sender, EventArgs e)


{
FrmDrawImage f = new FrmDrawImage();
f.MdiParent = this;
f.Show();
}

private void menuDrawByMouse_Click(object sender, EventArgs e)


{
FrmDrawByMouse f = new FrmDrawByMouse();
f.MdiParent = this;
f.Show();
}

private void FrmMain_Load(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;
using System.Drawing.Drawing2D;

namespace Chuong7_Laptrinhgiaodien
{
public partial class FrmDrawByMouse : Form
{
Color color; //Màu nét vẽ
int pentWidth; //Độ dày nét vẽ
Point pOld; //Điểm lưu vị trí điểm nhấn chuột
Bitmap bmp; //Vẽ trên bitmap này sau đó mới vẽ trên form
public FrmDrawByMouse()
{
InitializeComponent();
}

private void FrmDrawByMouse_Load(object sender, EventArgs e)


{
color = Color.Red;
pentWidth = 1;
//bmp có kích thước = kích thước màn hình
bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

private void FrmDrawByMouse_MouseDown(object sender, MouseEventArgs e)


{
pOld = e.Location;
}

private void FrmDrawByMouse_MouseMove(object sender, MouseEventArgs e)


{
if(e.Button == MouseButtons.Left)
{
Pen pen = new Pen(color, pentWidth);
pen.StartCap = LineCap.Round;
pen.EndCap = LineCap.Round;
Graphics g = Graphics.FromImage(bmp);
g.DrawLine(pen, pOld, e.Location);
pOld = e.Location;
Invalidate();
}
}

private void FrmDrawByMouse_Paint(object sender, PaintEventArgs e)


{
e.Graphics.DrawImage(bmp, 0, 0);
}

private void FrmDrawByMouse_SizeChanged(object sender, EventArgs e)


{
Invalidate();
}

protected override bool ProcessDialogKey(Keys keyData)


{
switch (keyData)
{
case Keys.R: color = Color.Red; break;
case Keys.G: color = Color.Green; break;
case Keys.B: color = Color.Blue; break;
case Keys.Up: pentWidth++; break;
case Keys.Down: pentWidth--; break;
}
return true;
}
}
}
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 Chuong5_Laptrinhgiaodien
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.KeyPreview = true;
}

int leftDog, leftTurtle, leftSky;


Random rand = new Random();
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}

private void Form1_Load(object sender, EventArgs e)


{
leftDog = picHinhcho.Left;
leftTurtle = picHinhrua.Left;
leftSky = picHinhsky.Left;
}

private void timer1_Tick(object sender, EventArgs e)


{
int widthDog = picHinhcho.Width;
int widthRua = picHinhrua.Width;
int widthSky = picHinhsky.Width;
int start1 = panel1.Right;
int start2 = panel2.Right;
int start3 = panel3.Right;

if (widthDog + picHinhcho.Left < start2)


{
picHinhcho.Left = picHinhcho.Left + rand.Next(5, 16);
}
if(widthRua + picHinhrua.Left < start1)
{
picHinhrua.Left = picHinhrua.Left + rand.Next(5, 16);
}
if(widthSky + picHinhsky.Left < start3)
{
picHinhsky.Left = picHinhsky.Left + rand.Next(5, 16);
}

if(widthDog + picHinhcho.Left >= start2


&& widthRua + picHinhrua.Left >= start1
&& widthSky + picHinhsky.Left >= start3)
{
timer1.Enabled = false;
}
}

private void Form1_KeyDown(object sender, KeyEventArgs e)


{
if(e.KeyData == (Keys.Control | Keys.S))
{
timer1.Enabled = true;
}

if(e.KeyData == (Keys.Control | Keys.R))


{
picHinhcho.Left = 0;
picHinhrua.Left = 0;
picHinhsky.Left = 0;
timer1.Enabled = false;
}
}

private void button1_KeyDown(object sender, KeyEventArgs e)


{

private void panel2_Paint(object sender, PaintEventArgs e)


{

}
private void lbAiWin_Click(object sender, EventArgs e)
{

private void panel3_Paint(object sender, PaintEventArgs e)


{

private void panel1_Paint(object sender, PaintEventArgs e)


{

private void label1_Click(object sender, EventArgs e)


{

private void pictureBox1_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 BTh_Chuong2
{
public partial class Form1 : Form
{
int[] arrInt;
int[] arrTang;
int[] arrGiam;
int[] arrDao;
int[] arrChanLe;
public Form1()
{
InitializeComponent();
}

private void ShowArray(int[] arr, TextBox txtBox)


{
txtBox.Text = String.Empty;
for(int i=0; i<arr.Length; i++)
txtBox.Text += arr[i].ToString() + ",";
txtBox.Text = txtBox.Text.TrimEnd(',');
}
private void btARand_Click(object sender, EventArgs e)
{
txtSoMangkhoitao.Text = "";
txtSoMangtang.Text = "";
txtSoManggiam.Text = "";
txtSoMangdao.Text = "";
txtSoMangchanle.Text = "";

try
{
int sopt = int.Parse(txtSoPT.Text);
arrInt = new int[sopt];
Random rand = new Random();
for(int i=0; i<sopt; i++)
{
arrInt[i] = rand.Next(0, 100);
}
ShowArray(arrInt, txtSoMangkhoitao);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

private void Sort()


{
arrTang = new int[arrInt.Length];
arrGiam = new int[arrInt.Length];
arrDao = new int[arrInt.Length];
try
{
Array.Copy(arrInt, arrTang, arrInt.Length);
Array.Sort(arrTang);
ShowArray(arrTang, txtSoMangtang);

Array.Copy(arrTang, arrGiam, arrTang.Length);


Array.Reverse(arrGiam);
ShowArray(arrGiam, txtSoManggiam);
Array.Copy(arrInt, arrDao, arrInt.Length);
Array.Reverse(arrDao);
ShowArray(arrDao, txtSoMangdao);
} catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

private void swap(ref int a, ref int b)


{
int tmp = a;
a = b;
b = tmp;
}
private void SortSpecial()
{
arrChanLe = new int[arrInt.Length];
Array.Copy(arrInt, arrChanLe, arrInt.Length);
int i = 0, j = arrChanLe.Length - 1;
while (i < j)
{
if (arrChanLe[i] % 2 == 0)
{
i++;
}
if (arrChanLe[j] % 2 != 0)
{
j--;
}
if (i < j)
{
if(arrChanLe[i]%2!=0 && arrChanLe[j] % 2 == 0)
{
swap(ref arrChanLe[i], ref arrChanLe[j]);
i++;
j--;
}
}
}
for(int n=0; n< i-1; n++)
{
for(int m=i+1; m<i; m++)
{
if (arrChanLe[n] > arrChanLe[m])
{
swap(ref arrChanLe[n], ref arrChanLe[m]);
}
}
}
for(int n = i; n<arrChanLe.Length-1; n++)
{
for(int m = n+1; m<arrChanLe.Length; m++)
{
if (arrChanLe[n] < arrChanLe[m])
{
swap(ref arrChanLe[n], ref arrChanLe[m]);
}
}
}
ShowArray(arrChanLe, txtSoMangchanle);
}
private void btSort_Click(object sender, EventArgs e)
{
Sort();
SortSpecial();
}
private void Form1_Load(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 ThemSuaXoaListView
{
public partial class Form1 : Form
{
public Form1()
{

InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void btnThem_Click(object sender, EventArgs e)


{
if((string.IsNullOrEmpty(txtTenPhong.Text)) ||
(string.IsNullOrEmpty(txtSoLuong.Text)))
{
MessageBox.Show("Vui lòng điền đủ thông tin");
}
else
{
ListViewItem item= new ListViewItem();
item.Text = txtTenPhong.Text;
listView1.Items.Add(item);

ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem(item, (txtSoLuong.Text));


item.SubItems.Add(subitem);

txtSoLuong.Clear();
txtTenPhong.Clear();
txtTenPhong.Focus();

private void listView1_SelectedIndexChanged(object sender, EventArgs e)


{

private void btnXoa_Click(object sender, EventArgs e)


{
if (listView1.SelectedItems.Count > 0)
{
DialogResult dl = MessageBox.Show("Bạn muốn xóa", "canh bao", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (dl == DialogResult.OK)
listView1.Items.Remove(listView1.SelectedItems[0]);
}
else MessageBox.Show("Xóa lỗi");
}

private void btnXoaHet_Click(object sender, EventArgs e)


{
listView1.Items.Clear();
}

private void btnThoat_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void inToolStripMenuItem_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.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

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

private void Form1_Load(object sender, EventArgs e)


{

private void label5_Click(object sender, EventArgs e)


{

private void textBox3_TextChanged(object sender, EventArgs e)


{

private void bt1_Click(object sender, EventArgs e)


{
string t = Regex.Replace(textBox1.Text, textBox2.Text, "", RegexOptions.IgnoreCase);
textBox1.Text = t.Replace(textBox1.Text, "");
}

private void bt2_Click(object sender, EventArgs e)


{
int so = int.Parse(textBox4.Text);
textBox1.Text = textBox1.Text.Substring(so) + textBox1.Text.Substring(0, so);
}

private void bt3_Click(object sender, EventArgs e)


{
textBox1.Text = Regex.Replace(textBox1.Text, textBox6.Text, textBox5.Text, RegexOptions.IgnoreCase);
}

private void textBox1_TextChanged(object sender, EventArgs e)


{

private void textBox2_TextChanged(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 Demo2
{
public partial class ListViewDemo : Form
{
public ListViewDemo()
{
InitializeComponent();
}

private void Btn_Them_Click(object sender, EventArgs e)


{
if (Txt_Ten.Text == "") return;
ListViewItem item = new ListViewItem(Txt_Ten.Text);
item.SubItems.Add(Rb_Nam.Checked ? "Nam" : "Nữ");
item.ImageIndex = (Rb_Nam.Checked ? 0 : 1);
item.SubItems.Add(Dp_ngaySinh.Value.ToString("dd/MM/yyyy"));
Txt_Ten.Text = "";
Txt_Ten.Focus();
LV.Items.Add(item);
}

private void Btn_Xoa_Click(object sender, EventArgs e)


{
foreach(ListViewItem i in LV.SelectedItems)
{
LV.Items.Remove(i);
}
}
private void Dp_ngaySinh_ValueChanged(object sender, EventArgs e)
{

private void LV_SelectedIndexChanged(object sender, EventArgs e)


{

private void Rb_Nam_CheckedChanged(object sender, EventArgs e)


{

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)


{

private void listView1_SelectedIndexChanged(object sender, EventArgs e)


{

private void ListViewDemo_Load(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.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

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

private void Form1_Load(object sender, EventArgs e)


{

private void label5_Click(object sender, EventArgs e)


{

private void textBox3_TextChanged(object sender, EventArgs e)


{

private void bt1_Click(object sender, EventArgs e)


{
string t = Regex.Replace(textBox1.Text, textBox2.Text, "", RegexOptions.IgnoreCase);
textBox1.Text = t.Replace(textBox1.Text, "");
}

private void bt2_Click(object sender, EventArgs e)


{
int so = int.Parse(textBox4.Text);
textBox1.Text = textBox1.Text.Substring(so) + textBox1.Text.Substring(0, so);
}

private void bt3_Click(object sender, EventArgs e)


{
textBox1.Text = Regex.Replace(textBox1.Text, textBox6.Text, textBox5.Text, RegexOptions.IgnoreCase);
}

private void textBox1_TextChanged(object sender, EventArgs e)


{

}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy