So I am making this sort of clock thing and I find it hard to discover a way to switch from textbox to another textbox every second. I've tried timers and dispatchtimer but I didn't succeed so I am looking for some expert tips.
The code below works.
Here's my vb.net script:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler TextBox1.Enter, AddressOf TextBox1_Enter
AddHandler TextBox2.Enter, AddressOf TextBox2_Enter
AddHandler TextBox3.Enter, AddressOf TextBox3_Enter
AddHandler TextBox4.Enter, AddressOf TextBox4_Enter
AddHandler TextBox5.Enter, AddressOf TextBox5_Enter
AddHandler TextBox6.Enter, AddressOf TextBox6_Enter
AddHandler TextBox7.Enter, AddressOf TextBox7_Enter
AddHandler TextBox8.Enter, AddressOf TextBox8_Enter
AddHandler TextBox9.Enter, AddressOf TextBox9_Enter
AddHandler TextBox10.Enter, AddressOf TextBox10_Enter
AddHandler TextBox11.Enter, AddressOf TextBox11_Enter
AddHandler TextBox12.Enter, AddressOf TextBox12_Enter
End Sub
Private Sub TextBox1_Enter(sender As Object, e As EventArgs)
BackColor = Color.Red
End Sub
Private Sub TextBox2_Enter(sender As Object, e As EventArgs)
BackColor = Color.Blue
End Sub
Private Sub TextBox3_Enter(sender As Object, e As EventArgs)
BackColor = Color.Yellow
End Sub
Private Sub TextBox4_Enter(sender As Object, e As EventArgs)
BackColor = Color.Green
End Sub
Private Sub TextBox5_Enter(sender As Object, e As EventArgs)
BackColor = Color.Pink
End Sub
Private Sub TextBox6_Enter(sender As Object, e As EventArgs)
BackColor = Color.Teal
End Sub
Private Sub TextBox7_Enter(sender As Object, e As EventArgs)
BackColor = Color.SteelBlue
End Sub
Private Sub TextBox8_Enter(sender As Object, e As EventArgs)
BackColor = Color.LightGray
End Sub
Private Sub TextBox9_Enter(sender As Object, e As EventArgs)
BackColor = Color.Gold
End Sub
Private Sub TextBox10_Enter(sender As Object, e As EventArgs)
BackColor = Color.BlueViolet
End Sub
Private Sub TextBox11_Enter(sender As Object, e As EventArgs)
BackColor = Color.Orange
End Sub
Private Sub TextBox12_Enter(sender As Object, e As EventArgs)
BackColor = Color.Brown
End Sub
End Class
I am also posting a design of a clock for better imagination of the idea.
Well, i'm no professional (which will be evident by the long way i've come up with a solution, i'm sure someone who does it for a living could get it done much more eloquently) but here's what i came up with as it seemed like a fun task.
I've got it stating a timer on launch, then when the button is clicked a new thread is started in the background, that new thread increments a counter every second, and timer1_tick is constantly checking what the counter value is and adjusting the form and textboxes accordingly, it's changing the colour, putting the number in and making it the focused item.
You'll need the following items on Form1:
Textboxes 1 to 12 (in the pattern you provided with 12 being the top one)
A button (Button1)
Drag a timer (Timer1) onto Form1
Then replace the code on Form1 with the below
Imports System.Threading
Public Class Form1
Dim WorkerThread As New Thread(AddressOf DoWork)
Public StartStop As Boolean
Dim Counter As Integer
Private Sub DoWork()
StartStop = False
Do Until StartStop = True
Counter = 0
Do Until Counter = 13
Counter = Counter + 1
Application.DoEvents()
If Counter < 13 Then Threading.Thread.Sleep(1000)
Loop
Loop
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
WorkerThread.Start()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ClearAllTBs()
If Counter = 1 Then
TextBox1.BackColor = Color.Bisque
TextBox1.Text = "1"
TextBox1.Focus()
End If
If Counter = 2 Then
TextBox2.BackColor = Color.Beige
TextBox2.Text = "2"
TextBox2.Focus()
End If
If Counter = 3 Then
TextBox3.BackColor = Color.CornflowerBlue
TextBox3.Text = "3"
TextBox3.Focus()
End If
If Counter = 4 Then
TextBox4.BackColor = Color.Crimson
TextBox4.Text = "4"
TextBox4.Focus()
End If
If Counter = 5 Then
TextBox5.BackColor = Color.DarkCyan
TextBox5.Text = "5"
TextBox5.Focus()
End If
If Counter = 6 Then
TextBox6.BackColor = Color.DarkMagenta
TextBox6.Text = "6"
TextBox6.Focus()
End If
If Counter = 7 Then
TextBox7.BackColor = Color.Gold
TextBox7.Text = "7"
TextBox7.Focus()
End If
If Counter = 8 Then
TextBox8.BackColor = Color.Fuchsia
TextBox8.Text = "8"
TextBox8.Focus()
End If
If Counter = 9 Then
TextBox9.BackColor = Color.DarkViolet
TextBox9.Text = "9"
TextBox9.Focus()
End If
If Counter = 10 Then
TextBox10.BackColor = Color.MediumSeaGreen
TextBox10.Text = "10"
TextBox10.Focus()
End If
If Counter = 11 Then
TextBox11.BackColor = Color.Navy
TextBox11.Text = "11"
TextBox11.Focus()
End If
If Counter = 12 Then
TextBox12.BackColor = Color.BlueViolet
TextBox12.Text = "12"
TextBox12.Focus()
End If
Application.DoEvents()
End Sub
Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles Me.Closed
StartStop = True
WorkerThread.Abort()
End Sub
Private Sub ClearAllTBs()
TextBox1.BackColor = Color.White
TextBox2.BackColor = Color.White
TextBox3.BackColor = Color.White
TextBox4.BackColor = Color.White
TextBox5.BackColor = Color.White
TextBox6.BackColor = Color.White
TextBox7.BackColor = Color.White
TextBox8.BackColor = Color.White
TextBox9.BackColor = Color.White
TextBox10.BackColor = Color.White
TextBox11.BackColor = Color.White
TextBox12.BackColor = Color.White
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
End Sub
End Class
Related
I managed to make my app capture any key to use it as a hotkey, but when I press the key the hotkey function is activated. This is what I have so far:
Private Sub tmrFunc_Tick(sender As Object, e As EventArgs) Handles tmrFunc.Tick
'Function
End Sub
Private Sub tmrKey_Tick(sender As Object, e As EventArgs) Handles tmrKey.Tick
'Uses the hotkey to start and stop tmrF
End Sub
Private Sub lblCapKey_Click(sender As Object, e As EventArgs) Handles lblCapKey.Click
tmrKey.Enabled = False
txtbStartFunc.Enabled = True
txtbStartFunc.Text = "Press any key"
txtbStartFunc.Focus()
End Sub
Private Sub txtbStartFunc_KeyDown(sender As Object, e As KeyEventArgs) Handles txtbStartFunc.KeyDown
If e.KeyCode = Keys.F10 Then
txtbStartFunc.Text = "F10"
End If
tmrKey.Enabled = True
txtbStartFunc.Enabled = False
End Sub
The current code perfectly captures the key and uses it as a hotkey, the problem is that the hotkey is activated on this first key pressed and that causes it to be activated unexpectedly at the wrong time.
My current goal is that the function is not activated with the first keystroke, but is activated with the following keystrokes.
I am expecting something like this:
Private Sub txtbStartFunc_KeyDown(sender As Object, e As KeyEventArgs) Handles txtbStartFunc.KeyDown
If e.KeyCode = Keys.F10 Then
txtbStartFunc.Text = "F10"
End If
tmrKey.Enabled = True
'=========================
tmrFunc.Enabled = False
'=========================
txtbStartFunc.Enabled = False
End Sub
Here's a solution that finally worked for me. It allows you to set the hotkeys between F1 and F10, but won't let you select the same key for both of them.
This is pretty different than what you had, so take your time studying it and ask as many questions as need be:
Public Class Form1
Private Const KeyDownBit As Integer = &H8000
Private Enum HotKeyType
StartClicker
StopClicker
End Enum
Private _StartHotkey As Keys
Private _StopHotKey As Keys
Private SelectingHotKey As HotKeyType
Private HotKeySelected As Boolean = False
Private _SettingHotKey As Boolean = False
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKeys As Integer) As Short
Private Property StartHotKey As Keys
Get
Return _StartHotkey
End Get
Set(value As Keys)
If value <> StopHotKey Then
_StartHotkey = value
TextBox1.Text = StartHotKey.ToString
End If
End Set
End Property
Private Property StopHotKey As Keys
Get
Return _StopHotKey
End Get
Set(value As Keys)
If value <> StartHotKey Then
_StopHotKey = value
TextBox2.Text = StopHotKey.ToString
End If
End Set
End Property
Private Property SettingHotKey As Boolean
Get
Return _SettingHotKey
End Get
Set(value As Boolean)
If value Then
HotKeySelected = False
Timer2.Stop()
Else
Timer2.Start()
End If
_SettingHotKey = value
End Set
End Property
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
Timer1.Enabled = False
Timer2.Enabled = False
Timer1.Interval = 50
Timer2.Interval = 50
TextBox1.ReadOnly = True ' they just stay this way all the time
TextBox2.ReadOnly = True ' they just stay this way all the time
StartHotKey = Keys.F1
StopHotKey = Keys.F2
Timer2.Start()
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim startKeyDown, stopKeyDown As Boolean
GetAsyncKeyState(StartHotKey) ' disregard first call to "flush it"
startKeyDown = (GetAsyncKeyState(StartHotKey) And KeyDownBit) = KeyDownBit ' see if it's down
GetAsyncKeyState(StopHotKey) ' disregard first call to "flush it"
stopKeyDown = (GetAsyncKeyState(StopHotKey) And KeyDownBit) = KeyDownBit ' see if it's down
TextBox1.BackColor = If(startKeyDown, Color.Green, Control.DefaultBackColor)
TextBox2.BackColor = If(stopKeyDown, Color.Green, Control.DefaultBackColor)
If startKeyDown Then
Timer1.Start()
End If
If stopKeyDown Then ' if you hold both down, then it'll stop
Timer1.Stop()
Label1.BackColor = Control.DefaultBackColor
End If
End Sub
Private Sub BothButtons_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click
SelectingHotKey = If(sender Is Button1, HotKeyType.StartClicker, HotKeyType.StopClicker)
SettingHotKey = True ' automatically turns off Timer2
Dim tb As TextBox = If(sender Is Button1, TextBox1, TextBox2)
tb.Text = "Press F1 to F10"
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
Select Case keyData
Case Keys.F1 To Keys.F10
If SettingHotKey Then
If SelectingHotKey = HotKeyType.StartClicker Then
If keyData <> StopHotKey Then
StartHotKey = keyData
HotKeySelected = True
Return True
End If
Else
If keyData <> StartHotKey Then
StopHotKey = keyData
HotKeySelected = True
Return True
End If
End If
End If
End Select
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If SettingHotKey AndAlso HotKeySelected Then
SettingHotKey = False ' restarts Timer2 once selected key has been released
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.BackColor = Color.Green
Label1.Text = DateTime.Now.ToString("HH:mm:ss.ffff") ' just to show it's "clicking"
End Sub
End Class
Okay, here's a little example of my program, which shows my problem.
This is the interface:
enter image description here
When I press F1, the counter starts to add 1 to itself, when I press F2, the counter stops. The Select button changes F1 to F9 or F2 to F10, but when I change the key the function is triggered, that is, if the counter is stopped, and the key is at F1, when I click Select to change from F1 to F9, the counter is activated.
Here is an example of the code, so you can see the problem first hand:
Public Class Form1
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKeys As Integer) As Short
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.Text += 1
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim a, b As Boolean
If TextBox1.Text = "F1" Then
a = GetAsyncKeyState(Keys.F1)
ElseIf TextBox1.Text = "F9" Then
a = GetAsyncKeyState(Keys.F9)
End If
If TextBox2.Text = "F2" Then
b = GetAsyncKeyState(Keys.F2)
ElseIf TextBox2.Text = "F10" Then
b = GetAsyncKeyState(Keys.F10)
End If
If a = True Then
Timer1.Start()
ElseIf b = True Then
Timer1.Stop()
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer2.Enabled = False
TextBox1.ReadOnly = False
TextBox1.Text = "Press any key"
TextBox1.Focus()
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
e.SuppressKeyPress = True
If TextBox1.ReadOnly = False Then
If e.KeyCode = Keys.F9 Then
TextBox1.Text = "F9"
Else
TextBox1.Text = "F1"
End If
End If
Timer2.Enabled = True
TextBox1.ReadOnly = True
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Timer2.Enabled = False
TextBox2.ReadOnly = False
TextBox2.Text = "Press any key"
TextBox2.Focus()
End Sub
Private Sub TextBox2_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyDown
e.SuppressKeyPress = True
If TextBox2.ReadOnly = False Then
If e.KeyCode = Keys.F10 Then
TextBox2.Text = "F10"
Else
TextBox2.Text = "F2"
End If
End If
Timer2.Enabled = True
TextBox2.ReadOnly = True
End Sub
End Class
#Idle_Mind
As stated I have a BackgroundWorker that runs a sub function DoHeavyWork().
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
If BackgroundWorker1.CancellationPending = True Then
e.Cancel = True
Else
'DO HEAVY WORK
DoHeavyWork()
End If
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
Label8.Text = e.ProgressPercentage.ToString() + " %"
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
If e.Cancelled = True Then
ProgressBar1.Value = 0
Label8.Text = ""
ElseIf e.Error IsNot Nothing Then
MessageBox.Show(e.Error.Message)
Else
MessageBox.Show("Completed!")
End If
End Sub
Inside this sub function DoHeavyWork(), there are codes to update another form's GUI.
Private Sub DoHeavyWork()
For i As Integer = 1 To fresult_counter
Dim fresult As New Button
fresult.Name = "fresult_" & i
fresult.Text = result(index_acc(i - 1)).ToString
fresult.TextAlign = ContentAlignment.MiddleLeft
fresult.Width = 265
fresult.AutoSize = True
fresult.BackColor = Color.White
With fresult.FlatAppearance
.BorderColor = Color.White
.BorderSize = 2
.MouseDownBackColor = Color.DeepSkyBlue
.MouseOverBackColor = Color.DeepSkyBlue
End With
fresult.Anchor = AnchorStyles.Left
fresult.FlatStyle = FlatStyle.Flat
fresult.UseVisualStyleBackColor = False
fresult.Location = New Point(0, 22 * (i - 1))
Form1.TabControl2.TabPages(1).Controls.Add(fresult)
BackgroundWorker1.ReportProgress(i)
Next
End Sub
The problem is it did not update the GUI but the progress bar is working. I've tried getting the set of code out of the BackgroundWorker and it works fine. Is there something I did not set to enable BackgroundWorker to update the GUI?
As mentioned by jmcilhinney, the solution for my answer is very simple.
Just let the BackgroundWorker update the progress bar at the background. And when it finished doing it's work, the progress bar will be at 100 which means it is completed.
Once it is completed, simply add the update GUI codings (in my case: 'Form1.TabControl2.TabPages(1).Controls.Add(fresult)') at the sub function when BackgroundWorker has completed:
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
If e.Cancelled = True Then
ProgressBar1.Value = 0
Label8.Text = ""
ElseIf e.Error IsNot Nothing Then
MessageBox.Show(e.Error.Message)
Else
MessageBox.Show("Completed!")
Form1.TabControl2.TabPages(1).Controls.Add(fresult)
End If
End Sub
In VB.NET I'm looking to build a "Time" grid very similar to the Time Restriction grid of the Parental Section of Windows: http://www.thinkbroadband.com/images/guides/time-restrictions.png
It needs to toggle between 2 colors on cell-click
I've played around with One-Cell = One-Label and it kinda works but, like the Windows Time Restriction grid, I'd like to have the labels change colors if I move over the label whilst having the left button pressed (and not only on label click).
Here is what I currently have:
Private Sub ColorToggle(sender As Object, e As MouseEventArgs) Handles Label1.Click, Label2.Click, Label3.Click 'etc..
If e.Button = Windows.Forms.MouseButtons.Left Then
sender.backcolor = If(sender.backcolor = SystemColors.Control, Color.LightGreen, SystemColors.Control)
End If
End Sub
Since the sender stays the same when I hover the labels (sender = label I've originally clicked on), this code doesn't work for my purpose.
I'm looking for suggestions!
Thanks :)
When you click on a control and you hold the mouse button down, this control captures the following mouse events, so that you won't get events from the other lables when moving the mouse over them.
The trick is to set label.Capture = False.
Lets define colors:
Private ReadOnly selectedColor As Color = Color.Blue
Private ReadOnly unselectedColor As Color = Color.White
And Booleans storing the current state of our operations
Private isSelecting As Boolean = False
Private isUnselecting As Boolean = False
(All four as fields of the form class)
Now lets write these three event handlers:
Private Sub Label_MouseDown(sender As Object, e As EventArgs)
'This event starts selecting/unselecting
Dim label = DirectCast(sender, Label)
label.Capture = False '<=== THIS IS IMPORTANT!
If label.BackColor = selectedColor Then
isUnselecting = True
Else
isSelecting = True
End If
SelectLabel(label)
End Sub
Private Sub Label_MouseUp(sender As Object, e As EventArgs)
'This event stops selecting/unselecting
isSelecting = False
isUnselecting = False
End Sub
Private Sub Label_MouseEnter(sender As Object, e As EventArgs)
SelectLabel(DirectCast(sender, Label))
End Sub
And we need this procedure that selects or unselects the labels:
Private Sub SelectLabel(label As Label)
If isSelecting Then
label.BackColor = selectedColor
ElseIf isUnselecting Then
label.BackColor = unselectedColor
End If
End Sub
That's it!
Footnote: I have created the lables like this:
Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Const w As Integer = 50, h As Integer = 50
For x = 1 To 10
For y = 1 To 10
Dim lbl As New Label() With {
.Location = New Point(x * w, y * h),
.Size = New Size(w, h),
.BorderStyle = BorderStyle.FixedSingle,
.BackColor = unselectedColor
}
AddHandler lbl.MouseDown, AddressOf Label_MouseDown
AddHandler lbl.MouseUp, AddressOf Label_MouseUp
AddHandler lbl.MouseEnter, AddressOf Label_MouseEnter
Controls.Add(lbl)
Next
Next
End Sub
I hope this isn't homework...
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Dim i As Integer
With dgv
.ColumnCount = 0
.DataSource = Nothing
.Columns.Add("Day", "Day")
For i = 0 To 23
.Columns.Add(i, i)
.Columns(.Columns.Count - 1).Width = 30
Next
For i = 1 To 7
.Rows.Add({i})
Next
End With
End Sub
Private Sub dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellClick
dgv.CurrentCell.Style.BackColor = Color.Blue
End Sub
Here is a drag version:
Private Sub dgv_MouseUp(sender As Object, e As MouseEventArgs) Handles dgv.MouseUp
For Each cell As DataGridViewCell In dgv.SelectedCells
If cell.Style.BackColor = Color.Blue Then
cell.Style.BackColor = Color.White
Else
cell.Style.BackColor = Color.Blue
End If
Next
dgv.ClearSelection()
End Sub
I am using a DataSource in my form app, and it was working fine for calls made across the board, Fill, Add, Delete, etc... It suddenly stopped working. I get no errors on build, no data is added to any ComboBoxes, and no new Adds work either.
I created a new DataSource from the same database that works fine with the exact same connection. The location of the database never moved, no changes were made to any properties of the DataSource or any of the Adapters assigned to the source, it just stopped working. Here is some screen shots and code of my form.
I tried to do a Code Compare but since there are a bunch of Adapters assigned to the source I can't find any anomalies. What would kill a data connection so that the code still sees the connection, but nothing gets filled?
The following code no longer works, no Fill or Add to DCGDataSet;
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs)
'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
'comboClear()
End Sub
Private Sub btnAddNew_Click(sender As Object, e As System.EventArgs)
' Add new Job to the database
Dim newJobRow As New DCGDataSetTableAdapters.MainTableAdapter
Dim intInsert As Integer
Dim jobText = txtBoxAddNewJob.Text
intInsert = newJobRow.InsertJob(jobText)
If intInsert = 1 Then
MessageBox.Show("New Job Added")
' Update the comboBox values
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
txtBoxAddNewJob.Text = ""
clearTabOne()
Else
MessageBox.Show("Job Not Added")
End If
End Sub
The following call for a ComboBox works fine, this is the new DataSource;
Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
Me.MainTableAdapter1.Fill(Me.DCGDataSet1.Main)
End Sub
These pics are of the two DS I am working with, the top one is the non-working DS.
Entire .vb of Form1 Code;
Public Class MainForm
Dim strCurrency As String = ""
Dim acceptableKey As Boolean = False
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
comboClear()
End Sub
Private Sub btnAddNew_Click(sender As Object, e As System.EventArgs)
' Add new Job to the database
Dim newJobRow As New DCGDataSetTableAdapters.MainTableAdapter
Dim intInsert As Integer
Dim jobText = txtBoxAddNewJob.Text
intInsert = newJobRow.InsertJob(jobText)
If intInsert = 1 Then
MessageBox.Show("New Job Added")
' Update the comboBox values
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
txtBoxAddNewJob.Text = ""
clearTabOne()
Else
MessageBox.Show("Job Not Added")
End If
End Sub
Private Sub TabPage2_Enter(sender As Object, e As System.EventArgs)
Me.ActiveControl = txtBoxAddNewJob
clearTabOne()
End Sub
Public Sub comboClear()
ComboBox1.SelectedIndex = -1
ComboBox2.SelectedIndex = -1
End Sub
Private Sub TabPage1_Enter(sender As Object, e As System.EventArgs)
'comboClear()
ComboBox1.SelectedIndex = -1
'ComboBox1.SelectedText = ""
End Sub
Private Sub TabPage3_Enter(sender As Object, e As System.EventArgs)
'comboClear()
ComboBox2.SelectedIndex = -1
clearTabOne()
End Sub
Private Sub btnDeleteJob_Click(sender As Object, e As System.EventArgs)
Dim delJobID = ComboBox2.SelectedValue
Dim delJobRowAdpt As New DCGDataSetTableAdapters.MainTableAdapter
Dim delJobRow As DCGDataSet.MainRow
Dim intDelete As Integer
delJobRow = DCGDataSet.Main.FindByID(delJobID)
delJobRow.Delete()
intDelete = delJobRowAdpt.Update(DCGDataSet.Main)
If intDelete = 1 Then
MessageBox.Show("Job Deleted")
'comboClear()
clearTabOne()
'ComboBox2.SelectedValue = -1
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
Else
MessageBox.Show("Job Failed to Delete")
End If
ComboBox2.SelectedValue = -1
End Sub
Private Sub FillSubCombo(ByVal subJob As String)
Dim selSubRow = DCGDataSet.SubBilling
Dim selSubValue As New DCGDataSetTableAdapters.SubBillingTableAdapter
Me.SubBillingTableAdapter.SubName(Me.DCGDataSet.SubBilling, subJob)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs)
Dim subJob As String = ComboBox1.Text
If subJob.Length > 1 Then
Label5.Visible = True
ComboBox3.Visible = True
FillSubCombo(subJob)
End If
End Sub
Public Sub clearTabOne()
Label5.Visible = False
ComboBox3.Visible = False
End Sub
Private Sub TabPage4_Enter(sender As Object, e As System.EventArgs)
clearTabOne()
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If (e.KeyCode >= Keys.D0 And e.KeyCode <= Keys.D9) OrElse (e.KeyCode >= Keys.NumPad0 And e.KeyCode <= Keys.NumPad9) OrElse e.KeyCode = Keys.Back Then
acceptableKey = True
Else
acceptableKey = False
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
' Check for the flag being set in the KeyDown event.
If acceptableKey = False Then
' Stop the character from being entered into the control since it is non-numerical.
e.Handled = True
Return
Else
If e.KeyChar = Convert.ToChar(Keys.Back) Then
If strCurrency.Length > 0 Then
strCurrency = strCurrency.Substring(0, strCurrency.Length - 1)
End If
Else
strCurrency = strCurrency & e.KeyChar
End If
If strCurrency.Length = 0 Then
TextBox1.Text = ""
ElseIf strCurrency.Length = 1 Then
TextBox1.Text = "0.0" & strCurrency
ElseIf strCurrency.Length = 2 Then
TextBox1.Text = "0." & strCurrency
ElseIf strCurrency.Length > 2 Then
TextBox1.Text = strCurrency.Substring(0, strCurrency.Length - 2) & "." & strCurrency.Substring(strCurrency.Length - 2)
End If
TextBox1.Select(TextBox1.Text.Length, 0)
End If
e.Handled = True
End Sub
Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
Me.MainTableAdapter1.Fill(Me.DCGDataSet1.Main)
End Sub
End Class
Your not-working code is missing the Handles clauses on Form1_Load and btnAddNew_Click. If you don't connect the event handler to the event (using either a Handles clause or an AddHandler statement), the event handler won't be run.
My progressbar is disappearing as soon as I start running any code. Why's that?
That's really strange.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
StartThinking()
For Each z In ListBox1.Items
Dim u = FindIPAddress(z)
ListBox2.Items.Add(If(IsNothing(u), "Not found!", u))
Next
StopThinking()
End Sub
Sub StartThinking()
Cursor = Cursors.WaitCursor
ProgressBar1.Minimum = 0
ProgressBar1.Style = ProgressBarStyle.Marquee
End Sub
Sub StopThinking()
ProgressBar1.Minimum = ProgressBar1.Maximum
ProgressBar1.Style = ProgressBarStyle.Blocks
Cursor = Cursors.Arrow
End Sub