Dạng bài tập về Micosoft.NET- P7 potx - Pdf 17

Các bài tập Microsoft .NET 31
Mỗi class đều có ít nhất một Sub New, gọi là Constructor (giống như
Class_Initialize của VB6 class) và Sub Dispose, gọi là Destructor. Đó
là hai Sub dùng để tạo ra và phá hủy Object. Vì Form1 thừa kế từ
Standard Form nên trong Sub New trước hết phải gọi constructor
MyBase.New() của cha nó, và trong Sub Dispose sau hết phải gọi
destructor MyBase.Dispose của cha nó.
Mở Class View Window
Bạn có thể Navigate trong Code qua Class View. DoubleClick lên tên của
Object hay Sub/Function trong Class View để mang cursor đến code của
nó trong trang Edit.
Các bài tập Microsoft .NET 32
Biu din DragDrop
Code của DragDrop, lưu ý ta phải viết thêm Sub ListBox2_DragEnter
để handle Event DragEnter.
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles
ListBox1.MouseDown
' Start the DragDrop process
Dim ItemIndex As Integer
Các bài tập Microsoft .NET 33
' Identify the Listbox item that has mousedown using mouse coordinates
ItemIndex = ListBox1.IndexFromPoint(New System.Drawing.Point(e.X, e.Y))
' Start the DragDrop process passing along the ListboxItem as
ListBox1.Items(ItemIndex)
ListBox1.DoDragDrop(ListBox1.Items(ItemIndex),
DragDropEffects.Copy Or DragDropEffects.Move)
End Sub
Private Sub ListBox2_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListBox2.DragEnter
' Apply the copy effect

' Use a StreamReader to open the UTF-8 file to read.
sr = New StreamReader(AppPath & "animals.txt")
' Read each line in the file.
' When the end of the file is reached, return the value "-1".
Dim x As String
Các bài tập Microsoft .NET 35
While sr.Peek <> -1
x = sr.ReadLine() ' Read a line
ListBox2.Items.Add(x) ' Add it to Listbox2
End While
sr.Close() ' Close the file
End Sub
Private Sub SaveAnimalList()
' Save the content of Listbox2 into a UTF-8 Text file
Dim i As Integer
Dim sw As StreamWriter
' Open the file to write in UTF-8 mode, using a StreamWriter.
sw = New StreamWriter(AppPath & "Animals.txt")
' Write each line in the Listbox.
For i = 0 To ListBox2.Items.Count - 1
sw.WriteLine(ListBox2.Items(i))
Next
sw.Close() ' Close the file
End Sub
Ta hiển thị ngày và giờ bằng cách dùng Timer1 và Shared Function DateTime.Now
formated bằng hai Functions có sẵn ToLongDateString và ToLongTimeString.
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Timer1.Tick
' Display Date and Time every half a second
Label3.Text = DateTime.Now.ToLongDateString & " " & DateTime.Now.ToLongTimeString


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status