naraynel Level: Trainee
 Registered: 08-11-2006 Posts: 1
|
RaiseEvent
Hi There,
Can someone help me please.
I am making a card game using the qcard32.dll and have dynamically placed various playing cards onto a form and used the Tools Menu in VB.Net 2005 to place several Labels onto the same form.
I have had a lot of trouble with the qcard32.dll but have persevered with it because it looks after the video display when the cards are moved. With the cards overlapping as in Solitaire this is a major challenge. The qcard32.dll is an old program made for the Windows 95 environment and I have no way of finding out how it processes the Subs or Functions. I have written to Stephen Murphy, the author of the Dll, and he said that "he didn’t use VB.Net but he did try using it with C# and it worked fine. You just need to call on its functions as Unmanaged code in a dll." I have used DllImport when declaring all the functions in the dll.
This all works but with problems. The Labels and the cards seem to be refreshed independently. The System looks after the labels but I have to have a Sub Form1_Paint to redraw the cards each time they are changed and as the System activates the Paint Sub I get a lot of flashing as it updates several times.
I have worked on this problem over the last few weeks and found that if I use the following code in the sub Form1_MouseDown
"Me.SetStyle(ControlStyles.UserPaint, False)"
it lets my program work better as it stops the system refreshing the form when the Mouse is pressed. The program is still not working properly in other parts of the code such as the load Sub or the DealCards Sub as it still repaints the screen several times and this causes the flashing. I have tried placing the above code into these subs but it then does not show any of the cards only the labels.
I know that I need to refresh the screen when I use these subs but I don't understand the WithEvents and RaiseEvent commands. Could someone give me an example using it with my Form1_Paint Sub
Code:
Public Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
I = 0
For I = 1 To 7 ‘The number of card rows.
For J = 1 To Counter(I) 'how many cards are in row.
x = GetCardX(CardArray(I, J))
y = GetCardY(CardArray(I, J))
DealCard(Me.HWnd, CardArray(I, J), x, y) ‘A routine in the qcards32.dll which places the cards (no drawing)
Next J
Next I
End Sub
I have dealt the cards using the following part code:
'Row One
CardArray(1, 0) = -1
For I = 1 To 3
DealCard(Me.HWnd, Deck(I), (((CARDWIDTH) * (I)) + PileSpacer1) + 45, 44)
SetUser2(Deck(I), 2) 'Used to control if card is blocked
CardArray(1, I) = Deck(I)
SetUser3(Deck(I), (I)) ' card's position in array '
SetUser4(Deck(I), 1) ' array ID '
If I > 0 Then PileSpacer1 = 143
If I > 1 Then PileSpacer1 = 283
Next I
Counter(1) = 3
Thanks for any help, it would be greatly appreciated.
Norman
|