关于把窗体里的代码封装为一个模块的问题 RRS feed

  • 问题

  •  Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
        Dim g As Graphics = e.Graphics
        Dim _TextBrush As Brush
        ' Get the item from the collection.
        Dim _TabPage As TabPage = TabControl1.TabPages(e.Index)
        ' Get the real bounds for the tab rectangle.
        Dim _TabBounds As Rectangle = TabControl1.GetTabRect(e.Index)
        If (e.State = DrawItemState.Selected) Then
          ' Draw a different background color, and don't paint a focus rectangle.
          ' “画一个不同的背景颜色,不要油漆焦点长方形。
          _TextBrush = New SolidBrush(Color.Yellow)
          g.FillRectangle(Brushes.Gray, e.Bounds)
          _TextBrush = New System.Drawing.SolidBrush(e.ForeColor)
        End If
        ' Use our own font.
        Dim _TabFont As New Font("幼圆", 15.0, FontStyle.Regular, GraphicsUnit.Pixel)
        ' Draw string. Center the text.
        Dim _StringFlags As New StringFormat()
        _StringFlags.Alignment = StringAlignment.Center
        _StringFlags.LineAlignment = StringAlignment.Center
        g.DrawString(_TabPage.Text, _TabFont, _TextBrush, _TabBounds, New StringFormat(_StringFlags))
      End Sub


    错误 1 Handles 子句要求一个在包含类型或它的某个基类型中定义的 WithEvents 变量。 E:\练习2\Timer3\Timer3\TabStyle.vb 2 121 Timer3

    错误 2 未声明“TabControl1”。它可能因其保护级别而不可访问。 E:\练习2\Timer3\Timer3\TabStyle.vb 8 35 Timer3

    错误 3 未声明“TabControl1”。它可能因其保护级别而不可访问。 E:\练习2\Timer3\Timer3\TabStyle.vb 12 39 Timer3

    2011年1月20日 12:08