Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Khởi động dự án. Bây giờ bạn sẽ thấy rằng khi một URL được chọn từ danh sách, LinkLabel kiểm soát thay đổi để phản ánh tên của mục đã chọn (xem hình 12-4). Khi bạn nhấp vào liên kết, Internet Explorer sẽ mở ra địa chỉ URL trong LinkCollection kiểm soát LinkLabel. | 398 I CHAPTER 12 ADVANCED OBJECT-ORIENTED TECHNIQUES ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs _ Handles lnkUrl.LinkClicked Process the selected link Process.Start e.Link.LinkData End Sub 3. Run the project. You should now see that when a URL is selected from the list the LinkLabel control changes to reflect the name of the selected item refer to Figure 12-4 . When you click the link Internet Explorer opens the URL in the LinkLabel control s LinkCollection. How It Works Now that you have the application working in this example let s look at how it works. When you click an item in the ListView control the Click event is fired for that control. You add code to the Click event to load the LinkLabel control with the selected link. You start by first setting the Text property of the LinkLabel control. This is the text that will be displayed on the form as shown in Figure 12-4. You set the Text property using the static text Visit followed by the actual favorite name. The favorite name is retrieved from the ListView control s Item collection. Each row in the ListView control is called an item and the first column contains the text of the item. Each column past the first column in a row is a subitem of the item the text in the first column . The text that gets displayed in the link label is taken from the Text property of the Item collection Private Sub lvwFavorites_Click ByVal sender As Object _ ByVal e As System.EventArgs Handles lvwFavorites.Click Update the link label control Text property lnkUrl.Text Visit lvwFavorites.SelectedItems.Item 0 .Text The Links property of the LinkLabel control contains a LinkCollection that contains a default hyperlink consisting of the text that is displayed in the LinkLabel control. You clear this collection and set it using the correct hyperlink for the selected Favorite. You do this by calling the Clear method on the Links property Clear the default hyperlink lnkUrl.Links.Clear Finally you add your hyperlink using