none
關於新物件的事件設定(VB.NET 2005) RRS feed

  • 問題

  • '使用程式碼創建一個ListView

    Dim newLV As New ListView

    '設置屬性

    With newLV

      .Size = new size(200,100)

      .Location = new point(10,10)

      .Visible = true

    End With

    屬性設置好了,但事件就設不了......

    '設置事件??

    With newLV

      .SelectedIndexChanged = 當newLV觸發SelectedIndexChanged 事件時的程式碼

      .Resize = 當newLV觸發Resize事件時的程式碼

    End With

    .....請問我該如何設置這個透過程式碼新增的ListView的事件?謝謝.

    2006年12月18日 下午 03:20

解答

  • :::

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            With newLV
                AddHandler newLV.SelectedIndexChanged, AddressOf newLV_SelectedIndexChanged
                AddHandler newLV.Resize, AddressOf newLV_Resize

                .Size = New Size(200, 100)
                .Location = New Point(10, 10)
            End With
            Me.Controls.Add(newLV)
        End Sub

        Private Sub newLV_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
            MessageBox.Show("SelectedIndexChanged")
        End Sub

        Private Sub newLV_Resize(ByVal sender As Object, ByVal e As System.EventArgs)
            MessageBox.Show("Resize")
        End Sub

    2006年12月18日 下午 10:57

所有回覆

  • :::

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            With newLV
                AddHandler newLV.SelectedIndexChanged, AddressOf newLV_SelectedIndexChanged
                AddHandler newLV.Resize, AddressOf newLV_Resize

                .Size = New Size(200, 100)
                .Location = New Point(10, 10)
            End With
            Me.Controls.Add(newLV)
        End Sub

        Private Sub newLV_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
            MessageBox.Show("SelectedIndexChanged")
        End Sub

        Private Sub newLV_Resize(ByVal sender As Object, ByVal e As System.EventArgs)
            MessageBox.Show("Resize")
        End Sub

    2006年12月18日 下午 10:57
  • 能否將問題說清楚,不要讓別人猜
    2006年12月21日 上午 02:48