VB :: Code & APIs

[VB.NET] PictureBox 를 서서히 표시하거나 서서히 사라지게 하는 방법

일단 모듈이나 폼에 아래 프로시저를 선언합니다.


Private Sub Back_SlowHide(ByVal tObj As PictureBox, ByVal Images As Image, ByVal Opacity As Single)
        Dim Img As Image = Images
        tObj.Image = New Bitmap(Img.Width, Img.Height)
        tObj.BackColor = Color.Transparent
        Dim IA As New Imaging.ImageAttributes
        Dim CM As New Imaging.ColorMatrix

        CM.Matrix00 = 1 : CM.Matrix11 = 1 : CM.Matrix22 = 1 : CM.Matrix33 = Opacity : CM.Matrix44 = 1       

        With tObj
            Using G As Graphics = Graphics.FromImage(tObj.Image)
                G.DrawImage(Img, New Rectangle(0, 0, .Image.Width, .Image.Height), 0, 0, .Image.Width, .Image.Height, GraphicsUnit.Pixel, IA)
            End Using
        End With
    End Sub


다음 적용이 필요한 폼에서 다음과 같이 사용합니다.


'서서히 표시되게 하기

        Dim tmpP As PictureBox
        Dim i As Single

        Dim Images As Image = My.Resources.darknight

        tmpP = New PictureBox

        With tmpP
            .Size = New Size(Images.Width, Images.Height)
            .Location = New Point((Me.ClientSize.Width - .Width) / 2, (Me.ClientSize.Height - .Height) / 2)
            .Visible = True
        End With
        For i = 0 To 1 Step 0.01
            Call Back_SlowHide(tmpP, Images, i)


이렇게 사용하시면 되겠습니다.

서서히 사라지게 하는 방법은 코드에서 For 문 부분만 변경하시면 되니, 나름대로 응용해보세요!

좋은 하루 보내세요!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: