如何使用ComboBox调整PictureBox和图片的大小?

时间:2016-05-25 13:42:36

标签: vb.net combobox visual-studio-2015 picturebox

现在我想要做的是选择你想要的尺寸,图片会改变。我做了一个例子,但它不会工作。

这是我的代码

Private Sub cboxpizzasize_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboxpizzasize.SelectedIndexChanged

    Select Case cboxselectclass.SelectedItem
        Case Is = "Personal - 4 slide"
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Size = New Size(134, 150)
        Case Is = "Regular - 6 slide"
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Size = New Size(174.2, 196.95)
        Case Is = "Large - 8 slide"
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Size = New Size(214.4, 242.4)
        Case Is = "Xtra Large - 12 slide"
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Size = New Size(268, 303)
    End Select

End Sub

2 个答案:

答案 0 :(得分:0)

您是否尝试过以下方法: resizing

更改SizeMode

或者您是否阅读了以下文章:article

  

只有在加载图像之前,才可以重新调整图片框的大小   它是只读的,没有效果!

答案 1 :(得分:0)

在设计器中将SizeMode设置为StretchImage,然后使用以下代码:

Private Sub cboxpizzasize_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboxpizzasize.SelectedIndexChanged
    Select Case cboxpizzasize.SelectedIndex
        Case Is = 0
            PictureBox1.Size = New Size(134, 150)
        Case Is = 1
            PictureBox1.Size = New Size(174.2, 196.95)
        Case Is = 2
            PictureBox1.Size = New Size(214.4, 242.4)
        Case Is = 3
            PictureBox1.Size = New Size(268, 303)
    End Select
End Sub

(ComboBox名为cboxpizzasize,PictureBox为PictureBox1)