Covering Panel with another - vb.net

Private Sub frmitem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pnldeposit.Visible = False
pnlwithdraw.Visible = False
End Sub
Private Sub cmdideposit_Click(sender As Object, e As EventArgs) Handles cmdideposit.Click
pnldeposit.Visible = True
pnlwithdraw.Visible = False
End Sub
Private Sub cmdiwithdraw_Click(sender As Object, e As EventArgs) Handles cmdiwithdraw.Click
pnlwithdraw.Visible = True
pnldeposit.Visible = False
End Sub
//i am having problem with this form. i want to show the first panel which is successful, but the problem is showing the second panel. it is not working, im using buttons btw. help me. Thank you in advance :D

Here is a quick example using BringToFront. With both panels having the same Location and being the same Size.
Public Class Form1
Private switchPanels As Boolean
Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
switchPanels = Not switchPanels
If switchPanels Then
Panel1.BringToFront()
Else
Panel2.BringToFront()
End If
End Sub
End Class

Private Sub cmdideposit_Click(sender As Object, e As EventArgs) Handles cmdideposit.Click
pnldeposit.Visible = True
pnlwithdraw.Visible = False
pnlreport.Visible = False
End Sub
Private Sub cmddcancel_Click(sender As Object, e As EventArgs)
pnldeposit.Hide()
End Sub
Private Sub cmdiwithdraw_Click(sender As Object, e As EventArgs) Handles cmdiwithdraw.Click
pnlwithdraw.Visible = True
pnlreport.Visible = False
End Sub
Private Sub cmdwclear_Click(sender As Object, e As EventArgs) Handles cmdwclear.Click
pnlwithdraw.Visible = False
End Sub
Private Sub cmdireport_Click(sender As Object, e As EventArgs) Handles cmdireport.Click
pnlreport.Visible = True
End Sub
//thank you for sharing your idea! i found how it works. thanks! :D

Related

How to subtract checkbox values?

When I select a checkbox, the value gets added in the textbox and gets incremented when I check another. Problem is, when I uncheck them, it should subtract the values too. Total_sum in my textbox. Please help me.
Dim sum As Integer
Public Sub ChangeValue(add As Boolean, value As Decimal)
sum += If(add, value, -value)
Total_sum.Text = sum.ToString
End Sub
Private Sub chk_1_CheckedChanged(sender As Object, e As EventArgs) Handles chk_1.CheckedChanged
If chk_1.Checked = True Then
ChangeValue(DirectCast(sender, CheckBox).Checked = True, 25I)
End If
End Sub
Private Sub chk_2_CheckedChanged(sender As Object, e As EventArgs) Handles chk_2.CheckedChanged
If chk_2.Checked = True Then
ChangeValue(DirectCast(sender, CheckBox).Checked, 25I)
End If
End Sub
Private Sub chk_3_1_CheckedChanged(sender As Object, e As EventArgs) Handles chk_3_1.CheckedChanged
If chk_3_1.Checked = True Then
chk_3_2.Checked = False
ChangeValue(DirectCast(sender, CheckBox).Checked, 15I)
End If
End Sub
Private Sub chk_3_2_CheckedChanged(sender As Object, e As EventArgs) Handles chk_3_2.CheckedChanged
If chk_3_2.Checked = True Then
chk_3_1.Checked = False
ChangeValue(DirectCast(sender, CheckBox).Checked, 30I)
End If
End Sub
Private Sub chk_4_CheckedChanged(sender As Object, e As EventArgs) Handles chk_4.CheckedChanged
If chk_4.Checked = True Then
ChangeValue(DirectCast(sender, CheckBox).Checked, 20D)
End If
End Sub
Private Sub chk_5_1_CheckedChanged(sender As Object, e As EventArgs) Handles chk_5_1.CheckedChanged
If chk_5_1.Checked = True Then
chk_5_2.Checked = False
chk_5_3.Checked = False
ChangeValue(DirectCast(sender, CheckBox).Checked, 0D)
End If
End Sub
Private Sub chk_5_2_CheckedChanged(sender As Object, e As EventArgs) Handles chk_5_2.CheckedChanged
If chk_5_2.Checked = True Then
chk_5_1.Checked = False
chk_5_3.Checked = False
ChangeValue(DirectCast(sender, CheckBox).Checked, 15D)
End If
End Sub
You do not need the DirectCast. You know what the sender is. Just passing the Boolean chk_1.Checked to ChangeValue will either increment or decrement the sum.
Private sum As Integer
Public Sub ChangeValue(add As Boolean, value As Integer)
sum += If(add, value, -value)
Total_sum.Text = sum.ToString
End Sub
Private Sub chk_1_CheckedChanged(sender As Object, e As EventArgs) Handles chk_1.CheckedChanged
ChangeValue(chk_1.Checked, 25)
End Sub

Simplifying multiple similar 'private subs' in VB

I'm writing a VB program that has multiple positions where when the user hovers over an item, the same image appears.
Currently I have:
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
PictureBox1.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove
PictureBox2.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox3_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox3.MouseMove
PictureBox3.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox4_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox4.MouseMove
PictureBox4.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox5_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox5.MouseMove
PictureBox5.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox6_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox6.MouseMove
PictureBox6.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox7_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox7.MouseMove
PictureBox7.Image = Image.FromFile(picturePath)
End Sub
This works fine, however, I am looking to condense my code. Surely there is a way of making this into just 1 or 2 private subs.
Note that this is just a snippet of my code.
The names of the objects are easily named PictureBox1, PictureBox2 etc.
Regards
Hugo.
Private Sub PictureBox_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove, PictureBox2.MouseMove, PictureBox3.MouseMove, PictureBox4.MouseMove, PictureBox5.MouseMove, PictureBox6.MouseMove, PictureBox7.MouseMove
DirectCast(sender, PictureBox).Image = Image.FromFile(picturePath)
End Sub

Setting a toggle key

I am currently making an autoclicker with human randomization.
The issue i am having is that i have no clue how to make a thing that you can bind a key and then make it run. This is my code so far, and also if you have any idea on how to improve the code then PLEASE share it, I mostly need to improve my randomization.
How can i make a thing so users can set their toggle key?
Public Class Form1
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Declare Function mouse_autoClicker Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean
Private Sub StartClick()
System.Windows.Forms.Cursor.Position = New System.Drawing.Point(System.Windows.Forms.Cursor.Position)
Call mouse_autoClicker(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call mouse_autoClicker(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
Private Sub TrackStart_Scroll(sender As Object, e As EventArgs) Handles TrackStart.Scroll
If TrackStart.Value > TrackEnd.Value Then
TrackStart.Value = TrackEnd.Value
End If
valstart.Text = trackstart.Value
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "ClickDevastator v.0.7"
End Sub
Private Sub TrackEnd_Scroll(sender As Object, e As EventArgs) Handles trackend.Scroll
If trackend.Value < trackstart.Value Then
trackend.Value = trackstart.Value
End If
ValEnd.Text = trackend.Value
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim rnd As New Random
Dim ClickString As Integer = rnd.Next(Val(valstart.Text), Val(ValEnd.Text))
txtRnd.Text = ClickString.ToString()
Timer2.Enabled = True
For i As Integer = 0 To Val(txtRnd.Text) - 1
StartClick()
Next
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnstart.Click
If btnstart.Text = "Start" Then
Timer1.Enabled = True
btnstart.Text = "Stop"
btnstart.ForeColor = Color.Red
ElseIf btnstart.Text = "Stop" Then
Timer1.Enabled = False
btnstart.Text = "Start"
btnstart.ForeColor = Color.LawnGreen
End If
End Sub
Private Sub btnClick_Click(sender As Object, e As EventArgs) Handles btnclick.Click
txtClick.Text = Val(txtClick.Text) + 1
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
valstart.Text = Date.Now.ToString("hh : mm : ss")
End Sub
Private Sub Timer1_Disposed(sender As Object, e As EventArgs) Handles Timer1.Disposed
Timer2.Enabled = False
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
If btnstart.Text = "Stop" Then
btnstart.PerformClick()
End If
End If
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btnstart.Click
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtRnd.TextChanged
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnclick.Click
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles ValEnd.Click
End Sub
Private Sub label1_Click_1(sender As Object, e As EventArgs) Handles valstart.Click
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Label1_Click_2(sender As Object, e As EventArgs)
End Sub
Private Sub trackstart_Scroll_1(sender As Object, e As EventArgs) Handles trackstart.Scroll
End Sub
Private Sub Label1_Click_3(sender As Object, e As EventArgs)
End Sub
Private Sub Label1_Click_4(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
End Class
A Toggle in code works on boolean values like this...
Button2.Enabled = Not (Button2.Enabled)

vb.net button visibility based on checkbox

So i have a form as below:
Public Class IPADSOFT
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
IPADSOFTTS.Show()
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Me.Hide()
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
HOME.Show()
Me.Hide()
End Sub
End Class
which has 3 checkboxes labeled IPADSOFTBOX1, IPADSOFTBOX2, IPADSOFTBOX3
So... i have another form as follows:
Public Class IPADSOFTTS
Private Sub onload()
If IPADSOFT.IPADSOFTBOX1.Checked Then
Button1.Visible = True
Button3.Visible = True
Button5.Visible = True
End If
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Me.Hide()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
HOME.Show()
IPADSOFT.Hide()
Me.Hide()
End Sub
End Class
Now the idea is that all the buttons on that second form are set to visible-false and i want the page to check which checkboxes are checked on the last form and then make the required buttons on this form visible... but it isnt working
What am i doing wrong?? i apologise im very very new to vb.net
Open the second form with this
Dim newForm As New IPADSOFTTS With
{.MainForm = Me}
newForm .Show()
Set Public MainForm As IPADSOFT below the Public Class of second form
Then use in the Load event
if MainForm.IPADSOFTBOX1.Checked = true then
'Do whatever
End if

How to make a clean and short code in vb.net

I'm pretty new here on Stack Overflow and this is my first time asking a question so please be kind to me if you find this question stupid or anything.
Does anyone know how can I make these codes short, I mean I would like to put all these codes into one line.. Please see the code below.
Private Sub PB_SearchP_MouseHover(sender As Object, e As EventArgs) Handles PB_SearchP.MouseHover
PB_SearchP.Image = My.Resources.search1
End Sub
Private Sub PB_SearchP_MouseLeave(sender As Object, e As EventArgs) Handles PB_SearchP.MouseLeave
PB_SearchP.Image = My.Resources.search
End Sub
Private Sub PB_AddP_MouseHover(sender As Object, e As EventArgs) Handles PB_AddP.MouseHover
PB_AddP.Image = My.Resources.add_1_iconhover
End Sub
Private Sub PB_AddP_MouseLeave(sender As Object, e As EventArgs) Handles PB_AddP.MouseLeave
PB_AddP.Image = My.Resources.add_1_icon
End Sub
Private Sub PB_New_MouseHover(sender As Object, e As EventArgs) Handles PB_New.MouseHover
PB_New.Image = My.Resources.newhover
End Sub
Private Sub PB_New_MouseLeave(sender As Object, e As EventArgs) Handles PB_New.MouseLeave
PB_New.Image = My.Resources.neww
End Sub
Private Sub PB_Save_MouseHover(sender As Object, e As EventArgs) Handles Btn_Save.MouseHover
Btn_Save.Image = My.Resources.savehover
End Sub
Private Sub PB_Save_MouseLeave(sender As Object, e As EventArgs) Handles Btn_Save.MouseLeave
Btn_Save.Image = My.Resources.save
End Sub
Private Sub PB_Update_MouseHover(sender As Object, e As EventArgs) Handles BTN_QUpdate.MouseHover
BTN_QUpdate.Image = My.Resources.edithover
End Sub
Private Sub PB_Update_MouseLeave(sender As Object, e As EventArgs) Handles BTN_QUpdate.MouseLeave
BTN_QUpdate.Image = My.Resources.edit
End Sub
A simpler solution is to use a function that sets-up lamba functions as event-handlers:
Public Shared Sub SetUpButton(btn As Button, normalImage As Image, hoverImage as Image)
AddHandler btn.MouseLeave, Sub(o, e) btn.Image = normalImage
AddHandler btn.MouseHover, Sub(o, e) btn.Image = hoverImage
End Sub
Called like so:
SetUpButton( Btn_Save, My.Resources.save, My.Resources.savehover )
SetUpButton( Btn_Update, My.Resources.update, My.Resources.updatehover )
SetUpButton( Btn_New, My.Resources.new, My.Resources.newhover )
and so on...
In C#, for a syntax comparison:
public static void SetUpButton(Button btn, Image normalImage, Image hoverImage) {
btn.MouseLeave += (o,e) => btn.Image = normalImage;
btn.MouseHover += (o,e) => btn.Image = hoverImage;
}