I want to know the code to the following illustration.
i have one form with some checkboxs and one button,
screen is here
i've try with this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True And CheckBox4.Checked = True Then
'when the button is clicked will be the process for moving images
'Like
System.IO.File.Copy(Application.StartupPath + "\File\Pic1.jpg", "D:\File\Pic1.jpg")
End If
End Sub
I was tired with that code, is there a shorter coding ?
for example, if the checkbox1.checked = true and another checkbox not checked then only moving one pict
If I understand the question, you want to copy pictures 1 to 4 if the checkboxes 1 to 4 are checked.
Try this:
Dim SourcePath As string = Application.StartupPath + "\File\"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CopyFile(CheckBox1, "Pic1.jpg")
CopyFile(CheckBox2, "Pic2.jpg")
CopyFile(CheckBox3, "Pic3.jpg")
CopyFile(CheckBox4, "Pic4.jpg")
End Sub
Private Sub CopyFile(CB As CheckBox, FileName As String)
If CB.Checked Then
System.IO.File.Copy(SourcePath + FileName, "D:\File\" + FileName)
End If
End Sub
Related
I am developing a simple SQL generator for images. I am having issues getting texts to be displayed in a textbox when I drag pictures into a PictureBox. Am I doing anything wrong? I want a situation when I drag the image into the PictureBox, the textbox shown in blue should display: 'SELECT FROM EMPLOYEE;'. I need help to get this code working. My code is displayed below.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'' picDropTarget.AllowDrop = True
picAccept.AllowDrop = True
End Sub
Private Sub picSELECT_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSELECT.MouseDown, picEMPLOYEE.MouseDown
' Start the drag if it's the left mouse button.
If (e.Button = MouseButtons.Left) Then
Dim source As PictureBox = DirectCast(sender, PictureBox)
picSELECT.DoDragDrop(source.Image, DragDropEffects.Copy)
'Added this line to show
'txtSQL.Text = "SELECT"
End If
End Sub
Private Sub picAccept_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picAccept.DragEnter
' See if this is a copy and the data includes an image.
If (e.Data.GetDataPresent(DataFormats.Bitmap) AndAlso
(e.AllowedEffect And DragDropEffects.Copy) <> 0) _
Then
' Allow this.
'e.Effect = DragDropEffects.All
e.Effect = DragDropEffects.All
Else
' Don't allow any other drop.
' e.Effect = DragDropEffects.None
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub picAccept_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picAccept.DragDrop, picSELECT.DragDrop, picEMPLOYEE.DragDrop
Dim bm As Bitmap = DirectCast(e.Data.GetData(DataFormats.Bitmap, True), Bitmap)
picAccept.Image = bm
End SubEnd Class
TextBox1.Text = "select from EMPLOYEES"
Here's a fully working minimal sample. You can copy/paste the below, drop a file into the PictureBox at the bottom of the form, and the TextBox at the top will get populated with text.
Public Class Form1
Dim txtbx As New TextBox
Dim pctbx As New PictureBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtbx.Dock = DockStyle.Top
pctbx.Dock = DockStyle.Bottom
pctbx.BackColor = Color.AntiqueWhite
pctbx.AllowDrop = True
Controls.Add(txtbx)
Controls.Add(pctbx)
AddHandler pctbx.DragEnter, AddressOf pctbx_DragEnter
AddHandler pctbx.DragDrop, AddressOf pctbx_DragDrop
End Sub
Private Sub pctbx_DragEnter(sender As Object, e As DragEventArgs)
e.Effect = DragDropEffects.All
End Sub
Private Sub pctbx_DragDrop(sender As Object, e As DragEventArgs)
txtbx.Text = "select from employees where id = "
End Sub
End Class
I'm Trying To make A button Only clickable once in Vb
I was thinking of this code
Sub B64_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B64.Click
Dim BClick As Integer = 0
If BClick = 0 Then
BClick = 1
'Other instructions
End If
Any Other Ideas!
Also Can I do something so that the button will make a sound when it is clicked ?!
Any Other Ideas!
Thank u
In your click event you can do:
B64.Enabled = False
You can also play a .WAV file on click:
Dim player As New System.Media.SoundPlayer()
player.SoundLocation = path
player.Load()
player.Play()
Just Disable Button
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Button1.Enabled = False
'Do Stuff....
'& Enable it if you want
Button1.Enabled = True
End Sub
you can disable button or any control with this code
by using Button1_Click(Button1, Nothing) or Button1_Click(Button2, Nothing)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim Element As Button = DirectCast(sender, Button)
Element.Enabled = False
'Do Stuff....
'if you want delay use: Threading.Thread.Sleep(500)
Element.Enabled = True
End Sub
How do I capture the name of a button so I can use it in another form to query a database. I am new to vb and still at the very early learning stage so any help would be greatfully appreciated.
frmMain
Private Sub btnA_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnA.MouseDown
If (e.Button = Windows.Forms.MouseButtons.Right) Then
frmRacks.Show()
ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
MessageBox.Show("Left clicked")
End If
End Sub
frmRacks
Here is where I need to capture name to query database
Private Sub Button1_MouseDown(sender As Object, e As MouseEventArgs) Handles Button1.MouseDown
Dim name As String = DirectCast(sender, Button).Name
End Sub
There are many ways to do this, one is to declare public field/variable in frmRack, another is using ShowDialog instead of Show:
I'll go with the first one (public) first:
Public buttonName as String
And in the button click from your frmMain you pass the value like:
Private Sub btnA_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnA.MouseDown
If (e.Button = Windows.Forms.MouseButtons.Right) Then
frmRacks.buttonName = "btnA" ' Or you could use DirectCast as proposed by dbasnett
frmRacks.Show()
ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
MessageBox.Show("Left clicked")
End If
End Sub
And then in Loading your frmRacks you have now the option of assigning button Name, like:
Private Sub frmRacks_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim query as String = "SELECT * FROM " + buttonName 'This is only an example you could make your own here
End Sub
It should be MouseButtons.Left instead of Windows.Forms.MouseButtons.Left
If e.Button = MouseButtons.Left Then
MsgBox("Left Button Clicked") 'OR WHATEVER YOU WANT IT TO DO?!
End If
I'm trying to move a set of 30 buttons downwards 100px when a textbox is ticked (and then back to their origins when the box is unticked). This is to provide room for some labels below the buttons if the user requires it... like the "show hints" box here: http://www.phonemicchart.com/
I have the following code:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
Button5.Location = New Point(100, 100)
Label1.Visible = False
Else
Button5.Location = New Point(300, 300)
Label1.Visible = True
End If
End Sub
The problem is the New Point() function. The new point I would like is -100px relative to origin, and then for the Else statement for it to be Button5.Location = Origin.
What commands can I use to achieve this?
Another idea...put all the buttons inside a Panel, then changed the .Top property of it to move everything inside it.
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
Panel1.Top += 100
Else
Panel1.Top -= 100
End If
End Sub
use Left and Top instead as in:
Changing the location of a control on a windows form programatically using VB.net?
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
Button5.Top = 100
Button5.Left = 100
Label1.Visible = False
Else
Button5.Top = 300
Button5.Left = 300
Label1.Visible = True
End If
End Sub
You can iterate over the controls owned by your container, and as offered by mfarid, you can use the Top property
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Dim ctrl As Control
For Each ctrl In container.Controls
If CheckBox1.Checked = True Then
ctrl.Top += 100
ElseIf
ctrl.Top -= 100
End If
Next
EndSub
So I have a code atm that has 2 combo boxes, one to select the make, then it will enable the model, I have 3 model choices, here's code:
Public Class Form2
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Private Sub cmb_make_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmb_make.Items.Add("Toyota")
cmb_make.Items.Add("Nissan")
cmb_make.Items.Add("Hyundai")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_finish.Click
If cmb_make.Text = "" Then
MsgBox("Please select your make")
End If
If cmb_model.Text = "" Then
MsgBox("Please select your model")
End If
If cmb_model.Text = ("Supra") Then
Form3.Show()
Me.Close()
End If
If cmb_model.Text = ("MR2") Then
Form4.Show()
Me.Close()
End If
If cmb_model.Text = ("Hilux") Then
Form5.Show()
Me.Close()
End If
If cmb_model.Text = ("R34") Then
Form6.Show()
Me.Close()
End If
If cmb_model.Text = ("R33") Then
Form7.Show()
Me.Close()
End If
If cmb_model.Text = ("R32") Then
Form8.Show()
Me.Close()
End If
If cmb_model.Text = ("Genesis Coupe") Then
Form9.Show()
Me.Close()
End If
If cmb_model.Text = ("RD1 Coupe") Then
Form10.Show()
Me.Close()
End If
If cmb_model.Text = ("Excel") Then
Form11.Show()
Me.Close()
End If
End Sub
Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click
End Sub
Private Sub cmb_make_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_make.SelectedIndexChanged
Dim Strchoice As String
Strchoice = cmb_make.SelectedItem
If Strchoice = "Toyota" Then
End If
cmb_model.Items.Clear()
cmb_model.Items.Add("Supra")
cmb_model.Items.Add("MR2")
cmb_model.Items.Add("Hilux")
If Strchoice = "Nissan" Then
cmb_model.Items.Clear()
cmb_model.Items.Add("R34")
cmb_model.Items.Add("R32")
cmb_model.Items.Add("R33")
ElseIf Strchoice = "Hyundai" Then
cmb_model.Items.Clear()
cmb_model.Items.Add("RD1 Coupe")
cmb_model.Items.Add("Genesis Coupe")
cmb_model.Items.Add("Excel")
Once I have selected my model of the car, it takes me to that specific form with a picture of that model, I then want to display individual parts, with individual prices that will add up in a text box above, can someone help me and tell me how? Please this is due tomorrow I'm freaking out!!
You can put the parts into picture boxes on the model's form and have either check boxes or radio buttons (depending on what functionality you are required to do) underneath that have the prices as labels and then use an if structure to assign a value to them that can be totaled in the text box.
Dim total as double
If chk_part1.checked = true then
total += partPrice
If chk_part2.checked = true then
total += partPrice
txtTotal.text = total
Not saying that this code is perfect but you could implement something along those lines to get the results you're looking for.
You can also do a For Each Statement. Such as:
Dim Form As New Form3.ControlCollection(Me)
For Each CheckBox As CheckBox In Form
If CheckBox.Checked = True Then
total += partPrice
End If
Next
So, In essense, it should cycle through all of the check boxes and, if they are checked, it adds the part price to the total.