Bump, Still looking for help please!
Hey guys, i'm making a program that in the end will be like a memory program for cards.
here is a few images:
So this image is just the basic program layout, it's really simple (and unfinished with the images)
This next image is when the card is selected it turns green
So, my question is, how would i make it so that If the card is selected (it's highlighted green) And, the button "mine" is pressed the shade will change to a blue color (which is just another image), Alternatively if the card is selected and the "thiers" button is pressed, it will change red, and that again is just a diffrent image similar to the selected image. And finally if the card is selected and remove is pressed the card will be removed (i think i got that part down using the hide() method and then using the show() method when i want to reset it).
My code currently when the card is selected:
I have tryed alot of diffrent things For the image color changing, but none of them Have seemed to work.Code:Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click, Button2.Click 'Ace of Clubs PictureBox1.Image = My.Resources.Ace_of_Clubs___Selected End Sub
The closest i have gotten is this:
Now, this is only for one picturebox, and there are 36 picture boxes total. I'm trying to get it for all of them selected and a button is pressed to change to that color or shade.Code:Dim Btn2Clicked As Boolean = False Dim Btn3Clicked as Boolean = False Dim Btn4Clicked as Boolean = false Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click If Btn2Clicked = True Then PictureBox1.image = My.Resources.Ace_of_Clubs___Mine Btn2Clicked = True ElseIf Btn3Clicked = True Then PictureBox1.Image = My.Resources.Ace_of_Clubs___Thiers Btn3Clicked = True ElseIf Btn4Clicked = true then PictureBox1.Hide() Btn4Clicked = True End If End Sub
I also tryed using an Image array that looked like this:
(I only did 4 pictures in this one, even though the normal one is 9)
However, after doing this array, i wasn't quite sure where to go with it.Code:Dim PicBoxes(3) As Image PicBoxes(0) = Image.FromFile(My.Resources.Ace_of_Clubs___Mine) PicBoxes(1) = Image.FromFile(My.Resources.King_of_Clubs___Mine) PicBoxes(2) = Image.FromFile(My.Resources.Queen_of_Clubs___Mine) PicBoxes(3) = Image.FromFile(My.Resources.Ten_of_Clubs___Mine)
Any help with this would be highly appreciated. If there is not enough information here, let me know and i'll add more information to better show the problem.
Last edited by money001; 04-15-2013 at 10:13 PM.
Bump, Still looking for help please!
Bump Again please, Need a bit of insight as to how to accomplish this task
So you want to change image on button click?
I'd recommend making a custom picturebox control with the following extra variables.
Then on the button click do the followingCode:is_selected
The code may contain an error as I have not tested it, but wrote it out-of-head.Code:for each item in me.controls if typeof item is card then if item.is_selected then 'do your mine/their's image code end if end if next
If You Like My Releases, Hit The Thanks button!
Follow the rules.
Successful Purchases: 2
Successful Sales: 1@The403
@sundy42
Scammed: 1@wZ. Gali
Favorite Quotes:
This may sound like a dumb question, but where would i input the is_selected variable?
Like, should i just make a new Private Sub called "is_selected" or would that be a new class or what? (I don't want to over complicate things)
Edit: i try'd to make a public function and here is the code that i have written for it:
and here is the code in the card:Code:Dim Selected As Boolean = False Public Function isSelected() Selected = True If isSelected() = Selected Then PictureBox1.Image = My.Resources.Ace_of_Clubs___Selected End If Return 0 End Function
(I know i screwed this up in the isSelected Function however i'm not sure how to fix it to make it work for every card (as atm it only would work if it actually worked for the picturebox1))Code:Private Sub PictureBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick 'Ace of Clubs isSelected() End Sub
Last edited by money001; 04-16-2013 at 11:46 PM.
Make a new project and give this a go.
2 pictureboxes, 1 button and 2 resources(images)
not the best way but you will think about it differently with this approach. if you need help understanding it send me a message.
but basically when you click on a picturebox it sets "SelectedCard" string to the controls name.
If it helps dont forget to Thanks. if you need more help send me a message.Code:Public Class Form1 Dim SelectedCard As String Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click Dim picBox As PictureBox = DirectCast(sender, PictureBox) Dim name As String = picBox.Name SelectedCard = name End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim pic As PictureBox pic = Me.Controls(SelectedCard) pic.Image = My.Resources.happy End Sub Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click Dim picBox As PictureBox = DirectCast(sender, PictureBox) Dim name As String = picBox.Name SelectedCard = name End Sub End Class
If You Like My Releases, Hit The Thanks button!
Follow the rules.
Successful Purchases: 2
Successful Sales: 1@The403
@sundy42
Scammed: 1@wZ. Gali
Favorite Quotes:
So, After how about for multiple pictureboxes how would i do that? I understand how to do it now for a single picturebox, and whenever i click on "mine" or "thiers" or "remove" it is supposed to set
But i'm trying to think of how to set it for picture boxes 1, 2, 3 and so on as to have multiple pictureboxes instead of just oneCode:is_selected = false
Edit: I think i just had a brain fart there, All i do is make each picture box is_selected = true, however, i still don't understand how to make it detect "if picturebox1.clicked & is_selected() then change to so and so card", or "if is_selected() & Button3.clicked then change to some card"
Sorry if i'm saying it a bit unclear, i'll try to fix it up to make it more understandable.
---------- Post added at 09:04 PM ---------- Previous post was at 08:59 PM ----------
I'm a bit unsure of what the "My.Resources.happy" is for. Can you please elaborate on this some? I read the code over a few times and it still doesn't make any sense to me.
edit: Alright, so i figured out what the .happy is for, and i changed it to the selected image card however, it just cycles through the cards and "selecting" them each one by one changing them to the same selected image, instead of diffrent images, but it was a good try.
Last edited by money001; 04-17-2013 at 09:08 PM.
sorry about the .happy :/
What this does is when the picture box is clicked the string "SelectedCard" will be set to that picture boxes name eg. PictureBox1.
this is so you dont accually have to know the name of the picturebox.
Code:Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click Dim picBox As PictureBox = DirectCast(sender, PictureBox) Dim name As String = picBox.Name SelectedCard = name End Sub
So, i'm still a bit unsure what to do with this section of code though:
The .happy isn't apart of my resources and as such, i can't debug because it gives me an error Should i rename it to something else?Code:Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim pic As PictureBox pic = Me.Controls(SelectedCard) pic.Image = My.Resources.happy End Sub
---------- Post added at 10:07 PM ---------- Previous post was at 10:01 PM ----------
So, i fixed it up a bit however i run into a problem when working with that .happy script and that is, that i should be able to select multiple cards at a time, and i need them to change to diffrent cards not just 1 single card (unless i can somehow add an opaque layer over the current image.
Again, make a custom picturebox control with the boolean "is_selected"
Then, when you click on it set the boolean to true
then on the button click to the following
Code:for each item in me.controls if typeof item is custompicturebox then item.MINE/THEIRS = true end if next
---------- Post added at 02:36 PM ---------- Previous post was at 02:35 PM ----------
No need to do that since the only object calling that sub is Picturebox1
If You Like My Releases, Hit The Thanks button!
Follow the rules.
Successful Purchases: 2
Successful Sales: 1@The403
@sundy42
Scammed: 1@wZ. Gali
Favorite Quotes:
Bump please
Bump bump...