Propeties & Object
Anda memiliki foto pada hard drive anda, lakukan hal berikut:
• Add a Picture Box control to your Form Tambahkan kontrol Picture Box untuk Formulir Anda
• Set the SizeMode Property of the Picture box to StretchImage Mengatur Properti SizeMode dari kotak Gambar untuk StretchImage
• Click on the Image Property, and add the planet.jpg image that you downloaded above Klik pada Gambar Properti, dan menambahkan gambar planet.jpg yang Anda download di atas
• Add two textboxes to the form. Tambahkan dua boks teks pada form. Change the Name of the first one to txtHeight , and the second one to txtWidth . Mengubah Nama pertama untuk txtHeight, dan yang kedua untuk txtWidth. Enter 300 as a the text for both textboxes Masukkan 300 sebagai teks untuk kedua boks teks
• Add two labels to the form. Tambahkan dua label pada form. Set the Text of the first one to Height , and the second one to Width . Mengatur Teks orang pertama yang Tinggi, dan yang kedua untuk Lebar. Move them next to the textboxes Memindahkan mereka di sebelah boks teks
• Add a new button to your form. Tambahkan tombol baru untuk membentuk Anda. Set the Text property to “Change Height and Width” Atur properti Text untuk "Perubahan Tinggi dan Lebar"
VB perlu tahu bahwa Anda ingin mengatur sebuah Properti untuk Kelas Anda. The way you do this is type "Public Property … End Property". Cara Anda melakukannya adalah tipe "Umum Properti ... Akhir Properti".
Access the code for your Class. Akses kode untuk Kelas Anda. Type a few lines of space between the End Sub of your DoMessageBox Method, and the line that reads "End Class". Ketik beberapa baris ruang antara Sub Akhir DoMessageBox Anda Metode, dan garis yang bertuliskan "End Class". On a new line, type the following: Pada baris baru, ketik berikut ini:
Public Property ChangeHeight() As Integer Umum Properti ChangeHeight () As Integer
ChangeHeight is the name of our property, and it's something we made up ourselves. ChangeHeight adalah nama properti kita, dan itu sesuatu yang kita dibuat sendiri. After a pair of round brackets, you add the type of value that will be returned (Just like a function). Setelah sepasang kurung bulat, Anda menambahkan jenis nilai yang akan dikembalikan (Sama seperti fungsi a). Here, we want to return an Integer value. Di sini, kami ingin mengembalikan nilai Integer.
Ketika Anda menekan tombol kembali setelah mengetik baris tersebut, VB selesai dari sisa rintisan kode untuk Anda:
Public Property ChangeHeight() As Integer Umum Properti ChangeHeight () As Integer
Get Mendapatkan
End Get Akhir Dapatkan
Set(ByVal Value As Integer) Set (ByVal Value As Integer)
End Set Akhir Set
End Property Akhir Properti
Before the code is explained, add a new variable right at the top of your code, just below "Public Class changeHeightWidth". Sebelum kode tersebut dijelaskan, tambahkan variabel baru tepat di bagian atas kode Anda, tepat di bawah "changeHeightWidth Kelas Publik". Add this: Tambahkan ini:
Private intHeight As Integer Swasta intHeight As Integer
The Private word means that only code inside of the Class can see this variable. Kata Swasta berarti bahwa kode hanya dalam Kelompok dapat melihat variabel ini. You can't access this code directly from a button on a Form, for example.
Jika Anda ingin Properti Anda untuk menangani teks Anda mungkin memiliki sesuatu seperti ini:
Set( ByVal MyText As String ) Set (ByVal MyText As String)
But you couldn't do this: Tapi Anda tidak bisa melakukan ini:
Set( ByVal Value As Integer , ByVal MyString As String ) Set (ByVal Value As Integer, MyString ByVal As String)
In other words, you can't pass two values to your property. Dengan kata lain, Anda tidak bisa lewat dua nilai untuk properti Anda. You can only pass one value. Anda hanya dapat melewati satu nilai.
But we want to pass a number to our property. Tapi kita ingin lulus nomor ke properti kami. For us, this value will come from the textbox on the form. Bagi kami, nilai ini akan datang dari textbox pada form. Whatever number is inside of the textbox will get handed over to our Property. Apapun nomor dalam textbox akan diserahkan kepada Properti kami.
• Add a Picture Box control to your Form Tambahkan kontrol Picture Box untuk Formulir Anda
• Set the SizeMode Property of the Picture box to StretchImage Mengatur Properti SizeMode dari kotak Gambar untuk StretchImage
• Click on the Image Property, and add the planet.jpg image that you downloaded above Klik pada Gambar Properti, dan menambahkan gambar planet.jpg yang Anda download di atas
• Add two textboxes to the form. Tambahkan dua boks teks pada form. Change the Name of the first one to txtHeight , and the second one to txtWidth . Mengubah Nama pertama untuk txtHeight, dan yang kedua untuk txtWidth. Enter 300 as a the text for both textboxes Masukkan 300 sebagai teks untuk kedua boks teks
• Add two labels to the form. Tambahkan dua label pada form. Set the Text of the first one to Height , and the second one to Width . Mengatur Teks orang pertama yang Tinggi, dan yang kedua untuk Lebar. Move them next to the textboxes Memindahkan mereka di sebelah boks teks
• Add a new button to your form. Tambahkan tombol baru untuk membentuk Anda. Set the Text property to “Change Height and Width” Atur properti Text untuk "Perubahan Tinggi dan Lebar"
VB perlu tahu bahwa Anda ingin mengatur sebuah Properti untuk Kelas Anda. The way you do this is type "Public Property … End Property". Cara Anda melakukannya adalah tipe "Umum Properti ... Akhir Properti".
Access the code for your Class. Akses kode untuk Kelas Anda. Type a few lines of space between the End Sub of your DoMessageBox Method, and the line that reads "End Class". Ketik beberapa baris ruang antara Sub Akhir DoMessageBox Anda Metode, dan garis yang bertuliskan "End Class". On a new line, type the following: Pada baris baru, ketik berikut ini:
Public Property ChangeHeight() As Integer Umum Properti ChangeHeight () As Integer
ChangeHeight is the name of our property, and it's something we made up ourselves. ChangeHeight adalah nama properti kita, dan itu sesuatu yang kita dibuat sendiri. After a pair of round brackets, you add the type of value that will be returned (Just like a function). Setelah sepasang kurung bulat, Anda menambahkan jenis nilai yang akan dikembalikan (Sama seperti fungsi a). Here, we want to return an Integer value. Di sini, kami ingin mengembalikan nilai Integer.
Ketika Anda menekan tombol kembali setelah mengetik baris tersebut, VB selesai dari sisa rintisan kode untuk Anda:
Public Property ChangeHeight() As Integer Umum Properti ChangeHeight () As Integer
Get Mendapatkan
End Get Akhir Dapatkan
Set(ByVal Value As Integer) Set (ByVal Value As Integer)
End Set Akhir Set
End Property Akhir Properti
Before the code is explained, add a new variable right at the top of your code, just below "Public Class changeHeightWidth". Sebelum kode tersebut dijelaskan, tambahkan variabel baru tepat di bagian atas kode Anda, tepat di bawah "changeHeightWidth Kelas Publik". Add this: Tambahkan ini:
Private intHeight As Integer Swasta intHeight As Integer
The Private word means that only code inside of the Class can see this variable. Kata Swasta berarti bahwa kode hanya dalam Kelompok dapat melihat variabel ini. You can't access this code directly from a button on a Form, for example.
Jika Anda ingin Properti Anda untuk menangani teks Anda mungkin memiliki sesuatu seperti ini:
Set( ByVal MyText As String ) Set (ByVal MyText As String)
But you couldn't do this: Tapi Anda tidak bisa melakukan ini:
Set( ByVal Value As Integer , ByVal MyString As String ) Set (ByVal Value As Integer, MyString ByVal As String)
In other words, you can't pass two values to your property. Dengan kata lain, Anda tidak bisa lewat dua nilai untuk properti Anda. You can only pass one value. Anda hanya dapat melewati satu nilai.
But we want to pass a number to our property. Tapi kita ingin lulus nomor ke properti kami. For us, this value will come from the textbox on the form. Bagi kami, nilai ini akan datang dari textbox pada form. Whatever number is inside of the textbox will get handed over to our Property. Apapun nomor dalam textbox akan diserahkan kepada Properti kami.
0 komentar:
Posting Komentar