Jimi2000

UserControl Transparent

Apr 7th, 2021
673
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // UserControl Code
  2. //--------------------------------------------------------
  3.  
  4. Public Class AddNewTask
  5.  
  6.     Private Const WS_EX_TRANSPARENT As Integer = &H20
  7.     Private Const WS_CLIPCHILDREN As Integer = &H2000000
  8.  
  9.     Public Event AddTaskClicked As EventHandler(Of AddTaskEventArgs)
  10.  
  11.     Public Sub New()
  12.         SetStyle(ControlStyles.Opaque Or ControlStyles.ResizeRedraw, True)
  13.         SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
  14.         InitializeComponent()
  15.     End Sub
  16.  
  17.     Protected Overrides ReadOnly Property CreateParams As CreateParams
  18.         Get
  19.             Dim cp As CreateParams = MyBase.CreateParams
  20.             cp.Style = cp.Style And Not WS_CLIPCHILDREN
  21.             cp.ExStyle = cp.ExStyle Or WS_EX_TRANSPARENT
  22.             Return cp
  23.         End Get
  24.     End Property
  25.  
  26.     Private Sub btnAddTask_Click(sender As Object, e As EventArgs) Handles btnAddTask.Click
  27.         Dim hours As UInteger
  28.         Dim sHours = If(String.IsNullOrEmpty(txtHours.Text.Trim()), "0", txtHours.Text)
  29.  
  30.         If (Not UInteger.TryParse(sHours, hours)) Then
  31.             ShowInputErrorMessage("Invalid Hours", txtHours)
  32.             Return
  33.         End If
  34.  
  35.         Dim minutes As UInteger
  36.         Dim sMinutes = If(String.IsNullOrEmpty(txtMinutes.Text.Trim()), "0", txtMinutes.Text)
  37.  
  38.         If (Not UInteger.TryParse(sMinutes, minutes)) Then
  39.             ShowInputErrorMessage("Invalid Minutes", txtMinutes)
  40.             Return
  41.         End If
  42.  
  43.         Hide()
  44.         Dim args = New AddTaskEventArgs(txtTaskName.Text, hours, minutes)
  45.         RaiseEvent AddTaskClicked(Me, args)
  46.  
  47.         txtHours.Clear()
  48.         txtMinutes.Clear()
  49.         txtTaskName.Clear()
  50.         ActiveControl = txtTaskName
  51.     End Sub
  52.  
  53.     Private Sub ShowInputErrorMessage(msg As String, ctrl As TextBox)
  54.         MessageBox.Show(msg)
  55.         ctrl.Select()
  56.         ctrl.SelectAll()
  57.     End Sub
  58.  
  59.  
  60.     Public Class AddTaskEventArgs
  61.         Inherits EventArgs
  62.         Public Sub New(sTaskName As String, hours As UInteger, minutes As UInteger)
  63.             TaskName = sTaskName
  64.             TaskHours = hours
  65.             TaskMinutes = minutes
  66.         End Sub
  67.         Public ReadOnly Property TaskName As String
  68.         Public ReadOnly Property TaskHours As UInteger
  69.         Public ReadOnly Property TaskMinutes As UInteger
  70.     End Class
  71. End Class
  72.  
  73.  
  74. // UserControl Designer
  75. //--------------------------------------------------------
  76.  
  77. <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
  78. Partial Class AddNewTask
  79.     Inherits System.Windows.Forms.UserControl
  80.  
  81.     <System.Diagnostics.DebuggerNonUserCode()>
  82.     Protected Overrides Sub Dispose(ByVal disposing As Boolean)
  83.         Try
  84.             If disposing AndAlso components IsNot Nothing Then
  85.                 components.Dispose()
  86.             End If
  87.         Finally
  88.             MyBase.Dispose(disposing)
  89.         End Try
  90.     End Sub
  91.  
  92.     Private components As System.ComponentModel.IContainer
  93.  
  94.     <System.Diagnostics.DebuggerStepThrough()>
  95.     Private Sub InitializeComponent()
  96.         Me.lblMinutes = New System.Windows.Forms.Label()
  97.         Me.lblHours = New System.Windows.Forms.Label()
  98.         Me.lblTime = New System.Windows.Forms.Label()
  99.         Me.lblTaskName = New System.Windows.Forms.Label()
  100.         Me.txtMinutes = New System.Windows.Forms.TextBox()
  101.         Me.txtHours = New System.Windows.Forms.TextBox()
  102.         Me.txtTaskName = New System.Windows.Forms.TextBox()
  103.         Me.btnAddTask = New System.Windows.Forms.Button()
  104.         Me.SuspendLayout()
  105.         '
  106.        'lblMinutes
  107.        '
  108.        Me.lblMinutes.AutoSize = True
  109.         Me.lblMinutes.ForeColor = System.Drawing.Color.White
  110.         Me.lblMinutes.Location = New System.Drawing.Point(280, 35)
  111.         Me.lblMinutes.Name = "lblMinutes"
  112.         Me.lblMinutes.Size = New System.Drawing.Size(53, 15)
  113.         Me.lblMinutes.TabIndex = 105
  114.         Me.lblMinutes.Text = "Minutes"
  115.         Me.lblMinutes.TextAlign = System.Drawing.ContentAlignment.MiddleRight
  116.         '
  117.        'lblHours
  118.        '
  119.        Me.lblHours.AutoSize = True
  120.         Me.lblHours.ForeColor = System.Drawing.Color.White
  121.         Me.lblHours.Location = New System.Drawing.Point(162, 35)
  122.         Me.lblHours.Name = "lblHours"
  123.         Me.lblHours.Size = New System.Drawing.Size(42, 15)
  124.         Me.lblHours.TabIndex = 106
  125.         Me.lblHours.Text = "Hours"
  126.         Me.lblHours.TextAlign = System.Drawing.ContentAlignment.MiddleRight
  127.         '
  128.        'lblTime
  129.        '
  130.        Me.lblTime.AutoSize = True
  131.         Me.lblTime.ForeColor = System.Drawing.Color.White
  132.         Me.lblTime.Location = New System.Drawing.Point(1, 35)
  133.         Me.lblTime.Name = "lblTime"
  134.         Me.lblTime.Size = New System.Drawing.Size(92, 15)
  135.         Me.lblTime.TabIndex = 107
  136.         Me.lblTime.Text = "Time required:"
  137.         Me.lblTime.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
  138.         '
  139.        'lblTaskName
  140.        '
  141.        Me.lblTaskName.AutoSize = True
  142.         Me.lblTaskName.ForeColor = System.Drawing.Color.White
  143.         Me.lblTaskName.Location = New System.Drawing.Point(1, 6)
  144.         Me.lblTaskName.Name = "lblTaskName"
  145.         Me.lblTaskName.Size = New System.Drawing.Size(76, 15)
  146.         Me.lblTaskName.TabIndex = 108
  147.         Me.lblTaskName.Text = "Task Name:"
  148.         Me.lblTaskName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
  149.         '
  150.        'txtMinutes
  151.        '
  152.        Me.txtMinutes.Location = New System.Drawing.Point(219, 32)
  153.         Me.txtMinutes.Name = "txtMinutes"
  154.         Me.txtMinutes.Size = New System.Drawing.Size(57, 23)
  155.         Me.txtMinutes.TabIndex = 103
  156.         Me.txtMinutes.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
  157.         '
  158.        'txtHours
  159.        '
  160.        Me.txtHours.Location = New System.Drawing.Point(101, 32)
  161.         Me.txtHours.Name = "txtHours"
  162.         Me.txtHours.Size = New System.Drawing.Size(57, 23)
  163.         Me.txtHours.TabIndex = 102
  164.         Me.txtHours.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
  165.         '
  166.        'txtTaskName
  167.        '
  168.        Me.txtTaskName.Location = New System.Drawing.Point(101, 3)
  169.         Me.txtTaskName.Name = "txtTaskName"
  170.         Me.txtTaskName.Size = New System.Drawing.Size(232, 23)
  171.         Me.txtTaskName.TabIndex = 101
  172.         '
  173.        'btnAddTask
  174.        '
  175.        Me.btnAddTask.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
  176.         Me.btnAddTask.BackColor = System.Drawing.Color.FromArgb(CType(CType(48, Byte), Integer), CType(CType(48, Byte), Integer), CType(CType(48, Byte), Integer))
  177.         Me.btnAddTask.FlatAppearance.BorderSize = 0
  178.         Me.btnAddTask.FlatStyle = System.Windows.Forms.FlatStyle.Flat
  179.         Me.btnAddTask.Font = New System.Drawing.Font("Microsoft YaHei UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  180.         Me.btnAddTask.ForeColor = System.Drawing.Color.GreenYellow
  181.         Me.btnAddTask.Location = New System.Drawing.Point(340, 5)
  182.         Me.btnAddTask.Name = "btnAddTask"
  183.         Me.btnAddTask.Size = New System.Drawing.Size(104, 54)
  184.         Me.btnAddTask.TabIndex = 104
  185.         Me.btnAddTask.Text = "Add Task"
  186.         Me.btnAddTask.UseVisualStyleBackColor = False
  187.         '
  188.        'AddNewTask
  189.        '
  190.        Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!)
  191.         Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
  192.         Me.BackColor = System.Drawing.Color.Transparent
  193.         Me.Controls.Add(Me.lblMinutes)
  194.         Me.Controls.Add(Me.lblHours)
  195.         Me.Controls.Add(Me.lblTime)
  196.         Me.Controls.Add(Me.lblTaskName)
  197.         Me.Controls.Add(Me.txtMinutes)
  198.         Me.Controls.Add(Me.txtHours)
  199.         Me.Controls.Add(Me.txtTaskName)
  200.         Me.Controls.Add(Me.btnAddTask)
  201.         Me.Font = New System.Drawing.Font("Microsoft YaHei UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  202.         Me.ForeColor = System.Drawing.Color.White
  203.         Me.MinimumSize = New System.Drawing.Size(445, 60)
  204.         Me.Name = "AddNewTask"
  205.         Me.Size = New System.Drawing.Size(447, 62)
  206.         Me.ResumeLayout(False)
  207.         Me.PerformLayout()
  208.  
  209.     End Sub
  210.  
  211.     Private WithEvents lblMinutes As Label
  212.     Private WithEvents lblHours As Label
  213.     Private WithEvents lblTime As Label
  214.     Private WithEvents lblTaskName As Label
  215.     Private WithEvents txtMinutes As TextBox
  216.     Private WithEvents txtHours As TextBox
  217.     Private WithEvents txtTaskName As TextBox
  218.     Private WithEvents btnAddTask As Button
  219. End Class
  220.  
RAW Paste Data