I have 3 buttons and 3 pictureboxes, one button per picbox. But my problem is, i copied your code 3 times and works once only. I want to show my codes to fix whats wrong... Thanks for replying jmcilhinney
What do you think is my problem here? Button1 is the only button transparent to its respective picturebox, but the other two don't work.. When I place the Me.EmbedButtonInPictureBox2(Me.Button2, Me.PicBox2) code before the first one, that button will be transparent the other two again, arent transparent same with the 3rd ones.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.EmbedButtonInPictureBox1(Me.Button1, Me.PicBox1)
Me.EmbedButtonInPictureBox2(Me.Button2, Me.PicBox2)
Me.EmbedButtonInPictureBox3(Me.Button3, Me.PicBox3)
End Sub
Private Sub EmbedButtonInPictureBox1(ByVal btn1 As Button, ByVal pbx As PictureBox)
Dim buttonLocation As Point = pbx.PointToClient(Me.PointToScreen(btn1.Location))
btn1.Parent = pbx
btn1.Location = buttonLocation
Dim buttonBackground As New Bitmap(btn1.Width, btn1.Height)
Using g As Graphics = Graphics.FromImage(buttonBackground)
g.DrawImage(pbx.Image, _
New Rectangle(0, _
0, _
buttonBackground.Width, _
buttonBackground.Height), _
btn1.Bounds, _
GraphicsUnit.Pixel)
End Using
btn1.BackgroundImage = buttonBackground
End Sub
Private Sub EmbedButtonInPictureBox2(ByVal btn2 As Button, ByVal picbx As PictureBox)
Dim buttonLocation As Point = picbx.PointToClient(Me.PointToScreen(btn2.Location))
btn2.Parent = picbx
btn2.Location = buttonLocation
Dim buttonBackground2 As New Bitmap(btn2.Width, btn2.Height)
Using g As Graphics = Graphics.FromImage(buttonBackground2)
g.DrawImage(picbx.Image, _
New Rectangle(0, _
0, _
buttonBackground2.Width, _
buttonBackground2.Height), _
btn2.Bounds, _
GraphicsUnit.Pixel)
End Using
btn2.BackgroundImage = buttonBackground2
End Sub
Private Sub EmbedButtonInPictureBox3(ByVal btn As Button, ByVal pbx As PictureBox)
Dim buttonLocation2 As Point = pbx.PointToClient(Me.PointToScreen(btn.Location))
btn.Parent = pbx
btn.Location = buttonLocation2
Dim buttonBackground As New Bitmap(btn.Width, btn.Height)
Using g As Graphics = Graphics.FromImage(buttonBackground)
g.DrawImage(pbx.Image, _
New Rectangle(0, _
0, _
buttonBackground.Width, _
buttonBackground.Height), _
btn.Bounds, _
GraphicsUnit.Pixel)
End Using
btn.BackgroundImage = buttonBackground
End Sub