برنامج بسيط وجميل من تصميمي الشخصي .. لكل من يرغب في تعلم Class
صورة البرنامج
Public Class Form1
Dim MyBook As New Book
Class Book
Public BookName As String
Public BookAuthors As String
Public BookPublisher As String
Public BookDatePublished As Integer
End Class
Public Sub SetBook(ByVal Name As String, ByVal Authors As String, ByVal Publisher As String, ByVal DatePublished As Integer)
lblBookName.Text = MyBook.BookName
lblBookAuthors.Text = MyBook.BookAuthors
lblBookPublisher.Text = MyBook.BookPublisher
lblBookDatePublished.Text = MyBook.BookDatePublished
End Sub
Public Sub ShowBook()
lblBookName.Text = txtBookName.Text
lblBookAuthors.Text = txtBookAuthors.Text
lblBookPublisher.Text = txtBookPublisher.Text
lblBookDatePublished.Text = txtBookDatePublished.Text
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (txtBookName.Text.Length = 0) Or (txtBookAuthors.Text.Length = 0) Or (txtBookPublisher.Text.Length = 0) Or (txtBookDatePublished.Text.Length = 0) Then
MsgBox("Please complete all information")
Else
SetBook(txtBookName.Text, txtBookAuthors.Text, txtBookPublisher.Text, txtBookDatePublished.Text)
End If
ShowBook()
End Sub
Private Sub txtBookDatePublished_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtBookDatePublished.KeyPress
Select Case e.KeyChar
Case "0" To "9"
txtBookDatePublished.ForeColor = Color.Red
Case Else
e.Handled = True
End Select
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtBookAuthors.Enabled = False
txtBookDatePublished.Enabled = False
txtBookName.Enabled = False
txtBookPublisher.Enabled = False
Button1.Enabled = False
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
txtBookAuthors.Enabled = True
txtBookDatePublished.Enabled = True
txtBookName.Enabled = True
txtBookPublisher.Enabled = True
Button1.Enabled = True
Else
txtBookAuthors.Enabled = False
txtBookDatePublished.Enabled = False
txtBookName.Enabled = False
txtBookPublisher.Enabled = False
Button1.Enabled = False
End If
End Sub
End Class