Đáp án môn lập trình c

18 1.1K 1
Đáp án môn lập trình c

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ĐÁP ÁN CÂU 10 ĐIỂM Câu Ý Nội dung Xây dựng chương trình soạn thảo văn Thiết kế giao diện: Mở Microsoft Visual Studio, tạo đặt tên ứng dụng Tạo form, đặt tên form, tên tiêu đề form Tạo mainMenu Tạo menuItem File submenuItem New, Open, Save, Exit mainMenu Tạo menuItem Edit submenuItem Cut, Copy, Paste mainMenu Tạo menuItem Format submenuItem Font mainMenu Tạo menuItem Help submenuItem About mainMenu Sử dụng TextBox làm vùng soạn thảo Thuộc tính Giá trị name txtnoidung font Time New Roman readonly False Multiline true Xây dựng phương thức xử lý: - Chức tạo file (File\New) private void mnew_Click(object sender, System.EventArgs e) { checkdirty(); } private void checkdirty() { if (dirty) { DialogResult click = MessageBox.Show(this,"Do You wish to save this Document?","Save",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Qu estion,MessageBoxDefaultButton.Button1); if (click == DialogResult.Yes) { savedata(); txt.Text=""; fname = ""; dirty = false; } if (click == DialogResult.No) { txt.Text=""; fname = ""; dirty = false; } } else { txt.Text = ""; fname = ""; } } - Chức mở file đĩa (File\Open) Từ Toolbox kéo công cụ OpenFileDialog vào form, đặt tên đối tượng ofd private void mopen_Click(object sender, System.EventArgs e) { ofd.Multiselect = false; ofd.Filter = "Text Files|*.txt"; ofd.ShowDialog(); if (File.Exists(ofd.FileName)) { fname = ofd.FileName; StreamReader sr = new StreamReader(fname); txt.Text=sr.ReadToEnd(); dirty = false; sr.Close(); } } - Chức lưu file lên đĩa (File\Save) Từ Toolbox kéo công cụ SaveFileDialog vào form, đặt tên đối tượng sfd private void msave_Click(object sender, System.EventArgs e) { savedata(); } private void savedata() { if (fname == "") { sfd.Filter = "Text Files|*.txt"; DialogResult res = sfd.ShowDialog(); if (res == DialogResult.Cancel) { return; } fname = sfd.FileName; MessageBox.Show(fname); } StreamWriter sw = new StreamWriter(fname); sw.WriteLine(txt.Text); sw.Flush(); sw.Close(); dirty = false; } - Chức thoát ứng dụng (File\Exit) private void mexit_Click(object sender, System.EventArgs e) { checkdirty(); this.Dispose(); } - Chức Cut (Edit\Cut) private void mcut_Click(object sender, System.EventArgs e) { txt.Cut(); dirty = true; } - Chức Copy (Edit\Copy) private void mcopy_Click(object sender, System.EventArgs e) { Clipboard.SetDataObject(txt.SelectedText, true); } - Chức Paste (Edit\Paste) private void mpaste_Click(object sender, System.EventArgs e) { IDataObject iData = Clipboard.GetDataObject(); if (iData.GetDataPresent(DataFormats.Text)) { txt.SelectedText = iData.GetData(DataFormats.Text).ToString(); } } - Chức định dạng văn (Format\Font) Từ Toolbox kéo công cụ FontDialog vào form, đặt tên đối tượng fd private void mfont_Click(object sender, System.EventArgs e) { fd.ShowColor = true; fd.ShowDialog(); txt.Font = fd.Font; txt.ForeColor=fd.Color; } - Chức About (Help\About) Trong cửa sổ Solution Explorer, bấm chuột phải vào tên ứng dụng, chọn mục Add\Windows form, cửa sổ chọn About form Trong cửa sổ Properties đặt tên cho đối tượng form NewForm mục name private void mabout_Click(object sender, System.EventArgs e) { NewForm nf = new NewForm(); nf.ShowDialog(); } Câu Ý Nội dung Xây dựng chương trình soạn thảo văn Thiết kế giao diện - Mở ứng dụng Microsoft Visual Studio, tạo Project - Đặt tên Form F_chinh, thay đổi tiêu đề Form - Tạo menu cho Form: + Trong cửa sổ Toolbox, chọn mục Menu&Toolbars kéo công cụ MenuStrip thả vào form, đặt tên cho menu + Tạo menu File submenu Exit - Tạo công cụ tắt: + Trong cửa sổ Toolbox, chọn mục Menu&Toolbars kéo công cụ ToolStrip thả vào form, đặt tên cho công cụ + Trên công cụ vừa tạo, tạo button: tạo file mới, mở file có, ghi file…, comboBox chọn font chữ, cỡ chữ - Tạo Form con: + Bấm chuột phải vào tên ứng dụng, chọn mục Add, chọn Windows Form Trong cửa sổ chọn kiểu form Windows Form, đặt tên cho form F_con + Trên Form kéo thả công cụ TextBox vào làm vùng soạn thảo Thuộc tính Giá trị name Txtnoidung font Time New Roman readonly False Multiline true Xây dựng phương thức xử lý: - Tạo file mới: void taomoi() { F_con fc = new F_con(); fc.MdiParent = this; fc.Text = "Document " + (stt++).ToString(); closeToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; tsmauto.Enabled = true; toolStripSave.Enabled = true; fc.Show(); } void newopen(string s) { F_con fc = new F_con(); fc.MdiParent = this; fc.Text = s; closeToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; toolStripSave.Enabled = true; fc.Show(); } private void toolStripButton1_Click(object sender, EventArgs e) { taomoi(); } - Mở file có đĩa: Từ Toolbox kéo công cụ OpenFileDialog vào form, đặt tên đối tượng open void openfile() { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Text Files (.txt)|*.txt|Ms Word Files (.doc)|*.doc|Rich Text Files (.rtf)|*.rtf|All Files (*.*)|*.*"; open.Multiselect = true; open.FilterIndex = 2; if (open.ShowDialog() == DialogResult.OK) { newopen(open.FileName); ((F_con)this.ActiveMdiChild).txtnoidung.LoadFile(open.FileName); } } private void toolStripButton2_Click(object sender, EventArgs e) { openfile(); } - Ghi file có soạn thảo: Từ Toolbox kéo công cụ SaveFileDialog vào form, đặt tên đối tượng savefile void savefile_new() { SaveFileDialog savefile = new SaveFileDialog(); savefile.Filter = "Text Files (.txt)|*.txt|Ms Word Files (.doc)|*.doc|Rich Text Files (.rtf)|*.rtf|All Files (*.*)|*.*"; savefile.FilterIndex = 2; savefile.RestoreDirectory = true; if (savefile.ShowDialog() == DialogResult.OK) { ((F_con)this.ActiveMdiChild).txtnoidung.SaveFile(savefile.FileName ); ((F_con)this.ActiveMdiChild).Text = savefile.FileName; } } void SaveFileTong() { string s = this.ActiveMdiChild.Text; if (s.Substring(0, 8).Equals("Document")) { savefile_new(); } else { ((F_con)this.ActiveMdiChild).txtnoidung.SaveFile(s); } } private void toolStripSave_Click(object sender, EventArgs e) { SaveFileTong(); } Câu Ý Nội dung Xây dựng chương trình xử lý văn Thiết kế giao diện: - Mở Microsoft Visual Studio, tạo đặt tên ứng dụng - Tạo form, đặt tên form, thay đổi tiêu đề form - Tạo textBox chứa nội dung văn bản, thay đổi số thuộc tính textBox cho phù hợp - Tạo label với text Find what, Replace with - Tạo textBox để nhập vào từ cần tìm kiếm, đặt tên textBox - Tạo textBox để nhập vào từ cần thay thế, đặt tên textBox - Tạo button Find, đặt tên button - Tạo button Find next, đặt tên button - Tạo button Replace, đặt tên button - Tạo button Replace all, đặt tên button - Tạo button Undo, đặt tên button - Tạo button Exit, đặt tên button Xây dựng phương thức xử lý: - Xử lý người dùng nhấn button Find private void btnTim_Click(object sender, EventArgs e) { if (txtVanBan.Text == "") MessageBox.Show("Bạn chưa nhập nội dung văn bản", "Thông báo"); BatDau = txtVanBan.Text.IndexOf(txtChuoiTim.Text, StringComparison.OrdinalIgnoreCase); if (BatDau >= 0) { txtVanBan.SelectionStart = BatDau; txtVanBan.SelectionLength = txtChuoiTim.TextLength; txtVanBan.Focus(); VitriBD=BatDau+txtChuoiTim.TextLength; } else { MessageBox.Show("Không có chuỗi văn bản", "Tìm Kiếm"); BatDau = 0; } } - Xử lý người dùng nhấn button Find Next private void btnTimtiep_Click(object sender, EventArgs e) { if (txtVanBan.Text == "") MessageBox.Show("Bạn chưa nhập nội dung văn bản", "Thông báo"); int TimTiep; if (VitriBD > txtVanBan.TextLength txtChuoiTim.TextLength) { MessageBox.Show("Không tìm thấy chuổi, hết văn bản", "Tìm Tiếp"); VitriBD = 0; return; } TimTiep = txtVanBan.Text.IndexOf(txtChuoiTim.Text, VitriBD, StringComparison.OrdinalIgnoreCase); if (TimTiep >= 0) { txtVanBan.SelectionStart = TimTiep; txtVanBan.SelectionLength = txtChuoiTim.TextLength; txtVanBan.Focus(); VitriBD = TimTiep + txtChuoiTim.TextLength; } else { if (VitriBD == 0) { MessageBox.Show("Không có chuỗi văn bản", "Tìm kiếm"); } else { MessageBox.Show("Không tìm thấy chuổi, hết văn bản", "Tìm Tiếp"); VitriBD = 0; } } } - Xử lý người dùng nhấn button Replace private void btnThayThe_Click(object sender, EventArgs e) { if (txtVanBan.Text == "") MessageBox.Show("Bạn chưa nhập nội dung văn bản", "Thông báo"); else NoiDung = txtVanBan.Text; if (txtChuoiTim.Text == "") { MessageBox.Show("Chưa có chuỗi cần tìm", "Tìm thay thế"); return; } BatDau = txtVanBan.Text.IndexOf(txtChuoiTim.Text, VitriBD, StringComparison.OrdinalIgnoreCase); if (BatDau >= 0) { txtVanBan.SelectionStart = BatDau; txtVanBan.SelectionLength = txtChuoiTim.TextLength; VitriBD = BatDau + txtChuoiTim.TextLength; txtVanBan.Focus(); txtVanBan.SelectedText = txtVanBan.SelectedText.Replace(txtVanBan.SelectedText, txtChuoiThay.Text); } else { if (VitriBD == 0) { MessageBox.Show("Không có chuỗi văn bản", "Tìm thay thế"); } else { MessageBox.Show("Không tìm thấy,đã hết văn bản", "Tìm thay thế"); BatDau = 0; VitriBD = 0; } } } - Xử lý người dùng nhấn button Replace All private void btnThayTatCa_Click(object sender, EventArgs e) { if (txtVanBan.Text == "") MessageBox.Show("Bạn chưa nhập nội dung văn bản", "Thông báo"); if (txtChuoiTim.Text == "") { MessageBox.Show("Chưa có chổ cần tìm", "Tìm thay thế"); return; } BatDau = txtVanBan.Text.IndexOf(txtChuoiTim.Text, VitriBD,StringComparison.OrdinalIgnoreCase); if (BatDau == -1) { MessageBox.Show("Không có chuỗi văn bản", "Tìm thay thế"); BatDau = 0; return; } while (BatDau >= 0) { txtVanBan.SelectionStart = BatDau; txtVanBan.SelectionLength = txtChuoiTim.TextLength; VitriBD = BatDau + txtChuoiTim.TextLength; txtVanBan.Focus(); txtVanBan.SelectedText = txtVanBan.SelectedText.Replace(txtVanBan.SelectedText,txtChuoiTha y.Text); BatDau = txtVanBan.Text.IndexOf(txtChuoiTim.Text, VitriBD,StringComparison.OrdinalIgnoreCase); } MessageBox.Show("Đã hết văn bản", "Tìm thay thế"); BatDau = 0; VitriBD = } - Xử lý người dùng nhấn button Undo (noidung = txtVanban.text) private void btnLamlai_Click(object sender, EventArgs e) { txtVanBan.Text = NoiDung; txtChuoiTim.Clear(); txtChuoiThay.Clear(); txtChuoiTim.Focus(); BatDau = 0; VitriBD = 0; } - Xử lý người dùng nhấn button Exit private void btnThoat_Click(object sender, EventArgs e) { this.Close(); } Câu Ý Nội dung Xây dựng chương trình vẽ hình Thiết kế giao diện: - Mở Microsoft Visual Studio, tạo đặt tên ứng dụng - Tạo form, đặt tên form, thay đổi tiêu đề form - Tạo toolStrip dùng để chứa mục chọn chức - Trên toolStrip thêm mục: Pen Size, PenColor, Clear, BackGround Color, Draw Shape - Tạo numericUpDown dùng để giá trị Pen Size - Tạo numericUpDown dùng để giá trị Shape Size - Tạo Panel dùng để làm cửa sổ vẽ Xây dựng phương thức xử lý: - Xử lý xự kiện người dùng chọn màu vẽ (PenColor) private void toolStripButton1_Click(object sender, EventArgs e) { ColorDialog cd = new ColorDialog(); if (cd.ShowDialog() == DialogResult.OK) { toolStripButton1.ForeColor = cd.Color; } } - Xử lý xự kiện người dùng chọn màu (BachGround Color) private void toolStripButton3_Click(object sender, EventArgs e) { ColorDialog cd = new ColorDialog(); if (cd.ShowDialog() == DialogResult.OK) { toolStripButton3.ForeColor = cd.Color; panel1.BackColor = cd.Color; } } - Xử lý kiện người dùng muốn xóa tất hình cửa sổ vẽ (Clear) private void toolStripButton2_Click(object sender, EventArgs e) { _g.Clear(panel1.BackColor); } - Xử lý kiện người dùng vẽ bút vẽ private void panel1_MouseMove(object sender, MouseEventArgs e) { if (_canPaint) { Pen pen = new Pen(toolStripButton1.ForeColor, float.Parse(numericUpDown1.Value.ToString())); _g.DrawLine(pen, new Point(_preX, _preY), new Point(e.X, e.Y)); } _preX = e.X; _preY = e.Y; } - Xử lý kiện người dùng vẽ hình vuông, hình chữ nhật, hình tròn private void panel1_MouseDown(object sender, MouseEventArgs e) { _canPaint = true; if (_drawSquare) { _canPaint = false; _drawSquare = false; SolidBrush sb = new SolidBrush(toolStripButton1.ForeColor); _g.FillRectangle(sb, e.X, e.Y, int.Parse(numericUpDown2.Value.ToString()), int.Parse(numericUpDown2.Value.ToString())); } else if (_drawRectangle) { _canPaint = false; _drawRectangle = false; SolidBrush sb = new SolidBrush(toolStripButton1.ForeColor); _g.FillRectangle(sb, e.X, e.Y, int.Parse(numericUpDown2.Value.ToString()) * 2, int.Parse(numericUpDown2.Value.ToString())); } else if (_drawCircle) { _canPaint = false; _drawCircle = false; SolidBrush sb = new SolidBrush(toolStripButton1.ForeColor); _g.FillEllipse(sb, e.X, e.Y, int.Parse(numericUpDown2.Value.ToString()), int.Parse(numericUpDown2.Value.ToString())); } } Câu Ý Nội dung Xây dựng chương trình quản lý học sinh Thiết kế CSDL: - Mở Microsoft SQL Server Management Studio tạo sở liệu HocSinh - Trong sở liệu tạo tạo bảng hocsinh có cấu trúc theo yêu cầu - Nhập thông tin học sinh Thiết kế giao diện:` - Mở Microsoft Visual Studio, tạo đặt tên ứng dụng - Tạo form, đặt tên form, thay đổi tiêu đề form - Tạo label có text Mã học sinh, textBox chứa mã học sinh, đặt tên textBox - Tạo label có text Họ tên, textBox chứa họ tên học sinh, đặt tên textBox - Tạo label có text Ngày sinh, textBox chứa ngày sinh, đặt tên textBox - Tạo label có text Giới tính, textBox chứa giới tính, đặt tên textBox - Tạo label có text Quê quán, textBox chứa quê quán, đặt tên textBox - Tạo label có text Email, textBox chứa email, đặt tên textBox - Tạo đặt tên button điều khiển việc xem thông tin học sinh - Tạo button Add New, đặt tên cho button - Tạo button Save, đặt tên cho button - Tạo button Edit, đặt tên cho button - Tạo button Delete, đặt tên cho button - Tạo button Cancel, đặt tên cho button Viết phương thức xử lý: - Tạo kết nối đến sở liệu: public frmHocsinh() { InitializeComponent(); // Kết nối CSDL connectionString = "Server=TUQUYEN; Database=hocsinh; Trusted_connection=true"; sqlconHocsinh = new SqlConnection(connectionString); sqlcomHocsinh = new SqlCommand(); } - Xử lý kiện form_load private void frmHocsinh_Load(object sender, EventArgs e) { try { ClearControls(); //ClearControls if (sqlconHocsinh.State == ConnectionState.Open) { sqlconHocsinh.Close(); } sqlconHocsinh.Open(); sqlcomHocsinh.CommandText = "Select * from hocsinh"; sqlcomHocsinh.Connection = sqlconHocsinh; sqldreaderHocsinh = sqlcomHocsinh.ExecuteReader(); if (sqldreaderHocsinh.HasRows) { sqldreaderHocsinh.Read(); DisplayResults(); if (sqldreaderHocsinh.Read()) { btnNext.Enabled = true; btnEnd.Enabled = true; rowNumber = rowNumber + 1; btnPre_Click(null, null); } else { btnNext.Enabled = false; btnEnd.Enabled = false; btnFirst.Enabled = false; btnPre.Enabled = false; } btnEdit.Enabled = true; btnDelete.Enabled = true; } else { DisableButtons(); } btnCancel.Enabled = false; btnSave.Enabled = false; btnAdd.Enabled = true; } catch (SqlException sqlexchocsinh) { MessageBox.Show("Lỗi kết nối CSDL", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information); sqlconHocsinh.Close(); } } void DisplayResults() { txtMahs.Text = sqldreaderHocsinh.GetString(0); txtHoten.Text = sqldreaderHocsinh.GetString(1); txtGioitinh.Text = sqldreaderHocsinh.GetString(2); txtQuequan.Text = sqldreaderHocsinh.GetString(3); txtEmail.Text = sqldreaderHocsinh.GetString(4); txtNgaysinh.Text = sqldreaderHocsinh.GetString(5); } - Xử lý kiện người dùng nhấn button điều khiển: btnNext, btnPre, btnFirst, btnEnd private void btnNext_Click(object sender, EventArgs e) { if (sqldreaderHocsinh.Read()) { rowNumber = rowNumber + 1; DisplayResults(); } else { MessageBox.Show("Đây ghi cuối", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); btnNext.Enabled = false; btnEdit.Enabled = false; } btnFirst.Enabled = true; btnPre.Enabled = true; } private void btnEnd_Click(object sender, EventArgs e) { while (sqldreaderHocsinh.Read()) { rowNumber = rowNumber + 1; DisplayResults(); } btnNext.Enabled = false; btnEnd.Enabled = false; btnPre.Enabled = true; btnFirst.Enabled = true; } private void btnFirst_Click(object sender, EventArgs e) { if (!sqldreaderHocsinh.IsClosed) { sqldreaderHocsinh.Close(); } sqldreaderHocsinh = sqlcomHocsinh.ExecuteReader(); if (rowNumber != 0) { sqldreaderHocsinh.Read(); DisplayResults(); rowNumber = 0; } else { MessageBox.Show("Đây ghi đầu tiên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); sqldreaderHocsinh.Read(); } btnPre.Enabled = false; btnFirst.Enabled = false; btnNext.Enabled = true; btnEdit.Enabled = true; } private void btnPre_Click(object sender, EventArgs e) { int currentRowNumber = 0; if (!sqldreaderHocsinh.IsClosed) { sqldreaderHocsinh.Close(); } sqldreaderHocsinh = sqlcomHocsinh.ExecuteReader(); if (rowNumber != 0) { while (currentRowNumber < rowNumber) { currentRowNumber = currentRowNumber + 1; sqldreaderHocsinh.Read(); } DisplayResults(); rowNumber = rowNumber - 1; } else { MessageBox.Show("Đây ghi đầu tiên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); sqldreaderHocsinh.Read(); } btnNext.Enabled = true; btnEdit.Enabled = true; } - Xử lý kiện thêm mới, sửa ghi private void btnSave_Click(object sender, EventArgs e) { string addNewString = ""; int index = 0; if (operation == "addnew") { addNewString = "insert into Hocsinh(mahs, hoten, gioitinh, quequan, email, ngaysinh) values ('" + txtMahs.Text + "','" + txtHoten.Text + "','" + txtGioitinh.Text + "'," + txtQuequan.Text + ",'" + txtEmail.Text + "," + txtNgaysinh.Text+ ")"; } else if (operation == "edit") { addNewString = "update hocsinh set hoten='" + txtHoten.Text + "', ngaysinh=" + txtNgaysinh.Text + ",gioitinh='" + txtGioitinh.Text + ",quequan='" + txtQuequan.Text + "',email=" + txtEmail.Text + "Where mahs='" + txtMahs.Text + "'"; } if (operation != "") { if (!sqldreaderHocsinh.IsClosed) { sqldreaderHocsinh.Close(); } sqlcomHocsinh.CommandText = addNewString; sqlcomHocsinh.Connection = sqlconHocsinh; record = "mahs: " + txtMahs.Text + "\nhoten: " + txtHoten.Text + "\ngioitinh: " + txtGioitinh.Text + "\nquequan: " + txtQuequan.Text + "\nemail: " + txtEmail.Text + "\nngaysinh: " + txtNgaysinh.Text; sqlcomHocsinh.ExecuteNonQuery(); MessageBox.Show("Đã cập nhật thành công thông tin học sinh\n" + record,"Hoc sinh",MessageBoxButtons.OK,MessageBoxIcon.Information); frmHocsinh_Load(null,null); } } private void btnEdit_Click(object sender, EventArgs e) { DisableButtons(); operation = "edit"; btnAdd.Enabled = false; btnSave.Enabled = true; btnCancel.Enabled = true; } private void btnCancel_Click(object sender, EventArgs e) { operation = ""; frmHocsinh_Load(null,null); } - Xử lý kiện xóa ghi private void btnDelete_Click(object sender, EventArgs e) { record = "mahs: " + txtMahs.Text + "\nHo ten: " + txtHoten.Text +"\nNgay sinh: " + txtNgaysinh.Text + "\nEmail: " + txtEmail.Text + "\nGioi tinh: " + txtGioitinh.Text + "\nQue quan: " + txtQuequan.Text; if (!sqldreaderHocsinh.IsClosed) { sqldreaderHocsinh.Close(); } sqlcomHocsinh.CommandText = "Delete from hocsinh Where mahs='" + txtMahs.Text + "'"; if (sqlconHocsinh.State == ConnectionState.Open) { sqlconHocsinh.Close(); } sqlconHocsinh.Open(); sqlcomHocsinh.ExecuteNonQuery(); sqlconHocsinh.Close(); MessageBox.Show("Thông tin học sinh xóa thành công\n" + record, "Hoc sinh", MessageBoxButtons.OK, MessageBoxIcon.Information); frmHocsinh_Load(null, null); } Câu Ý Nội dung Xây dựng ứng dụng mô máy tính bỏ túi để thực phép toán số học (cộng, trừ, nhân, chia) Thiết kế giao diện: - Mở Microsoft Visual Studio, tạo đặt tên ứng dụng - Tạo form, đặt tên form, thay đổi tiêu đề form - Tạo label textBox dùng để chứa thông kết tính toán Nếu textBox cần đặt thuộc tính readonly = true Đặt tên cho công cụ [...]... Database=hocsinh; Trusted_connection=true"; sqlconHocsinh = new SqlConnection(connectionString); sqlcomHocsinh = new SqlCommand(); } - Xử lý sự kiện form_load private void frmHocsinh_Load(object sender, EventArgs e) { try { ClearControls(); //ClearControls if (sqlconHocsinh.State == ConnectionState.Open) { sqlconHocsinh.Close(); } sqlconHocsinh.Open(); sqlcomHocsinh.CommandText = "Select * from hocsinh"; sqlcomHocsinh.Connection... sqldreaderHocsinh.Close(); } sqlcomHocsinh.CommandText = "Delete from hocsinh Where mahs='" + txtMahs.Text + "'"; if (sqlconHocsinh.State == ConnectionState.Open) { sqlconHocsinh.Close(); } sqlconHocsinh.Open(); sqlcomHocsinh.ExecuteNonQuery(); sqlconHocsinh.Close(); MessageBox.Show("Thông tin c a h c sinh đã xóa thành c ng\n" + record, "Hoc sinh", MessageBoxButtons.OK, MessageBoxIcon.Information); frmHocsinh_Load(null,... btnThoat_Click(object sender, EventArgs e) { this.Close(); } C u Ý 4 Nội dung Xây dựng chương trình vẽ hình Thiết kế giao diện: - Mở Microsoft Visual Studio, tạo và đặt tên ứng dụng - Tạo form, đặt tên form, thay đổi tiêu đề c a form - Tạo toolStrip dùng để chứa c c m c chọn ch c năng - Trên toolStrip thêm đư c c c m c: Pen Size, PenColor, Clear, BackGround Color, Draw Shape - Tạo numericUpDown dùng để chỉ... dùng chọn màu nền (BachGround Color) private void toolStripButton3_Click(object sender, EventArgs e) { ColorDialog cd = new ColorDialog(); if (cd.ShowDialog() == DialogResult.OK) { toolStripButton3.ForeColor = cd.Color; panel1.BackColor = cd.Color; } } - Xử lý sự kiện khi người dùng muốn xóa tất c c c hình trên c a sổ vẽ (Clear) private void toolStripButton2_Click(object sender, EventArgs e) { _g.Clear(panel1.BackColor);... tên c c button điều khiển vi c xem thông tin h c sinh - Tạo button Add New, đặt tên cho button này - Tạo button Save, đặt tên cho button này - Tạo button Edit, đặt tên cho button này - Tạo button Delete, đặt tên cho button này - Tạo button Cancel, đặt tên cho button này Viết c c phương th c xử lý: - Tạo kết nối đến c sở dữ liệu: public frmHocsinh() { InitializeComponent(); // Kết nối CSDL connectionString... Xây dựng chương trình quản lý h c sinh Thiết kế CSDL: - Mở Microsoft SQL Server Management Studio tạo c sở dữ liệu HocSinh - Trong c sở dữ liệu đã tạo tạo bảng hocsinh c c u tr c theo yêu c u - Nhập đư c thông tin c a ít nhất 5 h c sinh Thiết kế giao diện:` - Mở Microsoft Visual Studio, tạo và đặt tên ứng dụng - Tạo form, đặt tên form, thay đổi tiêu đề c a form - Tạo label c text là Mã h c sinh,... sqlcomHocsinh.ExecuteNonQuery(); MessageBox.Show("Đã c p nhật thành c ng thông tin c a h c sinh\n" + record,"Hoc sinh",MessageBoxButtons.OK,MessageBoxIcon.Information); frmHocsinh_Load(null,null); } } private void btnEdit_Click(object sender, EventArgs e) { DisableButtons(); operation = "edit"; btnAdd.Enabled = false; btnSave.Enabled = true; btnCancel.Enabled = true; } private void btnCancel_Click(object... dùng để chỉ giá trị c a Pen Size - Tạo numericUpDown dùng để chỉ giá trị c a Shape Size - Tạo Panel dùng để làm c a sổ vẽ Xây dựng c c phương th c xử lý: - Xử lý xự kiện khi người dùng chọn màu vẽ (PenColor) private void toolStripButton1_Click(object sender, EventArgs e) { ColorDialog cd = new ColorDialog(); if (cd.ShowDialog() == DialogResult.OK) { toolStripButton1.ForeColor = cd.Color; } } - Xử lý... null); } C u Ý 6 Nội dung Xây dựng ứng dụng mô phỏng một máy tính bỏ túi để th c hiện c c phép toán số h c (c ng, trừ, nhân, chia) Thiết kế giao diện: - Mở Microsoft Visual Studio, tạo và đặt tên ứng dụng - Tạo form, đặt tên form, thay đổi tiêu đề c a form - Tạo label ho c textBox dùng để chứa thông và kết quả tính toán Nếu là textBox thì c n đặt thu c tính readonly = true Đặt tên cho c ng c ... btnNext.Enabled = true; btnEdit.Enabled = true; } private void btnPre_Click(object sender, EventArgs e) { int currentRowNumber = 0; if (!sqldreaderHocsinh.IsClosed) { sqldreaderHocsinh.Close(); } sqldreaderHocsinh = sqlcomHocsinh.ExecuteReader(); if (rowNumber != 0) { while (currentRowNumber < rowNumber) { currentRowNumber = currentRowNumber + 1; sqldreaderHocsinh.Read(); } DisplayResults(); rowNumber = rowNumber

Ngày đăng: 29/03/2016, 10:43

Tài liệu cùng người dùng

Tài liệu liên quan