如何使用 vb.net 在 windows 窗体上旋转图片框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/544636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:03:36  来源:igfitidea点击:

How to rotate a PictureBox on a windows form using vb.net

vb.net

提问by user39035

I need to rotate a picture box 180 degrees when a condition in my if statement is met. Is this possible?

当满足 if 语句中的条件时,我需要将图片框旋转 180 度。这可能吗?

回答by Thomas

I'll assume that you want to rotate the image inside, because rotating the box itself doesn't make much sense (and is impossible anyway).

我假设你想旋转里面的图像,因为旋转盒子本身没有多大意义(无论如何都是不可能的)。

Try this:

尝试这个:

myPictureBox.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);

回答by Ash

The System.Drawing.Image.RotateFlip() method allows you to rotate the actual image displayed in the picturebox. See this page

System.Drawing.Image.RotateFlip() 方法允许您旋转图片框中显示的实际图像。看这个页面

Dim bitmap1 As Bitmap

Private Sub InitializeBitmap()
    Try
        bitmap1 = CType(Bitmap.FromFile("C:\Documents and Settings\All Users\" _
            & "Documents\My Music\music.bmp"), Bitmap)
        PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
        PictureBox1.Image = bitmap1
    Catch ex As System.IO.FileNotFoundException
        MessageBox.Show("There was an error. Check the path to the bitmap.")
    End Try


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    If bitmap1 IsNot Nothing Then
   bitmap1.RotateFlip(RotateFlipType.Rotate180FlipY)
        PictureBox1.Image = bitmap1
    End If

End Sub

回答by Mustaf Mohammeed

PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone)
PictureBox1.Refresh()

When you try to rotate your image with:

当您尝试使用以下方法旋转图像时:

PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone)

nothing will happen until you close the form and open it again (not the project, just the form). If you want to rotate at once then you should use PictureBox1.Refresh().

在您关闭表单并再次打开它(不是项目,只是表单)之前,什么都不会发生。如果你想一次旋转,那么你应该使用PictureBox1.Refresh().