当前位置:编程学习 > VB >>

用VB帮做一个心形图形

同题,速度啊。。。 --------------------编程问答-------------------- loadpicture --------------------编程问答--------------------
引用 1 楼 wallescai 的回复:
loadpicture
--------------------编程问答-------------------- 想去泡mm啊  --------------------编程问答-------------------- 想用什么做? PICTRUEBOX然后设透明色? 还是怎么样? --------------------编程问答-------------------- 不清不楚的问题 --------------------编程问答-------------------- --------------------编程问答-------------------- 自己先画一个心形(任意图形都可以),然后将窗体设置成透明就可以了。
参考代码:
Option Explicit

'Example Name:Path2Region
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Click()
    'end..
    Unload Me
End Sub
Private Sub Form_Load()
    Me.Width = 800 * 15
    Me.Height = 600 * 15
    Dim hRgn As Long
    Const sText = "O"
    'set the font to 'Times New Romen, size 72'
    Me.FontName = "Times New Roman"
    Me.FontSize = 256
    'set the backcolor to Red
    Me.BackColor = vbRed
    'open a path bracket
    BeginPath Me.hdc
    'draw the text
    TextOut Me.hdc, 0, 0, sText, Len(sText)
    'close the path bracket
    EndPath Me.hdc
    'convert the path to a region
    hRgn = PathToRegion(Me.hdc)
    'set the Window-region
    SetWindowRgn Me.hWnd, hRgn, True
    'destroy our region
    DeleteObject hRgn
End Sub

--------------------编程问答-------------------- Option Explicit

'Example Name:Path2Region
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function TextOutW Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long

Private Sub Form_Click()
    'end..
    Unload Me
End Sub
Private Sub Form_Load()
    Me.Width = 800 * 15
    Me.Height = 600 * 15
    Dim hRgn As Long
    
    Dim S(2) As Byte
    
    S(0) = &H65
    S(1) = &H26
    
    'set the font to 'Times New Romen, size 72'
    Me.FontName = "Times New Roman"
    Me.FontSize = 500
    'set the backcolor to Red
    Me.BackColor = vbRed
    'open a path bracket
    BeginPath Me.hdc
    'draw the text
    TextOutW Me.hdc, 0, 0, VarPtr(S(0)), 1
    'close the path bracket
    EndPath Me.hdc
    'convert the path to a region
    hRgn = PathToRegion(Me.hdc)
    'set the Window-region
    SetWindowRgn Me.hWnd, hRgn, True
    'destroy our region
    DeleteObject hRgn
End Sub
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,