Results 1 to 1 of 1

Thread: NumericUpDown for touchscreen

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,190

    NumericUpDown for touchscreen

    Perhaps someone will find this useful. I'm new to .Net so this is my first CodeBank submission and first UserControl. Kudos to circuits2 for his post that provided the main inspiration to tackle this as a UserControl instead of individual components.

    The app I'm rewriting uses touchscreens and the controls used in VB6 don't exist anymore. This uses 2 pairs of buttons for coarse or fine "steps" since that was another way it had been done in the past so the operators are familiar with it. You could alter to only one button and have a timer to repeat it if you want. It will resize a bit and may be done better than I did perhaps. Left size (75x215) is the minimum and it will go to 300x1000 (right one is 200x499). Smallest size should allow 5 digit integers (if you don't alter the font).

    I'm using this with .Net 4.5 so I don't know if there would be any issues with older versions.

    Name:  NUD_Touch.png
Views: 924
Size:  1.3 KB Name:  NUD_Touch2.png
Views: 980
Size:  2.7 KB

    vb.net Code:
    1. Public Class NUD_Touch
    2.  
    3.     Public Event ValueChanged(ByVal Value As Integer)
    4.  
    5. #Region "Properties"
    6.  
    7.     Private _StepFine As Integer
    8.     Private _StepCoarse As Integer
    9.     Private _minimum As Integer
    10.     Private _maximum As Integer
    11.  
    12.     Public Property Minimum() As Integer
    13.         Get
    14.             Return _minimum
    15.         End Get
    16.         Set(ByVal value As Integer)
    17.             _minimum = value
    18.         End Set
    19.     End Property
    20.     Public Property Maximum() As Integer
    21.         Get
    22.             Return _maximum
    23.         End Get
    24.         Set(ByVal value As Integer)
    25.             _maximum = value
    26.         End Set
    27.     End Property
    28.     Public Property StepCoarse() As Integer
    29.         Get
    30.             Return _StepCoarse
    31.         End Get
    32.         Set(ByVal value As Integer)
    33.             _StepCoarse = value
    34.             UpCoarse.Text = "+ " & CStr(_StepCoarse)
    35.             DownCoarse.Text = "- " & CStr(_StepCoarse)
    36.         End Set
    37.     End Property
    38.     Public Property StepFine() As Integer
    39.         Get
    40.             Return _StepFine
    41.         End Get
    42.         Set(ByVal value As Integer)
    43.             _StepFine = value
    44.             UpFine.Text = "+ " & CStr(_StepFine)
    45.             DownFine.Text = "- " & CStr(_StepFine)
    46.         End Set
    47.     End Property
    48.     Public Property Value() As Integer
    49.         Get
    50.             Return CInt(lblValue.Text)
    51.         End Get
    52.         Set(ByVal value As Integer)
    53.             lblValue.Text = CStr(value)
    54.             RaiseEvent ValueChanged(value)
    55.         End Set
    56.     End Property
    57. #End Region
    58.  
    59.     Private Sub NUD_Touch_Load(sender As Object, e As EventArgs) Handles Me.Load
    60.         'set some defaults if nothing has been set in design
    61.         If Maximum = 0 Then Maximum = 100
    62.         If StepCoarse = 0 Then StepCoarse = 10
    63.         If StepFine = 0 Then StepFine = 1
    64.     End Sub
    65.  
    66.     Private Sub UpFine_Click(sender As Object, e As EventArgs) Handles UpFine.Click
    67.         If CInt(lblValue.Text) + StepFine > Maximum Then
    68.             Value = Maximum
    69.         Else
    70.             Value = CInt(lblValue.Text) + StepFine
    71.         End If
    72.     End Sub
    73.  
    74.     Private Sub UpCoarse_Click(sender As Object, e As EventArgs) Handles UpCoarse.Click
    75.         If CInt(lblValue.Text) + StepCoarse > Maximum Then
    76.             Value = Maximum
    77.         Else
    78.             Value = CInt(lblValue.Text) + StepCoarse
    79.         End If
    80.     End Sub
    81.  
    82.     Private Sub DownCourse_Click(sender As Object, e As EventArgs) Handles DownCoarse.Click
    83.         If CInt(lblValue.Text) - StepCoarse < Minimum Then
    84.             Value = Minimum
    85.         Else
    86.             Value = CInt(lblValue.Text) - StepCoarse
    87.         End If
    88.     End Sub
    89.  
    90.     Private Sub DownFine_Click(sender As Object, e As EventArgs) Handles DownFine.Click
    91.         If CInt(lblValue.Text) - StepFine < Minimum Then
    92.             Value = Minimum
    93.         Else
    94.             Value = CInt(lblValue.Text) - StepFine
    95.         End If
    96.     End Sub
    97.  
    98.     Private Sub NUD_Touch_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    99.         Dim new_h As Integer
    100.         Dim but_h As Integer
    101.  
    102.         'widths are being taken care of by anchor property
    103.         new_h = Me.Height
    104.         but_h = CInt((new_h - lblValue.Height) / 4)
    105.         Me.Height = (but_h * 4) + lblValue.Height
    106.         UpFine.Top = 0
    107.         UpFine.Height = but_h
    108.         UpCoarse.Top = but_h
    109.         UpCoarse.Height = but_h
    110.         lblValue.Top = but_h * 2
    111.         DownCoarse.Top = but_h * 2 + lblValue.Height
    112.         DownCoarse.Height = but_h
    113.         DownFine.Top = DownCoarse.Top + but_h
    114.         DownFine.Height = but_h
    115.  
    116.     End Sub
    117. End Class

    vb.net Code:
    1. <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    2. Partial Class NUD_Touch
    3.     Inherits System.Windows.Forms.UserControl
    4.  
    5.     'UserControl1 overrides dispose to clean up the component list.
    6.     <System.Diagnostics.DebuggerNonUserCode()> _
    7.     Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    8.         Try
    9.             If disposing AndAlso components IsNot Nothing Then
    10.                 components.Dispose()
    11.             End If
    12.         Finally
    13.             MyBase.Dispose(disposing)
    14.         End Try
    15.     End Sub
    16.  
    17.     'Required by the Windows Form Designer
    18.     Private components As System.ComponentModel.IContainer
    19.  
    20.     'NOTE: The following procedure is required by the Windows Form Designer
    21.     'It can be modified using the Windows Form Designer.  
    22.     'Do not modify it using the code editor.
    23.     <System.Diagnostics.DebuggerStepThrough()> _
    24.     Private Sub InitializeComponent()
    25.         Me.UpFine = New System.Windows.Forms.Button()
    26.         Me.UpCoarse = New System.Windows.Forms.Button()
    27.         Me.DownFine = New System.Windows.Forms.Button()
    28.         Me.DownCoarse = New System.Windows.Forms.Button()
    29.         Me.lblValue = New System.Windows.Forms.Label()
    30.         Me.SuspendLayout()
    31.         '
    32.         'UpFine
    33.         '
    34.         Me.UpFine.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    35.         Me.UpFine.FlatAppearance.BorderColor = System.Drawing.SystemColors.Highlight
    36.         Me.UpFine.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ActiveCaption
    37.         Me.UpFine.FlatAppearance.MouseOverBackColor = System.Drawing.SystemColors.GradientActiveCaption
    38.         Me.UpFine.FlatStyle = System.Windows.Forms.FlatStyle.Flat
    39.         Me.UpFine.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    40.         Me.UpFine.Location = New System.Drawing.Point(0, 0)
    41.         Me.UpFine.Name = "UpFine"
    42.         Me.UpFine.Size = New System.Drawing.Size(75, 45)
    43.         Me.UpFine.TabIndex = 0
    44.         Me.UpFine.Text = "UP"
    45.         Me.UpFine.UseVisualStyleBackColor = True
    46.         '
    47.         'UpCoarse
    48.         '
    49.         Me.UpCoarse.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    50.         Me.UpCoarse.FlatAppearance.BorderColor = System.Drawing.SystemColors.Highlight
    51.         Me.UpCoarse.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ActiveCaption
    52.         Me.UpCoarse.FlatAppearance.MouseOverBackColor = System.Drawing.SystemColors.GradientActiveCaption
    53.         Me.UpCoarse.FlatStyle = System.Windows.Forms.FlatStyle.Flat
    54.         Me.UpCoarse.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    55.         Me.UpCoarse.Location = New System.Drawing.Point(0, 45)
    56.         Me.UpCoarse.Name = "UpCoarse"
    57.         Me.UpCoarse.Size = New System.Drawing.Size(75, 45)
    58.         Me.UpCoarse.TabIndex = 1
    59.         Me.UpCoarse.Text = "UP"
    60.         Me.UpCoarse.UseVisualStyleBackColor = True
    61.         '
    62.         'DownFine
    63.         '
    64.         Me.DownFine.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    65.         Me.DownFine.FlatAppearance.BorderColor = System.Drawing.SystemColors.Highlight
    66.         Me.DownFine.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ActiveCaption
    67.         Me.DownFine.FlatAppearance.MouseOverBackColor = System.Drawing.SystemColors.GradientActiveCaption
    68.         Me.DownFine.FlatStyle = System.Windows.Forms.FlatStyle.Flat
    69.         Me.DownFine.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    70.         Me.DownFine.Location = New System.Drawing.Point(0, 170)
    71.         Me.DownFine.Name = "DownFine"
    72.         Me.DownFine.Size = New System.Drawing.Size(75, 45)
    73.         Me.DownFine.TabIndex = 2
    74.         Me.DownFine.Text = "DN"
    75.         Me.DownFine.UseVisualStyleBackColor = True
    76.         '
    77.         'DownCoarse
    78.         '
    79.         Me.DownCoarse.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    80.         Me.DownCoarse.FlatAppearance.BorderColor = System.Drawing.SystemColors.Highlight
    81.         Me.DownCoarse.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ActiveCaption
    82.         Me.DownCoarse.FlatAppearance.MouseOverBackColor = System.Drawing.SystemColors.GradientActiveCaption
    83.         Me.DownCoarse.FlatStyle = System.Windows.Forms.FlatStyle.Flat
    84.         Me.DownCoarse.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    85.         Me.DownCoarse.Location = New System.Drawing.Point(0, 125)
    86.         Me.DownCoarse.Name = "DownCoarse"
    87.         Me.DownCoarse.Size = New System.Drawing.Size(75, 45)
    88.         Me.DownCoarse.TabIndex = 2
    89.         Me.DownCoarse.Text = "DN"
    90.         Me.DownCoarse.UseVisualStyleBackColor = True
    91.         '
    92.         'lblValue
    93.         '
    94.         Me.lblValue.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    95.         Me.lblValue.BackColor = System.Drawing.SystemColors.Window
    96.         Me.lblValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    97.         Me.lblValue.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    98.         Me.lblValue.Location = New System.Drawing.Point(0, 90)
    99.         Me.lblValue.MaximumSize = New System.Drawing.Size(300, 35)
    100.         Me.lblValue.Name = "lblValue"
    101.         Me.lblValue.Size = New System.Drawing.Size(75, 35)
    102.         Me.lblValue.TabIndex = 4
    103.         Me.lblValue.Text = "0"
    104.         Me.lblValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    105.         '
    106.         'NUD_Touch
    107.         '
    108.         Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    109.         Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    110.         Me.Controls.Add(Me.lblValue)
    111.         Me.Controls.Add(Me.DownCoarse)
    112.         Me.Controls.Add(Me.DownFine)
    113.         Me.Controls.Add(Me.UpCoarse)
    114.         Me.Controls.Add(Me.UpFine)
    115.         Me.MaximumSize = New System.Drawing.Size(300, 1000)
    116.         Me.MinimumSize = New System.Drawing.Size(75, 215)
    117.         Me.Name = "NUD_Touch"
    118.         Me.Size = New System.Drawing.Size(75, 215)
    119.         Me.ResumeLayout(False)
    120.  
    121.     End Sub
    122.     Friend WithEvents UpFine As System.Windows.Forms.Button
    123.     Friend WithEvents UpCoarse As System.Windows.Forms.Button
    124.     Friend WithEvents DownFine As System.Windows.Forms.Button
    125.     Friend WithEvents DownCoarse As System.Windows.Forms.Button
    126.     Friend WithEvents lblValue As System.Windows.Forms.Label
    127.  
    128. End Class
    Last edited by topshot; Jan 23rd, 2015 at 12:07 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width