⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmtimetracker.vb

📁 Programming the .NET Compact Framework with vb 源代码
💻 VB
📖 第 1 页 / 共 2 页
字号:

   Private Sub cboxTasks_SelectedIndexChanged( _
                  ByVal sender As System.Object, _
                  ByVal e As System.EventArgs _
                  ) _
                  Handles cboxTasks.SelectedIndexChanged
      '  Since every task was loaded into the ComboBox, 
      '     the index values for any task are the same
      '     in the ComboBox as they are in the ArrayList.
      LoadTaskFields(cboxTasks.SelectedIndex)
   End Sub

   Private Sub btnNewTask_Click( _
                  ByVal sender As System.Object, _
                  ByVal e As System.EventArgs _
                  ) _
                  Handles btnNewTask.Click
      '  Save the index number of the previous task.  We will
      '     need to know it in case the users cancels out 
      '     during task creation.
      ixTaskPrev = cboxTasks.SelectedIndex

      '  Deselect the current task from the dropdown
      '     ComboBox.  This will also cause the 
      '     SelectedIndexChanged event to fire 
      '     which will cause the task fields to clear.
      cboxTasks.SelectedIndex = -1
      cboxTasks.SelectedIndex = -1

      '  Create and display a multiline textbox
      '     for the user to enter comments.
      txtTaskComments = New Windows.Forms.TextBox
      With txtTaskComments
         .Multiline = True

         '  Locate it relative to other 
         '     controls on the form.
         .Left = txtTaskNo.Left
         .Top = lblProjName.Top
         .Width = Me.Width - (2 * .Left)
         .Height = (txtTaskNo.Top - .Top) - (txtTaskNo.Height / 3)

         '  Enter and select some text.
         .Text = "Add task comments here."
         .SelectAll()

         '  Add the control to the form.
         Me.Controls.Add(txtTaskComments)

         '  Bring it to the z-axis top and
         '     set the focus into it.
         .BringToFront()
         .Focus()
      End With

      '  Designate the handler for the TextChanged
      '      event of the newly created control.
      AddHandler txtTaskComments.TextChanged, _
         AddressOf txtTaskComments_TextChanged

      '  Hide self and show Add and Cancel.
      btnAddTask.Visible = True
      btnCancel.Visible = True
      btnNewTask.Visible = False
   End Sub

   Private Sub btnAddTask_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTask.Click
      '  Unbind the Tasks array list from 
      '     the dropdown ComboBox.
      cboxTasks.DataSource = Nothing


      '  Add the task to the Tasks array list.
      theTasks.Add(New Task(txtTaskNo.Text, txtTaskName.Text, _
                            txtTaskStart.Text, txtTaskEnd.Text, _
                            txtTaskEstimated.Text, _
                            txtTaskActual.Text, _
                            txtTaskComments.Text))

      With cboxTasks
         '  Rebind the Tasks array list to 
         '     the dropdown ComboBox.
         .DataSource = theTasks
         .DisplayMember = "strTaskName"
         .ValueMember = "strTaskIdent"

         '  Start with the new task
         '     as the selected task.
         .SelectedIndex = theTasks.Count - 1
      End With

      '  Cleanup the form and re-select the old task.
      AfterNewTaskCleanup(ixTaskPrev)
   End Sub

   Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
      '  Cleanup the form and re-select the old task.
      AfterNewTaskCleanup(ixTaskPrev)
   End Sub

   '  The event handler for a control
   '     that is created "on the fly".
   Private Sub txtTaskComments_TextChanged( _
                  ByVal sender As System.Object, _
                  ByVal e As EventArgs _
                  )
      With txtTaskComments
         .BackColor = IIf(.Text.Length > 30, _
                           Color.Red, _
                           Color.White)
      End With
   End Sub

   Private Sub InitControlState()
      '  Hide the Add button directly under the new button.
      btnAddTask.Visible = False
      btnAddTask.Bounds = btnNewTask.Bounds
      '  Hide the cancel button
      btnCancel.Visible = False
   End Sub

   Private Sub DisplayProject()
      '  Load Proj data into the labels.
      With theProject
         lblProjName.Text = .strProjName
         lblProjStart.Text = .dateProjStart.ToString("ddMMM")
         lblProjEnd.Text = .dateProjEnd.ToString("ddMMM")
      End With

      '  Load Proj data into the listbox.
      Dim theTask As Task
      With cboxTasks
         For Each theTask In theTasks
            .Items.Add(theTask.strTaskName)
         Next
         '  Start with the first task as 
         '     the currently selected task.
         .SelectedIndex = 0
         '  Set focus to the tasks ComboBox.
         .Focus()
      End With
   End Sub

   Private Sub LoadTaskFields(ByVal intTaskNo As Integer)
      '  Load the fields for the specified
      '     task into the text boxes.  If 
      '     intTaskNo is out of range, clear
      '     the textboxes.  
      If intTaskNo >= 0 And intTaskNo < theTasks.Count Then
         '  Create a variable of a specific type 
         '     so that we can do early binding.
         Dim refTask As Task = theTasks(intTaskNo)
         With refTask
            txtTaskNo.Text = .strTaskIdent
            txtTaskName.Text = .strTaskName
            txtTaskStart.Text = .dateTaskStart.ToString("MM/dd/yy")
            txtTaskEnd.Text = .dateTaskEnd.ToString("MM/dd/yy")
            txtTaskEstimated.Text = .durTaskEstimated
            txtTaskActual.Text = .durTaskActual
         End With
      Else
         txtTaskNo.Text = String.Empty
         txtTaskName.Text = String.Empty
         txtTaskStart.Text = String.Empty
         txtTaskEnd.Text = String.Empty
         txtTaskEstimated.Text = String.Empty
         txtTaskActual.Text = String.Empty
      End If
   End Sub

   Private Sub AfterNewTaskCleanup(ByVal ixTask As Integer)
      '  Destroy the comments textbox
      txtTaskComments.Dispose()
      txtTaskComments = Nothing

      '  Hide Add and Cancel and show New.
      btnAddTask.Visible = False
      btnCancel.Visible = False
      btnNewTask.Visible = True

      '  Select the specified task.
      cboxTasks.SelectedIndex = ixTaskPrev

      '  Set focus to the tasks ComboBox.
      cboxTasks.Focus()
   End Sub

   Private Sub SetBkColor( _
                  ByVal lblTarget As Label, _
                  ByVal colorBack As Color _
                  )
      '  If the desired background color is the background 
      '     color of this form, remove the label from the
      '     panel and dispose of the panel.
      Dim panelBackColor As New Panel
      If colorBack.Equals(Me.BackColor) Then
         If Not lblTarget.Parent Is Me Then
            panelBackColor = lblTarget.Parent
            lblTarget.Bounds = panelBackColor.Bounds
            lblTarget.Parent = Me
            panelBackColor.Dispose()
         End If
      Else
         '  If the desired background color is not the 
         '     background color of this form, then if the
         '     label is already inside a panel, set the
         '     background color of that panel.  If not,
         '     create a panel, position it, put the label 
         '     in it, and set the background color.  
         If lblTarget.Parent Is Me Then
            panelBackColor = New Panel
            Me.Controls.Add(panelBackColor)
            With panelBackColor
               .Visible = True
               .Bounds = lblTarget.Bounds
               lblTarget.Location = New Point(0, 0)
               .Controls.Add(lblTarget)
            End With
         End If
         panelBackColor.BackColor = colorBack
      End If
   End Sub

#Region " Database Read Simulation "

   Private Function LoadProject( _
                        ByVal ProjectID As Integer _
                        ) _
                        As Boolean
      '  Simulate having retrieved project data
      '     from a database.  Here, we'll use our
      '     Project and Task data structures to
      '     hold the data.
      With theProject
         .strProjNo = 1
         .strProjName = "Net CF Book"
         .dateProjStart = DateTime.Today.AddDays(-100)
         .dateProjEnd = DateTime.Today.AddDays(100)
      End With

      theTasks.Add(New Task(0, "Create Blueprints", _
                            DateTime.Today.AddDays(-17), _
                            DateTime.Today.AddDays(22), _
                            120, 60, ""))
      theTasks.Add(New Task(1, "Build Franistans", _
                            DateTime.Today.AddDays(-11), _
                            DateTime.Today.AddDays(0), _
                            35, 30, ""))
      theTasks.Add(New Task(2, "Build Widgets", _
                            DateTime.Today.AddDays(-4), _
                            DateTime.Today.AddDays(44), _
                            400, 45, ""))
      theTasks.Add(New Task(3, "Assemble Woobletogles", _
                            DateTime.Today.AddDays(-19), _
                            DateTime.Today.AddDays(2), _
                            20, 20, ""))
      theTasks.Add(New Task(4, "Weld Mainwareing", _
                            DateTime.Today.AddDays(-100), _
                            DateTime.Today.AddDays(50), _
                            20, 6, ""))
      Return True
   End Function

#End Region

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -