home *** CD-ROM | disk | FTP | other *** search
- Public Class UserControl1
- Inherits System.Windows.Forms.UserControl
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'UserControl1 overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- '
- 'UserControl1
- '
- Me.Name = "UserControl1"
-
- End Sub
-
- #End Region
-
- Private pressed As Boolean
- Private dispText As String = "Standard text"
-
- Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
- End Sub
-
- Private Sub UserControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
- pressed = True
- Me.Invalidate()
- End Sub
-
- Private Sub UserControl1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
- pressed = False
- Me.Invalidate()
- End Sub
-
- Public Property DisplayText() As String
- Get
- Return dispText
- End Get
- Set(ByVal Value As String)
- dispText = Value
- Me.Invalidate()
- End Set
- End Property
- Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
- Dim f As New Font("Arial", 20, FontStyle.Bold), c As Color
- Dim p As SizeF = e.Graphics.MeasureString(dispText, f)
- Dim x As Integer = e.ClipRectangle.Width / 2 - p.Width / 2
- Dim y As Integer = e.ClipRectangle.Height / 2 - p.Height / 2
- If pressed Then c = Color.Red Else c = ForeColor
- e.Graphics.DrawString(dispText, f, New SolidBrush(c), x, y)
- End Sub
- End Class
-