|
Hi,
I've been working more on this and came up with the following. wondering if State variable makes any difference. Anyhow, when I run at runtime, the card from image1 pile that I drag from the left to the right over the same card, actually copies all of those cards in the entire suit of the hearts cards. Hope this makes sense. Here is the code.
Private Sub Image1_DragOver(Index As Integer, Source As Control, _
X As Single, Y As Single, State As Integer)
Dim HeartsIndex As Integer
For Index = 0 To 12
For HeartsIndex = 0 To 12
If State = 0 Then
Hearts(HeartsIndex).Picture = Image1(Index).Picture
End If
Next
Next
End Sub
Private Sub Hearts_DragOver(Index As Integer, Source As Control, _
X As Single, Y As Single, State As Integer)
Dim HeartsIndex As Integer
If State = 2 Then
If Hearts(HeartsIndex).Picture <> Image1(Index).Picture Then
Image1(Index).Drag vbEndDrag
MsgBox ("You're Right")
Exit Sub
Else
Image1(Index).Drag vbCancel
MsgBox ("You're Wrong")
End If
End If
End Sub
Private Sub Image1_DragDrop(Index As Integer, Source As Control, _
X As Single, Y As Single)
If Source.Name <> Image1(Index).Picture Then Exit Sub
Image1(Index).Picture = Source.Picture
End Sub
Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
For Index = 0 To 12
Hearts(Index).Picture = Source.Picture
Next
End Sub
|
|
|
|
|
I don't think you want to be doing this.
When you drag a card from the left (i.e. image1(x)) to right, when the dragged card enters the Hearts() area then Hearts_DragOver is triggered. At this point you should only be doing something like changing the Hearts background to give visual indication to the user; and restoring original background if state = 1. You should not be changing the image to that of the card you have dragged - that should be done in Hearts_DragDrop.
The state variable only tells you if you are entering (0), leaving (1) or moving within (2) the target area. So when state=0 and the user releases the mouse button, a Hearts_DragDrop event is triggered - it's in that event that you would want to change the image.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thank you; so this code wouldn't work then? I thought I had it close, but get a runtime error of 340. So, I'll take heed of your suggestion though; back to the drawing board. Thanks in advance.
Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
Dim NewIndex As Integer
'For Index = 0 To 12
'If TypeOf Source Is Image Then
' Hearts(Index).Picture = Source.Picture
'End If
'Next
Index = 0
NewIndex = 0
For Index = 0 To 12
For NewIndex = 0 To 12
Image1(Index).Picture = Hearts(NewIndex).Picture
Index = Index + 1
NewIndex = NewIndex + 1
Next
Next
For Index = 0 To 12
For NewIndex = 0 To 12
If Image1(Index).Picture = Hearts(NewIndex).Picture Then
Image1(Index).Drag vbEndDrag
MsgBox ("You're right!")
Exit Sub
Else
Image1(Index).Drag vbCancel
MsgBox ("This card does not belong here")
Exit Sub
End If
Next
Next
End Sub
|
|
|
|
|
I'm a bit still confused; you think I should use dragover? dragdrop seems to allow me to drag and drop the cards just fine. Problem is I don't know how to write the code for this....what you are stating....I know State is for dragover, but if I don't use that, I use source for dragdrop. Now I don't even know the right settings for the cards on the left and on the right for in design mode, dragmode, oledragdrop, and oledrag...something, can't remember off the top of my head. But now I have all those confused and that's what might be causing my code not to work properly. Can you pleeeeeese help? You're my only hope.
|
|
|
|
|
ymilan wrote: you think I should use dragover?
Not for dropping the image. As I said you should only be changing something like the background or border of the target to give user feedback. If you don't want to give feedback do nothing.
To see why imagine you have a form with four images.
On the left is an image called theShape; on the right are three images called BoxA, BoxB and BoxC.
Imagine that the user selects theShape image and drags it to the right of the form (i.e.they are holding the mouse button down).
Suppose they drag the shape over the BoxA image. This will trigger the BoxA_DragOver event with state = 0. What should this event do? One option is nothing, so you don't write any code for the event. Another option is to change the border or color of the BoxA image so the user knows that theShape is over BoxA. What you should not do is set BoxA image to theShape image. The user has not released the mouse button so they don't want theShape to be in BoxA.
If the user does release the mouse button then the BoxA_DragDrop event is triggered. That is when you might want to set BoxA image to theShape so that the code to do so should be in the BoxA_DragDrop event.
Suppose the user drags theShape over the BoxA image (without releasing the mouse button) and then drags it over the BoxB image. Two things happen. First the BoxA_DragOver event is triggered with state = 1; then the BoxB_DragOver event is triggered with state = 0. In this case the BoxA_DragDrop could set the border or color back to their original values and the BoxB_DragDrop could change the border or color of BoxB image. Again, BoxB_DragOver should not set the BoxB image to theShape image. The user might continue the drag so it goes over BoxC.
If you imagine that the images for the boxes are much larger than theShape image, then as the user drags theShape around in a box image the DragOver event is triggered continuously with state = 2. In most cases that does not matter so the code does nothing.
This all means that the typical code for a DragOver event will be something like:
If State = 0 Then
'Do something like change border or color of the box
'You simply want to make user aware of where theShape has been dragged too
Else
If State = 1 Then
'Set the border/color of the box back to original value
Else 'State = 2
'Do nothing - they are moving around within the box
End If
End If
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Awesome! I understand dragover now! I will write that and see how I do. However, please assist on dragdrop; what do I put in that code? I tried hearts(index).Picture = Source, like every tutorial I read said to do. Then do I do vbenddrag and vbcancel like I did before, or is this in error?
|
|
|
|
|
Ok, this is the code I have so far, but ALL the cards from every suit are allowed to drop on the target. In design view, I need some assistance on whether to put Manual, Autmatic, or None or DragDrop, OLEDragOver, OLEDragDrop.....I think that may be messing this whole thing up. Anyhow, my code is below; any errors?
Private Sub Hearts_DragOver(Index As Integer, Source As Control, _
X As Single, Y As Single, State As Integer)
For Index = 0 To 12
If State = 0 Then
CommonDialog1.Flags = &H80FFFF
CommonDialog1.ShowColor
Hearts(Index).BackColor = CommonDialog1.Color
Else
If State = 1 Then
CommonDialog1.Flags = &HFFFFFF
CommonDialog1.ShowColor
Hearts(Index).BackColor = CommonDialog1.Color
Else
If State = 2 Then
End If
End If
End If
Next Index
End Sub
Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
For Index = 0 To 12
Hearts(Index).Picture = Source.Picture
Source.Picture = Image1(Index).Picture
Next Index
For Index = 0 To 12
If Image1(Index).Picture = Hearts(Index).Picture Then
Image1(Index).DragMode Manual
Image1(Index).Drag vbEndDrag
MsgBox ("You're Right")
Else
Image1(Index).Drag vbCancel
MsgBox ("You're Wrong")
End If
Next Index
|
|
|
|
|
Firstly, I don't think you should be messing with OLEDrag* at all, so would set OLEDragMode property to 0. OLE drag features are for dragging and dropping data rather than images. E.g. drag data between DataGrid controls.
Secondly, I don't think you should have loops in the Hearts_DragOver or Hearts_DragDrop events. You probably should not be changing the value of Index (as the loops are doing) and I doubt that you should be changing the Source.Picture.
Imagine the following. There is a form with two control arrays called theShapes and theBoxes. Both have say 5 items (so indexes go from 0 to 4) with theShapes on left of form; theBoxes on right.
The user clicks and drags e.g. theShapes(3) image over to the right.
Suppose it is dragged over theBoxes(1) image. Then the theBoxes_DragOver event is triggered with Index = 1 and State = 0. So in the code the only image that should change color is theBoxes(1). All the other theBoxes() images should remain as they were. So no loop required. Also, the Source is theShapes(3) and presumably you don't want its picture to change. So you never want to be doing something like Source.Picture = SomeOtherControl.Picture .
Suppose that the object is to place the correct shapes in the correct boxes. So at the start theBoxes() all have some blank image; theShapes() all have some appropriate image. E.g. theShapes(3) could be a triangle, theShapes(4) could be a circle, etc. If the user drags a shape and drops it into a box, the box should only accept it if it is the correct shape. So e.g. if theShape(3) (i.e. a triangle) is dragged and dropped into theBoxes(1), the drop should only succeed if theBoxes(1) accepts triangles. So how do we tell if this is the case? We cannot compare pictures because theBoxes() are all a blank image so will never be the same as a shape image.
One way of doing this is to set the Tag property for each of the controls and compare the Tags before allowing the drop to succeed or fail.
E.g. when setting up the control arrays you would have something like
theShapes(3).Tag = "Triangle"
theBoxes(0).Tag = "Square"
theBoxes(1).Tag = "Triangle"
theBoxes(2).Tag = "Circle"
In the theBoxes_DragDrop event you would then have something like
If theBoxes(Index).Tag = Source.Tag Then
'Allow the drop
Else
'Cancel the drop
End If
I think this is how to do it. But to do so requires that the DragMode for theShapes() to be set to 0 (i.e. vbManual) and that the Drag method is implemented. I might be wrong about this, it may be possible to cancel the drop when mode is set to vbAutomatic but I can't think how it would work.
The DragMode should be set when the controls are created, I can't think of a good reason to set the mode in the DragDrop event of another control.
Finally, the mode for theBoxes controls should be set to vbManual and no Drag method implemented. This stops the user from dragging theBoxes controls around.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Wow! Thanks for the expert explanation. Does this mean I would put:
Image1(0).Tag = Hearts(0).Tag
Somewhere in the first part of the code? Where so? This is all my code so far; problem is which ever card is in the first slot (as in Image1(0)), but can be any card, when dropped over Hearts(0), it says, you're right and allows drop. If the real Image1(0).Picture, King Hearts is dropped over Hearts(0), it says you're wrong.
I changed all my settings in design mode to put images on the left as Automatic and none for both OLE modes. I set images on the right to be Manual for drag and none for both Ole modes. Any problems on this? Here is all of my code so far: I appeciate your help....
Option Explicit
Public Sub Main()
Start_Game.Show
End Sub
Private Sub Exit_Click()
MsgBox ("Thank you for playing. Good Bye.")
End
End Sub
Private Sub Start_Click()
Dim arrDeck(52)
Dim Cardcount As Integer
Dim Counter As Integer
Do While Cardcount <= 51
arrDeck(Cardcount) = Cardcount
Cardcount = Cardcount + 1
Loop
Dim swap As Integer
Dim posn1 As Integer
Dim posn2 As Integer
Randomize
For swap = 0 To 100
posn1 = Int(52 * Rnd)
posn2 = Int(52 * Rnd)
If (posn1 <> posn2) Then
KingH(0).Picture = Image1(posn1).Picture
Image1(posn1).Picture = Image1(posn2).Picture
Image1(posn2).Picture = KingH(0).Picture
End If
Next swap
Counter = 0
For Counter = 0 To 51
Image1(Counter).Visible = True
Next Counter
End Sub
Private Sub Hearts_DragOver(Index As Integer, Source As Control, _
X As Single, Y As Single, State As Integer)
If Index <= 12 Then
If State = 0 Then
Hearts(Index).Picture = LoadPicture("C:\Program1\redbacking.gif")
Else
If State = 1 Then
Hearts(Index).Picture = Hearts(Index).Picture
Else
If State = 2 Then
End If
End If
End If
End If
End Sub
Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
If Hearts(Index).Tag = Source.Tag Then
Image1(Index).Drag vbEndDrag
MsgBox ("You're Right")
Else
Image1(Index).Drag vbCancel
MsgBox ("You're Wrong")
Exit Sub
End If
End Sub
|
|
|
|
|
ymilan wrote: put images on the left as Automatic and
Then you cannot stop the drop - you can only do that if the mode is Manual and you have a Drag method which allows you to Cancel the drop.
ymilan wrote: If State = 0 Then
Hearts(Index).Picture = LoadPicture("C:\Program1\redbacking.gif")
Else
If State = 1 Then
Hearts(Index).Picture = Hearts(Index).Picture
Else
This won't work - when you DragDrop is triggered with State = 0 (entering) the Hearts(Index).Picture is changed to the gif. When it is triggered with state = 1 (leaving) it set back to itself i.e. to the gif it was set to when entering.
ymilan wrote: Does this mean I would put:
Image1(0).Tag = Hearts(0).Tag
Somewhere in the first part of the code?
Have you set Hearts(x).Tags in Designer for all controls? If so and you want the Image(x).Tags to be the same as the Hearts(x) tags, you need to do so in the Form_Load event. But I'm not sure that's what you want.
Is this the complete code? There seems to be something missing e.g. this is not right.
ymilan wrote: Private Sub Exit_Click()
MsgBox ("Thank you for playing. Good Bye.")
End
End Sub
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Can I have your email address again to take this offline? I have some gifs to show you.
Thanks.
YMilan
|
|
|
|
|
When I put the images on the left in design view as automatic, when they are in a random place, i.e. image1(0), King of Hearts, they do not move at all. When I put them in manual, they move.
For some reason; and you said; but I don't understand the reason; when in State 0, I move the images, i.e. King of Hearts to the top of the hearts(0) image (a white backing gif, not King of Hearts. I did this so I can show a white backed card, so the player can see a white card instead of a black space. I can place the redbacking card no problem when the card enters the white backed card on the right. It works. However, if it is right, it doesn't drop the Image1(Index).Picture at all. It leaves it a redbacking gif.
Now, when my images on the left are randomized, and I want to pic out the King of Hearts on the left, somewhere in the shuffle, it says you're wrong when I place it over the hearts(0) position on the right. It shows a red backing but, does not say You're right or drop the card. I have that code in my hearts dragdrop; you'll see above in my last code reply. However, when I place a random card from the Image1(0) POSITION on the left, it works and says you'r right, but that is the wrong card....???? Don't understand. It leaves a redbacked gif as well, when it is the wrong card, but say's your're right.
You're helping me and I'm glad; Thank you.
|
|
|
|
|
Oh in addition, what I need to know is what setting, manual, automatic, or none do I set in design view for the one dragmode, and two oledrag properties?
|
|
|
|
|
This is what I've tried as well....still in design mode I have each image1 card set to Manual for dragmode, Automatic for oledragmode and automatic for oledropmode. Not sure what to set the hearts cards to though...tried many different modes and all seems confusing...here is my code so far: Wondering if I should have the question of whether image1(1 through 12) = Hearts(1 through 12) in the dragdrop not dragover....I tried that too, but no avail.
Public Sub Image1_Click(Index As Integer)
For Index = 0 To 12
Hearts(Index).Picture = Image1(Index).Picture
Next Index
For Index = 13 To 25
Clubs(Index).Picture = Image1(Index).Picture
Next Index
For Index = 26 To 38
Diamonds(Index).Picture = Image1(Index).Picture
Next Index
For Index = 39 To 51
Spades(Index).Picture = Image1(Index).Picture
Next Index
End Sub
Private Sub Hearts_DragOver(Index As Integer, Source As Control, _
X As Single, Y As Single, State As Integer)
For Index = 0 To 12
If State = vbEnter Then
If Source.Picture = Image1(Index).Picture Then
If Image1(Index).Picture = Hearts(Index).Picture Then
Image1(Index).Drag vbEndDrag
MsgBox ("You're Right")
Exit Sub
Else
Image1(Index).Drag vbCancel
MsgBox ("You're Wrong")
Exit Sub
End If
End If
End If
Next Index
End Sub
Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
For Index = 0 To 12
Hearts(Index).Picture = Source.Picture
Next Index
End Sub
|
|
|
|
|
I need to attached to the event.
AddHandler client.evDeliverSm, AddressOf client_evDeliverSm
It is to enable me to receive SMS from SMSC in my SMPP client. How can I achieve this.
Thank you.
Thayhor
|
|
|
|
|
You're going to have to consult the documentation on the library that you're using. It should give you the signature of the method that you have to build so you can wire up the event handler with AddHandler.
|
|
|
|
|
Thanks for your prompt response. Actually there was no documentation on the library for now. The Moderator said I should make sure I attached to event:
AddHandler client.evDeliverSm, AddressOf client_evDeliverSm
The source code already have this;
Private Sub client_evDeliverSm(ByVal sender As Object, ByVal data As DeliverSm)
Dim messageText As String = SmppClient.GetMessageText(data.UserDataPdu.ShortMessage, data.DataCoding)
MessageBox.Show("Source: " + data.SourceAddr + "Text: " + messageText + "Coding: " + data.DataCoding.ToString())
End Sub
I just need a sample illustration. I can send sms but cannot receive.
An sample code to attached to the event will be appreciated.
Thank you.
Thayhor
|
|
|
|
|
OK, so in an appropriate place you make the AddHandler call to wire up the event. Where you put this depends on your design and code.
You already have the pieces, you just need to place them.
If there is only a specific time where it's legal for your code to receive messages, put the AddHandler in the code that sets up the receive.
|
|
|
|
|
Thank you.
I don't have any specify time to receive, I can receive from my smsc anytime. Can I leave it the way it was? or I should add a timer event;
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
AddHandler client.evDeliverSm, AddressOf client_evDeliverSm
End Sub
And when connected to smsc then enable timer1. Interval is 1sec i.e 1000.
I just want to perfect everything on my own side b/4 contacting my smsc provider which claims that shortcode "1234" have been added for me to receive sms.
Thank you.
Thayhor
|
|
|
|
|
No timers. You only need to setup the handler once, probably in Form.Load when your app starts.
|
|
|
|
|
hi,
i want to bing the checkedlistbox control with datasource,(with a table that in which i am fetching data from database.)
i am using the following code.
checkedlistbox.datasource = table
checkedlistbox.diplaymember = columnname
This is working fine.
after the execution of this code, the screen flickers and datarowview (a text) displays in the first row of checklistbox control and disappears after the control populates completely. I was using the loops to populate the control, but that was quite slow process, now the execution is faster, but the screen flickers a lot.
Please help
|
|
|
|
|
So, all you're doing is setting the DataSource and DisplayMember properties and the form is flickering constantly after that??
|
|
|
|
|
Yes, after writing this code, the checkedlistbox first row creates problem, in the first row, it shows a text dataroweview
and afterwards this text disappears and the control gets populated with the data.
Please suggest anything..
|
|
|
|
|
I am trying to play music in my application using command
My.Computer.Audio.Play (complete path , AudioPlayMode.Background).
The file I am trying to use is a wavefile(.wmv). However when the command is executed an exception is thrown saying The specified file is not PCM type wavefile. Please help regarding what i am supposed to do.
I am using Visual Studio 2008.
modified on Wednesday, May 6, 2009 2:40 PM
|
|
|
|
|
It's quite plain. The file you're trying to play is not in the correct format. Just because the file extension is WMV doesn't mean that the audio is encoded the same as every other WMV. The audio in each file, no matter what the extension, is encoded using different codecs, compressor/decompressors. But, there is a standard format called PCM (Pulse Coded Modulation) that is kind of like the Text file of the audio world. It's audio that is not compressed at all. This is the format that the Audio.Play method supports. It cannot play audio that is compressed. You have to use some kind of tool to create a new file with the audio uncompressed.
|
|
|
|
|