开发者

I've increased the size of image in picture box but now I want to take it back to its original size

I am working with vb.net and want to increase the size of image when the cursor 开发者_StackOverflowis over that image, but the image should come back to its original size when the cursor leaves that image area.

I've used the following code to increase the size of image:

Private Sub PictureBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
    PictureBox1.Size = New Size(300, 250)
End Sub

I've used the default size class but, it gives some different dimensions.

Please guide me by the code that brings the image into its original size that I've been declared into the picture box properties.


You should probably be hooking in to the MouseEnter and MouseLeave events. Links for MSDN reference


Here's the code that will resize the PictureBox to the dimensions of the image:

PictureBox1.Size = PictureBox1.Image.Size

Assuming that the original size of the PictureBox was the image size, then that'll work just fine.

As kaveman suggested, MouseEnter and MouseLeave would be much better events to put the code in ;-)

In order to restore the custom size you've set it to, you'll need some code like this: (make sure its somewhere which won't go out of scope, like in the form, outside of methods)

You'll need a variable to store the original size:

Dim OriginalSize as Size

Then, before changing the size when the user moves the mouse over the image, store the size in the variable: (put this in the MouseEnter event)

OriginalSize = PictureBox1.Size
PictureBox1.Size = New Size(300, 250)

Restoring that size is a simple matter of putting that variable back into the picturebox size: (this goes in the MouseLeave event)

PictureBox1.Size = OriginalSize

=)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜