在偏移处重画Picturebox并返回以模拟为按钮效果

时间:2018-10-20 19:54:57

标签: vb.net winforms picturebox tablelayoutpanel

我有一些文档和书籍封面的图像,这些图像是通过“表格”布局面板中的图片框显示的。

Image excerpt from winform app

我正在遵循此代码 (摘自:https://social.msdn.microsoft.com/Forums/vstudio/en-US/da545e8e-e059-4681-9893-6d5dbdf6eba6/drop-shadow-around-the-image-in-picturebox?forum=vbgeneral)  在单击并打开所需的书或文档时,使Picturebox像按钮一样工作。

Public Enum ShadowPosition As Integer
        TopLeft = 0
        TopRight = 1
        BottomLeft = 2
        BottomRight = 3
    End Enum

    Private Sub AddImageWithShadow(ByVal img As System.Drawing.Image, ByVal area As ShadowPosition, ByVal thickness As Integer, ByVal clr As Color, ByVal PicBox As PictureBox)
        Using bm As New Bitmap(img.Width + thickness, img.Height + thickness)
            Using gr As Graphics = Graphics.FromImage(bm)
                Dim ix, iy As Integer
                Dim rect As New Rectangle(thickness, thickness, img.Width, img.Height)
                If area = ShadowPosition.TopLeft Or area = ShadowPosition.TopRight Then
                    iy = thickness
                    rect.Y = 0
                End If
                If area = ShadowPosition.TopLeft Or area = ShadowPosition.BottomLeft Then
                    ix = thickness
                    rect.X = 0
                End If
                gr.FillRectangle(New SolidBrush(clr), rect)
                gr.DrawImage(img, ix, iy)
            End Using
            If PicBox.Image IsNot Nothing Then PicBox.Image.Dispose()
            PicBox.Image = New Bitmap(bm)
        End Using
    End Sub

我试图更改图像的位置: Picturebox1.Location =新点(10,10)

有人可以猜测在不偏移阴影的情况下重新偏移图片框的位置并返回初始状态的方法。

0 个答案:

没有答案