|
|
I am writing a program that shows a listbox with the name of 5 bitmap images to pick from. This program will allow the user to pick one for each 16 pictureboxes on the next form. When the user is done, he will push a button and another form pops up and shows 16 pictureboxes with the images he selected for each.
I have the 16 pictureboxes and a working listbox but due to lack of experience using windows forms in visual basic, I don't know how to take the selection from the listbox and use an if statement to tell the second form what to print inside the box.
For example, it would look something like this:
if form1.listbox1.selection = red car
then form2.picturebox1.image = redcar.png
This doesn't work, obviously, but you see what I am trying to do.
Any ideas?
-Live long and prosper
|
|
|
|
|
I assume that you need the name of selected item in the listbox such as (red car, Purple car, etc.) and your aim is to use these values on both forms. All you need is a Global variable what will keep the selected item of Listbox. Then you can use this variable to call the values from form1. Here is a brief example.
<br />
<br />
Public MySelectedItem as String 'Define this out of a procedure or function<br />
<br />
<br />
FORM1<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim I as Int32 = Nothing<br />
MySelectedItem = Listbox1.SelectedItems.Item(I) <br />
End Sub<br />
<br />
FORM2<br />
<br />
Select Case MySelectedItem<br />
<br />
Case "Red car"<br />
Form2.PictureBox1.Image = image.fromfile("Redcar.png")<br />
Case "Purple car"<br />
<br />
End Selection<br />
<br />
<br />
I hope that helps
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Everything seems to work ok except this one thing......
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim I As Int32 = Nothing
MySelectedItem1 = ListBox1.SelectedItems.Item(I)
MySelectedItem2 = ListBox2.SelectedItems.Item(I)
MySelectedItem3 = ListBox3.SelectedItems.Item(I)
MySelectedItem4 = ListBox4.SelectedItems.Item(I)
Dim y As New Form2
Dim x As New Form3
x.ShowDialog()
y.ShowDialog()
End Sub
Error message says:
IndexOutOfRangeException was unhandled
Index is out of bounds of the array
The error points to the MySelectedItem1 = ListBox1.SelectedItems.Item(I)
-Live long and prosper
|
|
|
|
|
Use a delegate, not a global. If form2 is a child of form1, you don't even need a delegate, just expose a method on the form, assuming it's modeless.
NEVER expose a control on the second form, expose a property that sets a property of the control.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
By exposing a control, you mean that I shouldn't allow the user to interact with it? All that I intend to do with the second form is to allow the user to see 16 small windows with pictures of cars in them.
-Live long and prosper
|
|
|
|
|
I mean if form1 has a listbox called lb1, NEVER make it public. Always expose no more functionality to other classes than you need to.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Friends,
I have an one .Net windows application setup project which consist for following files.
1.Setup.exe
2.Setup.msi
3.sample.txt
My question is, how to get sample.txt file when installing the setup file?. Because i will be refer from some criteria in sample.txt file.
Urgent
Thanks in advance
Rameshkumar Thirumalaisamy
|
|
|
|
|
Windows.Forms.Application.StartupPath & "\" & "sample.txt"
Shay Noy
|
|
|
|
|
I am new to programming with databases. Any and all help will be very much appreciated. Thank you in advance.
I am writing an application that connects to an access database (4000 records). The database tracks boxes in a small warehouse. The box numbers are the primary key. Fields include the room number, store date, disposal date, section, shelf number.... I have successfully created a form with separate text boxes for each field. I can connect to the database and load the data into a DataSet. I can search the database by entering a box number and all of the text boxes update with the correct information. I can move forward or backwards one box at a time. The problem I am having is updating the database. Like I said, I'm new to this part of programming. I should never need to insert a line into the database, but I will most definately need to update a line. (One field is a y/n, y if the box is available for a new record.) The app will search for the first 'y' in the field and assign the user with the box number. The user will input the required info and save to the database.
Once again, I need to be able to update a line in an Access database. There is only one table.
I hope I have described this well enough to get some help. Thank you again!
Chuck
|
|
|
|
|
You need to do an Update SQL statement as following:
if you use a connection object:
con.execute "Update YourTable SET YourField= YourValue WHERE..."
if you use a database object:
db.execute "Update YourTable SET YourField= YourValue WHERE..."
Shay Noy
|
|
|
|
|
I believe I'm using a connection object. I don't really know the proper terminology. Here is a bit of my code.
Dim myConnectionString as String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=I:AccessDB.mdb"
Dim myConnection as new OleDb.OleDbConnection(myconnectionString)
---ONLOAD---
myConnection.open()
OleDbDataAdapter1.Fill(Dataset11)
And so on...
I take it this is a Connection object?
I have tried using MyConnection.execute but this doesn't work.
I'm not finding the ".execute" anywhere. Is there some Inherits that I'm missing? The only thing I'm Inherting at the moment is System.windows.forms.form
I'm sorry if I sound a little uneducated. This is the first serious application I've attempted and unfortunately my Associates in Programming probably wasn't worth the education I received. Thanks again.
|
|
|
|
|
Read up on the Update method of the OleDbDataAdapter
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
Hello every one
Is there any way how we can differentiate between the close click, in the control box and me.close call
My objective is...
I want the user to be able to minimize the form not to close it. When i handle it in form closing event i am not able to differentiate between me.close & lose clicked..
Regards
Nishkarsh
|
|
|
|
|
hi,
handle formClosing Event of Form which you want to minimize and write following statement
e.Cancel = True<br />
Me.WindowState = FormWindowState.Minimized
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
Thanks Rupesh
I think i have to explain the situation again
The idea was that we do not want the user to be able to close any form by clicking "Close" in control box
So we removed control box....
Now the objective is that the user should be allowed to minimize the the form..
So when we enable control box close option is also available
So i taught to handle it in form closing .... but the issue is now when i close the form from the code the same event is fired and i am not able to close the form...
Is there any way i can come over it???
I hope this will give a better understanding of my objective
Regards
Nishkarsh
|
|
|
|
|
I think the following may help you:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
e.Cancel = True
End If
End Sub
Shay Noy
|
|
|
|
|
I had tried this
shaynoy wrote: If e.CloseReason = CloseReason.UserClosing Then
e.Cancel = True
End If
In both the case "Me.close" and close from control box... the control come in the above condition only..
|
|
|
|
|
What about this:
Private _userClosed as Boolean = false
Public Sub SomeMethod()
_userClosed = true
Me.Close()
End Sub
Private sub Form_Closing(sender as object, e as EventArgs)
If (_userClosed) then
'-do what you want
Else
'-do what you want
End If
End Sub
Mike Lasseter
|
|
|
|
|
just use an extra variable that you set before the me.close statement then inside the form_closing event unless that variable is set.... e.cancel =true and exit sub
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
You can also disable the close button of the form:
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Long) As IntPtr
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const MF_DISABLED = &H2
Public Sub DisableCloseButton(ByVal hwnd As IntPtr)
Dim hMenu As IntPtr
Dim menuItemCount As Integer
hMenu = GetSystemMenu(hwnd, False)
menuItemCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, menuItemCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call RemoveMenu(hMenu, menuItemCount - 2, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(hwnd)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisableCloseButton(Handle)
End Sub
Shay Noy
|
|
|
|
|
|
Hi I am trying to make live Broadcast program using video cam which is attached to my laptop. I am relatvely new to this windows Media Encoder SDK. I found on the net this can be use to make the live broadcast program. Is there anyone familiar with those technology? Thanks a million
|
|
|
|
|
Do a seach on CodeProject for web cam. That might be able to help you.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
As part of a presentation software, I decided to write a custom control that provides cool text effects (like in powerpoint 2007). To support transparency, I used Bob Powell's code. Everything is fine in the designer, but when I try to animate the control, it flickers a lot. Double buffering just gives it a black background. Can anyone help me remove the flicker?
The code for the class:
Imports System.Drawing.Drawing2D
Public Class Text2007
Inherits System.Windows.Forms.UserControl
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
End Sub
Protected Sub InvalidateEx()
If (Parent Is Nothing) Then
Exit Sub
Else
Dim rc As New Rectangle(Location, Size)
Parent.Invalidate(rc, True)
End If
End Sub
Protected Overrides Sub OnMove(ByVal e As EventArgs)
Me.InvalidateEx()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim bm As New Bitmap(CInt(Me.ClientSize.Width / 5), CInt(Me.ClientSize.Height / 5))
Dim pth As New GraphicsPath()
pth.AddString(Me.Text, New FontFamily("Verdana"), CInt(FontStyle.Regular), 100, New Point(20, 20), StringFormat.GenericTypographic)
Dim h As Graphics = Graphics.FromImage(bm)
Dim mx As New Matrix(1.0F / 5, 0, 0, 1.0F / 5, -(1.0F / 5), -(1.0F / 5))
h.SmoothingMode = SmoothingMode.AntiAlias
h.Transform = mx
Dim p As New Pen(Color.Yellow, 3)
h.DrawPath(p, pth)
h.FillPath(Brushes.Yellow, pth)
h.Dispose()
e.Graphics.Transform = New Matrix(1, 0, 0, 1, 50, 50)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic
e.Graphics.DrawImage(bm, ClientRectangle, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)
e.Graphics.FillPath(Brushes.Black, pth)
pth.Dispose()
End Sub
Public Sub pInvalidate()
Me.InvalidateEx()
End Sub
End Class
~ Soumya92
|
|
|
|