|
-
Nov 8th, 2006, 06:44 PM
#1
Thread Starter
New Member
[2005] Raise Event or refresh the form
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.
At this stage the program 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 feel that I now need to refresh the screen when I use these subs (DealCards) but I don't understand the WithEvents and RaiseEvent commands. Could someone give me an example using it with my Form1_Paint Sub or is there another way to refresh the screen,any suggestion would be appreciated.
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.
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
-
Nov 10th, 2006, 09:16 PM
#2
Thread Starter
New Member
Re: [2005] Raise Event or refresh the form
Hey there,
I’m getting a bit of a complex here. I am wondering why no one has tried to answer my problem. Am I asking the impossible or have I not stated my problem clearly.
Please, Please help, I really need your help and any help would be appreciated.
Here is a summary of my problem.
I am making a card game using the qcard32.dll and have dynamically placed various playing cards onto a form. I have also used the Tools Menu in VB.Net 2005 to place several Labels onto the same form. This all works but with problems. The Labels and the cards seem to be refreshed independently. The program 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 Form1_Paint Sub I get a lot of flashing as it updates several times.
I have used the following code in the sub Form1_MouseDown
VB.Net Code: "Me.SetStyle(ControlStyles.UserPaint, False)"
This stops the program automatically refreshing the form each time the mouse is pressed and therefore stops some of the flashing. I have tried placing the above code into other subs such as the DealCards Sub but then the program stops showing the cards and just shows the labels. I feel that if I use this code ("Me.SetStyle(ControlStyles.UserPaint, False)" in other parts of my program to stop the repainting then I will have to activate the repainting myself.
Therefore my question is how do I repaint the form after I use other subs in my program such as DealCards or Load my form. Here is my sub that repaints the form.
VB.Net 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)) ) ‘Uses a routine in the qcards32.dll which gets the x co-ordinates.
y = GetCardY(CardArray(I, J)) ) ‘Uses a routine in the qcards32.dll which gets the y co-ordinates.
DealCard(Me.HWnd, CardArray(I, J), x, y) ‘A routine in the qcards32.dll which places the cards
‘CardArray holds
'the various cards
Next J
Next I
End Sub
Can someone help me please.
Thank you.
Norman
-
Nov 11th, 2006, 09:24 AM
#3
Re: [2005] Raise Event or refresh the form
Why all the repainting? Can't you simply use pictureboxes?
-
Nov 11th, 2006, 06:12 PM
#4
Thread Starter
New Member
Re: [2005] Raise Event or refresh the form
Thanks Half for the reply.
No I can't use Pictureboxes for the playing card action because I would have problems restoring the background each time the cards are moved. This is why I used the Qcards32.dll, it looks after the background.
My thinking at the moment is to make a new Sub that will do the painting when called but I get an error that I'm not supplying the argument for the "System.Windows.Forms.PaintEventArgs".
Please send some more suggestions.
Thanks
Norman
-
Nov 11th, 2006, 08:54 PM
#5
Re: [2005] Raise Event or refresh the form
Did you actually have those problems or are you anticipating them? 
Anywayz, try Me.SuspendLayout in the beginning and Me.ResumeLayout in the end of the Form1_Paint
-
Nov 11th, 2006, 09:07 PM
#6
Re: [2005] Raise Event or refresh the form
The above should work if you chose to use pictureboxes, not sure about the repainting though.
This posting should help you in your current situation.
-
Nov 11th, 2006, 09:11 PM
#7
Re: [2005] Raise Event or refresh the form
All painting should be done IN or FROM the Paint event handler of the appropriate control. A Graphics object is supplied to that event handler and you can then pass that to other methods if required. If you need to force a repaint of the control then you call its Refresh or Invalidate method. There should be no cause to paint on controls in any other way.
-
Nov 12th, 2006, 02:05 AM
#8
Thread Starter
New Member
Re: [2005] Raise Event or refresh the form
Thank you to both jmcilhinney and Half for your advice and help, it is greatly appreciated.
Half:
No I haven't actually experienced those problems but I listened to other coders on the net and in books who said this. Looking back this was probably in VB6 and VB.Net is different. I would like to carry on with this at the moment because of all the time I have spent on it. The game is working but with problems. I will try your PictureBox idea later but as I am just learning I will have to do some study. The SuspendLayout code didn't seem to help but your other suggestion (isReady) shows promise. I will work on this and see how we go.
jmcilhinney:
At present the problem is that I am getting too many repaints. When the form is first loaded it seems to repaint 3 times, twice without the cards and then with the cards. It is this that I'm trying to stop.
Thanks again.
Norman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|