Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Đây là nơi mà các tính năng Thêm nhanh đến chơi. Cách nhấp chuột phải vào một lĩnh vực do đó cho phép bạn thay đổi cách thực hiện chương trình. Khi điều Go Wrong Tất cả các quy tắc và pháp luật liên quan đến bản quyền và thương hiệu | Answers to Exercises Private Sub btnGo_Click ByVal sender As System.Object _ ByVal e As System.EventArgs Handles btnGo.Click If IsNumeric txtIncrement.Text Then txtResults.Text vbNullString For Counter As Integer 1 To 100 Step CType txtIncrement.Text Integer txtResults.Text vbCrLf Counter.ToString Next Else MessageBox.Show Sorry the increment you entered is not valid. End If End Sub 2. Run the application enter alphabetic characters in the Increment text box and click the Go button. Chapter 6 Exercises 1. Create an event handler for the New Person menu item that replicates the code you created for the New button on the Toolstrip. 2. Create an event in the PersonalDetails control that you can raise when the Save and Cancel buttons are clicked. Exercise 1 Solution 1. Because the event signatures are the same for the Toolstrip New button and the New Person Menuitem you can just change the Handles clause of the existing subroutine Private Sub newToolStripButton_Click ByVal sender As System.Object _ ByVal e As System.EventArgs Handles newToolStripButton.Click _ newToolStripMenuItem.Click If objPersonalDetails IsNot Nothing Then objPersonalDetails.ResetFields Me.Text Personal Organizer End If End Sub Exercise 2 Solution 1. Define the event at the top of the PersonalDetails.vb code Public Event ButtonClicked ByVal iButtonType As Integer 2. Replace the MessageBox lines in the ButtonClickHandler routine to raise the event instead including an identifier that tells the event handler routine which button was clicked Private Sub ButtonClickedHandler ByVal sender As System.Object _ ByVal e As System.EventArgs 323 Appendix C Dim btnSender As Button CType sender Button If btnSender.Name btnSave Then RaiseEvent ButtonClicked l ElseIf btnSender.Name btnCancel Then RaiseEvent ButtonClicked 2 End If End Sub 3. Change the definition of objPersonalDetails in the main form to include the WithEvents keyword Private WithEvents objPersonalDetails As PersonalDetails 4. Create an event .