|
> やはり、自前でなんとかするしかなさそうですね。
あれ?・・・
BitmapRegion.cs で、渡されたBitmapのGraphicsPathを算出してRegionに
代入してくれているんで・・・(そのもの)
自前も何も、そのまま使えますが・・・
※ C# をVBにできない?・・・と言うことですか?
私は別クラスモジュールに定義してDLLにしたのですが・・・
下記のコード参考・・・
Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
#Region "Public Functions"
Public Sub CreateControlRegion(ByVal ctrl As Control, ByVal bitmap As Bitmap)
If ctrl Is Nothing Or bitmap Is Nothing Then
Exit Sub
End If
ctrl.Width = bitmap.Width
ctrl.Height = bitmap.Height
If TypeOf (ctrl) Is Form Then
Dim objForm As System.Windows.Forms.Form = CType(ctrl, System.Windows.Forms.Form)
With objForm
.Width += 15
.Height += 35
.FormBorderStyle = FormBorderStyle.None
.BackgroundImage = bitmap
End With
Dim gp As GraphicsPath = CalculateControlGraphicsPath(bitmap)
objForm.Region = New Region(gp)
ElseIf TypeOf (ctrl) Is Button Then
Dim btn As Button = CType(ctrl, Button)
With btn
.Text = ""
.Cursor = Cursors.Hand
.BackgroundImage = bitmap
End With
Dim gp As GraphicsPath = CalculateControlGraphicsPath(bitmap)
btn.Region = New Region(gp)
End If
End Sub
#End Region
#Region "Private Functions"
Private Function CalculateControlGraphicsPath(ByVal bitmap As Bitmap) As GraphicsPath
Dim gp As GraphicsPath = New GraphicsPath()
Dim colorTransparent As Color = bitmap.GetPixel(0, 0)
Dim colOpaquePixel As Integer = 0
For row As Integer = 0 To bitmap.Height - 1
colOpaquePixel = 0
For col As Integer = 0 To bitmap.Width - 1
If bitmap.GetPixel(col, row) <> colorTransparent Then
Dim colNext As Integer = col
colOpaquePixel = col
For colNext = colOpaquePixel To bitmap.Width - 1
If bitmap.GetPixel(colNext, row) = colorTransparent Then
Exit For
End If
Next
gp.AddRectangle(New Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1))
col = colNext
End If
Next
Next
Return gp
End Function
#End Region
で、Bitmapは、リソースファイルに埋め込んで使用するようにしたので・・・
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim asm As System.Reflection.Assembly
Dim rm As System.Resources.ResourceManager
asm = System.Reflection.Assembly.GetExecutingAssembly()
rm = New System.Resources.ResourceManager(asm.GetName().Name + ".Resource1", asm)
bmpFrmBack = CType(rm.GetObject("back"), Bitmap)
bmpBob = CType(rm.GetObject("bob"), Bitmap)
bmpSmiles = CType(rm.GetObject("smiles"), Bitmap)
bmpGreenBtnUp = CType(rm.GetObject("greenbtnup"), Bitmap)
bmpX = CType(rm.GetObject("x"), Bitmap)
bmpBobSay = CType(rm.GetObject("bobsay"), Bitmap)
bmpSmilesAngry = CType(rm.GetObject("smilesangry"), Bitmap)
bmpGreenBtnDown = CType(rm.GetObject("greenbtndown"), Bitmap)
bmpXSmile = CType(rm.GetObject("xsmile"), Bitmap)
Me.Width = bmpFrmBack.Width
Me.Height = bmpFrmBack.Height
Button1.Left = (Me.Width \ 4)
Button2.Left = (Me.Width \ 4) * 3
Button3.Left = (Me.Width \ 4) * 2
Button4.Left = (Me.Width \ 4) * 3
Button1.Top = (Me.Height \ 4)
Button2.Top = (Me.Height \ 4)
Button3.Top = (Me.Height \ 4) * 2
Button4.Top = (Me.Height \ 4) * 3
Using br As BitmapRegion.BitmapRegion = New BitmapRegion.BitmapRegion
With br
.CreateControlRegion(Me, bmpFrmBack)
.CreateControlRegion(Button1, bmpBob)
.CreateControlRegion(Button2, bmpSmiles)
.CreateControlRegion(Button3, bmpGreenBtnUp)
.CreateControlRegion(Button4, bmpX)
End With
End Using
End Sub
マウスの操作(MouseEnter/MouseLeave)や、フォームの移動(MouseMove)の部分くらいは
解読してインプリしてネ!
以上。
|