关键词:vb.net 扑克 cards.dll

Posted on 2006-02-09 16:56  岳洋  阅读(576)  评论(0)    收藏  举报
网上的确有,不过不知道为什么我那里运行不了。这里提供的代码是paint在panel上的。.net真好啊,不用设备上下文,gethdc默认还是隐藏的……我找来找去都找不到这个方法……
几点注意:
1.记得要把dll初始化,function cdtInit。两个参数,在网上找吧。
2.要redraw panel,用:Panel1.Invalidate()。
Public Class Form1
    
Inherits System.Windows.Forms.Form
    
Dim pcards(3As card
    
Dim p As card
    
Dim i As Integer
    
Declare Function cdtInit Lib "cards.dll" (ByRef width As Integer, _
    
ByRef height As IntegerAs Boolean
    
Declare Function cdtDrawExt Lib "cards.dll" (ByVal hdc As IntPtr, _
      
ByVal x As IntegerByVal y As IntegerByVal dx As Integer, _
      
ByVal dy As IntegerByVal card As Integer, _
      
ByVal suit As IntegerByVal color As LongAs Boolean
    
Declare Sub cdtTerm Lib "cards.dll" ()

    
Public Structure card
        
Public face As Integer
        
Public suit As Integer
        
Public count As Integer
        
Public faceup As Boolean
    
End Structure



Windows 窗体设计器生成的代码


    
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        
Dim ct As Int16 = 0
        
For ct = 1 To 3
            drawcard(pcards(ct), e.Graphics, 
10 + ct * 203075100)
        
Next
        
'For Each p In pcards
        'drawcard(p, e.Graphics, 10 + ct * 10, 30, 75, 100)
        'ct += 1
        'Next

    
End Sub

    
Private Sub drawcard(ByVal t As card, ByVal g As Graphics, ByVal x As Integer, _
     
ByVal y As IntegerByVal dx As IntegerByVal dy As Integer)
        
Dim hdc As IntPtr = g.GetHdc()
        
Try
            
Dim Card As Integer = t.suit * 4 + t.count
            cdtDrawExt(hdc, x, y, dx, dy, Card, 
00)
        
Finally
            
' If Intellisense doesn't show this method 
            ' unhide advanced members in Tools|Options
            g.ReleaseHdc(hdc)
        
End Try
    
End Sub


    
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cdtInit(
75100)

        
For i = 1 To 3
            pcards(i) 
= New card()
            
With pcards(i)
                .suit 
= i
                .count 
= i + 1
            
End With
        
Next
        Panel1.Invalidate()
    
End Sub

End Class


博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3