BAI_TAP_T9

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 7

BÀI TẬP VỀ NHÀ TUẦN 9

BÀI 1. Thiết kế Form theo mẫu, sử dụng Richtextbox cho ô nhập dữ liệu (rtbHienThi)

- Code tham khảo:


Public Class Bai2
Dim i As Integer = 0
Private Sub btnDam_Click(sender As Object, e As EventArgs) Handles btnDam.Click
i = i + 1
If i Mod 2 <> 0 Then
rtbHienThi.SelectionFont = New Font("Tahoma", 12, FontStyle.Bold)
Else
rtbHienThi.SelectionFont = New Font("Tahoma", 12, FontStyle.Regular)
End If

End Sub

Private Sub btnNghieng_Click(sender As Object, e As EventArgs) Handles btnNghieng.Click


i = i + 1
If i Mod 2 <> 0 Then
rtbHienThi.SelectionFont = New Font("Tahoma", 12, FontStyle.Italic)
Else
rtbHienThi.SelectionFont = New Font("Tahoma", 12, FontStyle.Regular)
End If

End Sub

Private Sub btnGachChan_Click(sender As Object, e As EventArgs) Handles btnGachChan.Click


i = i + 1
If i Mod 2 <> 0 Then
rtbHienThi.SelectionFont = New Font("Tahoma", 12, FontStyle.Underline)
Else
rtbHienThi.SelectionFont = New Font("Tahoma", 12, FontStyle.Regular)
End If

End Sub

Private Sub btnTrai_Click(sender As Object, e As EventArgs) Handles btnTrai.Click


i = i + 1
If i Mod 2 <> 0 Then
rtbHienThi.SelectionAlignment = HorizontalAlignment.Left
Else
rtbHienThi.SelectionAlignment = HorizontalAlignment.Center
End If

End Sub

Private Sub btnGiua_Click(sender As Object, e As EventArgs) Handles btnGiua.Click


rtbHienThi.SelectionAlignment = HorizontalAlignment.Center
End Sub

Private Sub btnPhai_Click(sender As Object, e As EventArgs) Handles btnPhai.Click


i = i + 1
If i Mod 2 <> 0 Then
rtbHienThi.SelectionAlignment = HorizontalAlignment.Right
Else
rtbHienThi.SelectionAlignment = HorizontalAlignment.Center
End If

End Sub

Private Sub btnXoa_Click(sender As Object, e As EventArgs) Handles btnXoa.Click


rtbHienThi.Clear()
End Sub

Private Sub btnMau_Click(sender As Object, e As EventArgs) Handles btnMau.Click


Dim c As New ColorDialog
If c.ShowDialog = DialogResult.OK Then
rtbHienThi.ForeColor = c.Color
End If
End Sub

Private Sub btnFont_Click(sender As Object, e As EventArgs) Handles btnFont.Click


Dim f As New FontDialog
If f.ShowDialog = DialogResult.OK Then
rtbHienThi.Font = f.Font
End If
End Sub

Private Sub BtnDong_Click(sender As Object, e As EventArgs) Handles BtnDong.Click


End
End Sub
Bài 2: Thiêt kế Form, Tạo các timer, kích vào timer và set Enable = true, trong mục Events
double click vào Phần Click

Chè
n
Lab
el

Chèn
'Chèn thêm
Time
thư viện
Imports System.Globalization
Public Class Bai1
' Tạo các timer, kích vào timeer và set Enable = true, trong mục Events double click vào
Phần Click
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
lblTime1.Text = TimeOfDay.ToString("hh:mm:ss tt")
End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick


lblTime2.Text = DateTime.Now.ToString("dd dddd, MMMM - yyyy",
DateTimeFormatInfo.InvariantInfo)
End Sub

Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick


lblTime3.Text = DateTime.Now.ToString("dd dddd, MMMM - yyyy")
End Sub

Private Sub Timer4_Tick(sender As Object, e As EventArgs)

L2.Text = TimeOfDay.ToString("hh:mm:ss tt")


End Sub

End Class
Bài 3: Thiết kế Form theo mẫu, chèn ProgressBar

Public Class Bai5


Dim i As Integer = 0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

i = i + 1
If i Mod 2 <> 0 Then
TimeRun.Start()
Else
TimeRun.Stop()
End If

End Sub

Private Sub TimeRun_Tick(sender As Object, e As EventArgs) Handles TimeRun.Tick


' Nếu chạy đế n 100 thì set về0
If pbRun.Value >= 100 Then
pbRun.Value = 0
Else
pbRun.Value = pbRun.Value + 1
lblRun.Text = pbRun.Value & "% Tôi đang bơi vềbờ :D ..."
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


End
End Sub
End Class
Bài 4: Sử dụng ListView

Imports System.IO
Public Class Bai3
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

lstView.Columns.Clear()
lstView.Items.Clear()
lstView.View = View.Details

lstView.Columns.Add("No", 30, HorizontalAlignment.Left)


lstView.Columns.Add("Name", 150, HorizontalAlignment.Left)
lstView.Columns.Add("Size", 80, HorizontalAlignment.Center)
lstView.Columns.Add("Extension", 80, HorizontalAlignment.Left)

Dim dir As DirectoryInfo = New DirectoryInfo("c:\Windows")


Dim files() As FileInfo = dir.GetFiles
Dim file As FileInfo
Dim lst As ListViewItem
Dim no As Integer = 0
For Each file In files
no = no + 1
lst = lstView.Items.Add(no)
lst.SubItems.Add(file.Name)
lst.SubItems.Add(file.Length)
lst.SubItems.Add(file.Extension)
Next

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


End
End Sub
End Class
Bài 5: Sử dụng TreeView

Imports System.IO
Public Class Bai4
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TreeView1.Nodes.Clear()

'Duyệt đểlấ y các ổcứng


For Each myDrives As DriveInfo In DriveInfo.GetDrives()
Dim myDrivesNode As TreeNode = TreeView1.Nodes.Add(myDrives.Name)
'Thêm các nố t là expand
myDrivesNode.Nodes.Add("Expand")
Next

End Sub

Private Sub TreeView1_BeforeExpand(sender As Object, e As TreeViewCancelEventArgs)


Handles TreeView1.BeforeExpand

'khởi tạo nốt khi ấn chọn tree


Dim MyExistNode As TreeNode = e.Node
'Xóa các node
MyExistNode.Nodes.Clear()

Try
'Đường dẫn
Dim mypath As String = MyExistNode.FullPath

'Duyệt đểlấ y các folder


For Each myFolders As String In Directory.GetDirectories(mypath)
Dim FldrNode As TreeNode =
MyExistNode.Nodes.Add(Path.GetFileName(myFolders))
'mở các nố t khi ấn "[+]" folder
FldrNode.Nodes.Add("Expand")
Next

'Lấy Files
For Each MyFiles As String In Directory.GetFiles(mypath)
Dim FLNode As TreeNode = MyExistNode.Nodes.Add(Path.GetFileName(MyFiles))
Next
Catch ex As Exception

End Try

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


End
End Sub

End Class

You might also like