Lab TH mạng căn bản buổi 1

14 589 0
Lab TH mạng căn bản buổi 1

Đ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

Lab thực hành mạng căn bản môn lập trình mạng căn bản 2016 Lab thực hành mạng căn bản môn lập trình mạng căn bản 2016 Lab thực hành mạng căn bản môn lập trình mạng căn bản 2016 Lab thực hành mạng căn bản môn lập trình mạng căn bản 2016 Lab thực hành mạng căn bản môn lập trình mạng căn bản 2016

THỰC HÀNH TUẦN I Tiếp cận môi trường lập trình Windows Forms với ngôn ngữ C#  IDE: Microsoft Visual Studio 2010  Nội dung: - Cách tạo Project - Thay đổi Tiêu đề cửa sổ - Cách chạy ứng dụng - Thay đổi màu Form - Quy định kích thước Form - Vị trí Form - Khóa MaximizeBox Form  Thực hành: Đầu tiên bạn mở Visual Studio 2010 lên > Click chọn New Project Trang Chọn Windows Forms Application > OK (Xem ảnh minh họa) Trang Mặc định ta có cửa sổ Form Trang Nếu để ý bạn thấy Tiêu đề Form là: Form Bây thay đổi tiêu đề thành: Ứng Dụng Đầu Tiên Để làm điều này, bạn Click chuột vào cửa sổ Form (để hiểu muốn làm việc với cửa sổ này) Bạn nhìn góc phải cửa sổ làm việc thấy cửa sổ Properties Tại mục Text có tiêu đề Form Trang Bạn sữa chữ Form thành Ứng Dụng Đầu Tiên Bây bạn nhấn phím F5 bàn phím để xem ứng dụng chạy Rõ ràng bạn thấy tiêu đề ứng dụng đổi thành Ứng Dụng Đầu Tiên Tắt cửa sổ chạy để quay trở lại hình thiết kế Chúng ta thay đổi thuộc tính Form code Trang Trong cửa sổ Solutin Explorer, bạn Click vào nút View code để chuyển sang cửa sổ viết code Trong kiện Form Load bạn thêm code sau để thay đổi màu Form: Code: this.BackColor = Color.Brown; Bạn nhấn F5 để xem kết Tiếp tục bạn thêm code sau để thay đổi tiêu đề Form Trang Code: this.Text = "Thay doi ten tieu de form"; Bạn nhấn F5 để xem kết Thêm code sau để quy định kích thước Form Code: this.Size = new Size(450, 125); Thêm code sau để qui định vị trí Form Code: this.Location = new Point(300, 300); Thêm code sau để khóa nút Maximize Form Code: this.MaximizeBox = false; Toàn code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.BackColor = Color.Brown; this.Text = " Thay doi ten tieu de form "; this.Size = new Size(450, 125); this.Location = new Point(300, 300); Trang this.MaximizeBox = false; } } } II Lập trình với ngôn ngữ C# mức Lập trình với ngôn ngữ C# mức bản:  Đọc hiểu chương trình C# mức  Nắm kiểu liệu C# Kiểu liệu nguyên thủy: int, long, double, char… Kiểu liệu tham chiếu: Array, List, Class …  Nắm cấu trúc điều khiển lập trình Cấu trúc điều khiển Cấu trúc điều khiển rẽ nhánh if Cấu trúc điều khiển rẽ nhánh if… else Cấu trúc điều khiển vòng lặp  Nắm kỹ thuật xử lý mảng chiều Chương trình xuất chữ “Hello World” namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine("Hello World"); } 10 } 11 } Viết chương trình nhập số nguyên tính tổng số (Sử dụng Windows Form Application) Class Form namespace WindowsFormsApplication1 { Trang public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string s1Text = s1.Text; string s2Text = s2.Text; int s1Int = int.Parse(s1Text); int s2Int = int.Parse(s2Text); long sumLong = 0; sumLong = s1Int + s2Int; sum.Text = sumLong.ToString(); } } } Form1.Designer.cs namespace WindowsFormsApplication1 { partial class Form1 { private void InitializeComponent() { this.s1 = new System.Windows.Forms.TextBox(); this.s2 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.sumBtn = new System.Windows.Forms.Button(); this.sum = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // s1 // this.s1.Location = new System.Drawing.Point(176, 102); this.s1.Multiline = true; this.s1.Name = "s1"; this.s1.Size = new System.Drawing.Size(163, 33); this.s1.TabIndex = 0; // // s2 // this.s2.Location = new System.Drawing.Point(176, 174); this.s2.Multiline = true; this.s2.Name = "s2"; this.s2.Size = new System.Drawing.Size(163, 35); this.s2.TabIndex = 1; // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); this.label1.Location = new System.Drawing.Point(44, 113); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(102, 22); Trang this.label1.TabIndex = 2; this.label1.Text = "Số thứ nhất"; this.label1.Click += new System.EventHandler(this.label1_Click); // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); this.label2.Location = new System.Drawing.Point(44, 187); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(91, 22); this.label2.TabIndex = 3; this.label2.Text = "Số thứ hai"; // // sumBtn // this.sumBtn.Location = new System.Drawing.Point(365, 129); this.sumBtn.Name = "sumBtn"; this.sumBtn.Size = new System.Drawing.Size(83, 47); this.sumBtn.TabIndex = 4; this.sumBtn.Text = "Tính"; this.sumBtn.UseVisualStyleBackColor = true; this.sumBtn.Click += new System.EventHandler(this.button1_Click); // // sum // this.sum.Location = new System.Drawing.Point(176, 251); this.sum.Multiline = true; this.sum.Name = "sum"; this.sum.Size = new System.Drawing.Size(163, 35); this.sum.TabIndex = 5; // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); this.label3.Location = new System.Drawing.Point(44, 264); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(82, 22); this.label3.TabIndex = 6; this.label3.Text = "Kết quả: "; // // label4 // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F); this.label4.Location = new System.Drawing.Point(86, 34); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(313, 26); this.label4.TabIndex = 7; this.label4.Text = "TÍNH TỔNG HAI SỐ NGUYÊN"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(500, 329); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.sum); this.Controls.Add(this.sumBtn); this.Controls.Add(this.label2); Trang 10 this.Controls.Add(this.label1); this.Controls.Add(this.s2); this.Controls.Add(this.s1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private private private private private private private private } System.Windows.Forms.TextBox s1; System.Windows.Forms.TextBox s2; System.Windows.Forms.Label label1; System.Windows.Forms.Label label2; System.Windows.Forms.Button sumBtn; System.Windows.Forms.TextBox sum; System.Windows.Forms.Label label3; System.Windows.Forms.Label label4; } Bài tập có gợi ý: Bài 1: Viết chương trình nhập vào số a b, cho biết số lớn số nhỏ số a, b với giao diện sau: Hướng dẫn gợi ý: Sử dụng cấu trúc If… else Trang 11 Bài 2: Viết chương trình nhập vào số a , b c cho biết số lớn số nhỏ số a, b, c với giao diện sau: Bài 3: Nhập vào số nguyên từ đến 9, hiển thị chữ với số Ví dụ:  Nhập 1: “Một”  Nhập 2: “Hai”  Nhập 3: “Ba” ………………  Nhập 9: “Chín” Hướng dẫn gợi ý: Sử dụng cấu trúc switch… case Bài 4: Viết chương trình gồm form có button label hiển thị số lầ nhấn button Trang 12 Bài 5: Viết chương trình nhập vào giá trị nguyên dương N, tính tổng S = + + + + …… + N Với giao diện sau: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnTinh_Click(object sender, EventArgs e) { string text = txtN.Text; int n = int.Parse(text); long s = 0; for (int i = 1; i [...]...this.Controls.Add(this.label1); this.Controls.Add(this.s2); this.Controls.Add(this.s1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private private private private private private private private } System.Windows.Forms.TextBox s1; System.Windows.Forms.TextBox s2; System.Windows.Forms.Label label1; System.Windows.Forms.Label label2;... một số nguyên từ 0 đến 9, hiển th bằng chữ với các số trên Ví dụ:  Nhập 1: “Một”  Nhập 2: “Hai”  Nhập 3: “Ba” ………………  Nhập 9: “Chín” Hướng dẫn gợi ý: Sử dụng cấu trúc switch… case Bài 4: Viết chương trình gồm 1 form trong đó có một button và 1 label hiển th số lầ khi nhấn button đó Trang 12 Bài 5: Viết chương trình nhập vào giá trị nguyên dương N, tính tổng S = 1 + 2 + 3 + 4 + …… + N Với giao... System.Windows.Forms.Button sumBtn; System.Windows.Forms.TextBox sum; System.Windows.Forms.Label label3; System.Windows.Forms.Label 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 Trang 11 Bài 2: Viết chương trình nhập vào 3 số a , b và c cho biết số lớn nhất và số nhỏ... Form1 : Form { public Form1() { InitializeComponent(); } private void btnTinh_Click(object sender, EventArgs e) { string text = txtN.Text; int n = int.Parse(text); long s = 0; for (int i = 1; i

Ngày đăng: 23/06/2016, 18:51

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

Tài liệu liên quan