Bài tập windows form c có lời giải năm 2024

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

private void button1_Click(object sender, EventArgs e) { string s1Text = s1; string s2Text = s2;

int s1Int = int(s1Text); int s2Int = int(s2Text);

long sumLong = 0; sumLong = s1Int + s2Int; sum = sumLong();

####### }

####### }

####### }

Form1.Designer

namespace WindowsFormsApplication

####### {

partial class Form

this.sum = new System.Drawing(176, 251); this.sum = true; this.sum = "sum"; this.sum = new System.Drawing(163, 35); this.sum = 5; // // label // this.label3 = true; this.label3 = new System.Drawing("Microsoft Sans Serif", 13F); this.label3 = new System.Drawing(44, 264); this.label3 = "label3"; this.label3 = new System.Drawing(82, 22); this.label3 = 6; this.label3 = "Kết qu¿: "; // // label // this.label4 = true; this.label4 = new System.Drawing("Microsoft Sans Serif", 16F); this.label4 = new System.Drawing(86, 34); this.label4 = "label4"; this.label4 = new System.Drawing(313, 26); this.label4 = 7; this.label4 = "TÍNH TỔNG HAI SỐ NGUYÊN"; // // Form // this = new System.Drawing(6F, 13F); this = System.Windows.Forms.AutoScaleMode; this = new System.Drawing(500, 329); this.Controls(this); this.Controls(this); this.Controls(this); this.Controls(this); this.Controls(this); this.Controls(this); this.Controls(this); this.Controls(this); this = "Form1"; this = "Form1"; this(false); this();

####### }

endregion

private System.Windows.Forms s1; private System.Windows.Forms s2; private System.Windows.Forms label1; private System.Windows.Forms label2; private System.Windows.Forms sumBtn; private System.Windows.Forms sum; private System.Windows.Forms label3; private System.Windows.Forms label4; } }

Bài tập có gợi ý:

Bài 1 : Viết chương trình nhập vào 2 số a và b, cho biết số lớn nhất và số nhỏ nhất

trong 2 số a, b với giao diện như sau:

Hướng dẫn gợi ý: Sử dụng cấu trúc If... else.

using System; using System.Collections; using System; using System; using System; using System; using System; using System.Threading; using System.Windows;

Tuần 1

Bài Tập 1.1

Hãy thiết kế giao diện một form như sau:Viết lệnh để chương trình hoạt động như sau:

Nhấn vào button btnHolot thì gán nội dung của txtHolot cho lblHolot (lblHolot.Text = txtHolot.text)

Nhấn vào button cmdTen thì gán nội dung của txtTen cho lblTen (lblTen.Text = txtTen.text)

Nhấn vào button btnHoVaTen thì gán nội dung của txtHolot cộng với txtTen cho lblHoVaTenlblHoVaTen.Text = txtHolot.text + “ “ + txtTen.Text)

Nhấn double click vào lblHoVaTen thì nội dung của lblHoVaTen bị xoá

Nhấn vào btnKetThuc thi đóng chương trình (this.Close() hoặc Application.Exit())

Bài tập 1.2

Thêm vào bài tập 1 với các yêu cầu sau: Nội dung của txtHoLot và txtTen được thể hiện ngay trên lblHoLot và LblTen khi user nhập dữ liệu vàotxtHoLot hay txtTen

(gợi ý : viết lệnh cho sự kiện TextChanged của txtHoLot va txtTen)

Bài Tập 1.3

txtHoLottxtTenlblHoLotlblTen btnHoLotlblHoVaTen

BÀI TẬP WINDOWS FORM

Yêu cầu:1.Thiết kế phải kéo đối tược tooltip vào form (nó hiện phần tray, khay phía duới form xemhình) thì mới tạo tooltip được.2.Khi chương trình chay lệna.Hiện tên người hướngdẫn mặc định vào ô người hướng dẫn (tùy ý họ tên sinh viên)hướng dẫn viết trong formload hặc trong design.

private

void

FrmLightSwitcher_Load(

object

sender,

EventArgs

e){txtnguoihuongdan.Text \=

"Nguyễn Văn Tuấn"

;lblhuongdan.Text =

"Click the light to turn off"

+ txtnguoihuongdan.Text;}

b.Hình đèn picOn (hình đèn mở) được hiện hướng dẫn hiệu chỉnh property trongdesign.c.Ô hướng dẫn là “Nếu nhấn vào tôi thì đèn tắt + giá trị ô người hướng dẫn” hướngdẫn xem đoạn code trên.d.Nếu đưa chuột vào hình đèn thì hiện tooltip là “Nhấn tôi thì tắt” cho đèn mở vàngược lại cho đèn tắt hướng dẫn cách làm hiệu chỉnh trong phần design.3.Nếu nhấn vào đèn picOn thì:a. picOn ẩn đi và hiện hình đèn picOff b.Đồng thời ô Hướng dẫn hiện “Nhấn tôi thì mở + giá trị ô người hướng dẫn” hướngdẫn cách làm viết trong sự kiện đèn chọn.

private

void

picmo_Click(

object

sender,

EventArgs

e){picmo.Visible =

false

;// công viêc 1pictat.Visible =

true

; // công viêc 1lblhuongdan.Text =

"Click the light to turn on."

+

" "

+ txtnguoihuongdan.Text; // công việc 2}

4.Nhấn nút thoát hoặc Esc thì thoát chương trình.

5.

Khi đưa chuột vảo hình thì hiện lên Tooltip “Click me” (Xem hình)

txtHuongDan picOff picOnlblHuongDan btnThoat

Bài tập windows form c có lời giải năm 2024

6.Khi chương trình đã chạy thì hiệu chỉnh sao cho hai hỉnh đè lên nhau và có size như nhau.7.chạy chượng trình cho hình sau: