<< Chapter < Page Chapter >> Page >

Bước 16: Đóng cửa sổ Code và nhấp đúp lên Command2. Sự kiện Command2_Click sẽ hiển thị trong cửa sổ Code. Nhấp bất kỳ bên trong thủ tục sự kiện và chọn Edit/Paste trên menu. Như vậy ta đã chép đoạn mã từ Command1 sang Command2.

Bước 17: Sửa lại các mã lệnh vừa được chép. Thay đổi các chú thích cho thích hợp; đổi List1 thành List2 và ngược lại. Những sửa đổi này giúp Command2 có thể thực hiện thao tác chuyển các phần tử được chọn từ List2 sang List1.

Lưu các công việc đã thực hiện bằng cách chọn File/Save Project.

Bước 18: Chạy chương trình. Chọn phần tử thứ nhất trong List1 và chọn Command1 để chuyển nó sang List2. Bây giờ chọn phần tử thứ nhất trong List2, và nhấp Command2. Nếu Command2 không thực thi, trở lại môi trường soạn thảo. Kiểm tra lại đoạn mã lệnh trong thủ tục Command2_Click ta vừa chép ở bước trên.

Bước 19: Lưu ý rằng các phần tử ở cả 2 ListBox không được sắp thứ tự; nếu muốn sắp thứ tự, ta nhấp List1 và đổi thuộc tính Sorted thành True, tương tự đối với List2.

Bước 20: Lưu dự án lại và chạy chương trình. Tất cả các phần tử phải được hiển thị theo thứ tự trong cả 2 ListBox, bất chấp thứ tự chúng được thêm vào trong ListBox.

Bài tập 1i-2

Thao tác với spincontrol

Một SpinControl là sự kết hợp của TextBox và Slider. Slider tạo một miền giá trị số được hiển thị trong TextBox. Các giá trị này có thể được thay đổi bằng cách nhập trực tiếp vào trong TextBox.

Bước 1: Tạo thư mục Basic\Bt1-2. Tạo dự án mới trong thư mục trên.

Bước 2: Trong Form1, thêm một TextBox và Horizontal Scroll Bar như hình 2. Thiết lập các thuộc tính sau cho mỗi Control:

Hình I.2: Spin Control

Item1: TextBox

Name: Text1

Text:<blank>

Item2: Horizontal Scroll Bar

Name: Hscroll1

LargeChange: 10

Max: 100

Bước 3: Nhấp đúp lên scrollbar để nhập mã lệnh, đây là sự kiện Change của Scroll Bar gọi là hàm HScroll1_Change. Thêm đoạn mã sau để hiển thị giá trị hiện thời của scroll bar trong TextBox.

Text1.Text = HScroll1.Value

Bước 4: Chạy ứng dụng bằng cách chọn Run/Start trên menu. Bây giờ nhấp các mũi tên trái và phải của scroll bar. Giá trị trong TextBox phải thay đổi.

Bước 5: Bây giờ thêm mã để thay đổi giá trị bằng cách nhập trực tiếp giá trị trong TextBox. Nhấp đúp vào TextBox và thêm đoạn mã sau để thiết lập giá trị cho scroll bar khi TextBox thay đổi:

HScroll1.Value = Text1.Text

Bước 6: Chạy chương trình và nhập 50 vào TextBox. Vạch của scroll bar thay đổi theo. Thay đổi vạch của scroll bar, giá trị trong TextBox cũng thay đổi.

Bước 7: Trong khi chạy chương trình, nhập ký tự A vào TextBox. Điều gì xảy ra? Nguyên nhân vì scroll bar chỉ nhận các giá trị là số chứ không phải ký tự.

Bước 8: Để ngăn chặn những ký tự không mong muốn được nhập vào TextBox, ta sử dụng sự kiện KeyPress. Sự kiện này xảy ra khi có một phím trên bàn phím được nhấn, nhưng trước khi giá trị thực sự được hiển thị trên TextBox. Sự kiện này nhận một giá trị số nguyên của phím được nhấn, gọi là ASCII. Mỗi ký tự trên bàn phím được đại diện bằng một mã ASCII duy nhất. Do đó ta có thể kiểm tra phím nào được nhấn và bỏ qua nó nếu ta thấy không cần thiết.

Questions & Answers

Discuss the differences between taste and flavor, including how other sensory inputs contribute to our  perception of flavor.
John Reply
taste refers to your understanding of the flavor . while flavor one The other hand is refers to sort of just a blend things.
Faith
While taste primarily relies on our taste buds, flavor involves a complex interplay between taste and aroma
Kamara
which drugs can we use for ulcers
Ummi Reply
omeprazole
Kamara
what
Renee
what is this
Renee
is a drug
Kamara
of anti-ulcer
Kamara
Omeprazole Cimetidine / Tagament For the complicated once ulcer - kit
Patrick
what is the function of lymphatic system
Nency Reply
Not really sure
Eli
to drain extracellular fluid all over the body.
asegid
The lymphatic system plays several crucial roles in the human body, functioning as a key component of the immune system and contributing to the maintenance of fluid balance. Its main functions include: 1. Immune Response: The lymphatic system produces and transports lymphocytes, which are a type of
asegid
to transport fluids fats proteins and lymphocytes to the blood stream as lymph
Adama
what is anatomy
Oyindarmola Reply
Anatomy is the identification and description of the structures of living things
Kamara
what's the difference between anatomy and physiology
Oyerinde Reply
Anatomy is the study of the structure of the body, while physiology is the study of the function of the body. Anatomy looks at the body's organs and systems, while physiology looks at how those organs and systems work together to keep the body functioning.
AI-Robot
what is enzymes all about?
Mohammed Reply
Enzymes are proteins that help speed up chemical reactions in our bodies. Enzymes are essential for digestion, liver function and much more. Too much or too little of a certain enzyme can cause health problems
Kamara
yes
Prince
how does the stomach protect itself from the damaging effects of HCl
Wulku Reply
little girl okay how does the stomach protect itself from the damaging effect of HCL
Wulku
it is because of the enzyme that the stomach produce that help the stomach from the damaging effect of HCL
Kamara
function of digestive system
Ali Reply
function of digestive
Ali
the diagram of the lungs
Adaeze Reply
what is the normal body temperature
Diya Reply
37 degrees selcius
Xolo
37°c
Stephanie
please why 37 degree selcius normal temperature
Mark
36.5
Simon
37°c
Iyogho
the normal temperature is 37°c or 98.6 °Fahrenheit is important for maintaining the homeostasis in the body the body regular this temperature through the process called thermoregulation which involves brain skin muscle and other organ working together to maintain stable internal temperature
Stephanie
37A c
Wulku
what is anaemia
Diya Reply
anaemia is the decrease in RBC count hemoglobin count and PVC count
Eniola
what is the pH of the vagina
Diya Reply
how does Lysin attack pathogens
Diya
acid
Mary
I information on anatomy position and digestive system and there enzyme
Elisha Reply
anatomy of the female external genitalia
Muhammad Reply
Organ Systems Of The Human Body (Continued) Organ Systems Of The Human Body (Continued)
Theophilus Reply
what's lochia albra
Kizito
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Giáo trình visual basic. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10777/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Giáo trình visual basic' conversation and receive update notifications?

Ask