PictureSizeMode 屬性範例
下列範例會使用 PictureSizeMode 屬性來示範圖片的三個顯示選項:依原樣顯示圖片、變更圖片大小,同時維持其原始比例,以及縮放圖片以填滿空間。
若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定該表單包含:
- 名為 Frame1 的 Frame 。
- 一個名為 SpinButton1 的 SpinButton 。
- 一個名為 TextBox1 的 TextBox 。
- 三個分別名為 OptionButton1 到 OptionButton3 的 OptionButton 控制項。
注意事項
此範例是 PictureAlignment 屬性範例的增強版本,因為兩個屬性彼此互補。 增強功能是三個 OptionButton 事件副程式,可控制是否裁剪、縮放或延展影像。
Dim Alignments(5) As String
Private Sub UserForm_Initialize()
Alignments(0) = "0 - Top Left"
Alignments(1) = "1 - Top Right"
Alignments(2) = "2 - Center"
Alignments(3) = "3 - Bottom Left"
Alignments(4) = "4 - Bottom Right"
'Specify a bitmap that exists on your system
Frame1.Picture = LoadPicture("c:\winnt2\ball.bmp")
SpinButton1.Min = 0
SpinButton1.Max = 4
SpinButton1.Value = 0
TextBox1.Text = Alignments(0)
Frame1.PictureAlignment = SpinButton1.Value
OptionButton1.Caption = "Crop"
OptionButton1.Value = True
OptionButton2.Caption = "Stretch"
OptionButton3.Caption = "Zoom"
End Sub
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
Frame1.PictureSizeMode = fmPictureSizeModeClip
End If
End Sub
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
Frame1.PictureSizeMode = fmPictureSizeModeStretch
End If
End Sub
Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
Frame1.PictureSizeMode = fmPictureSizeModeZoom
End If
End Sub
Private Sub SpinButton1_Change()
TextBox1.Text = Alignments(SpinButton1.Value)
Frame1.PictureAlignment = SpinButton1.Value
End Sub
Private Sub TextBox1_Change()
Select Case TextBox1.Text
Case "0"
TextBox1.Text = Alignments(0)
Frame1.PictureAlignment = 0
Case "1"
TextBox1.Text = Alignments(1)
Frame1.PictureAlignment = 1
Case "2"
TextBox1.Text = Alignments(2)
Frame1.PictureAlignment = 2
Case "3"
TextBox1.Text = Alignments(3)
Frame1.PictureAlignment = 3
Case "4"
TextBox1.Text = Alignments(4)
Frame1.PictureAlignment = 4
Case Else
TextBox1.Text = Alignments(SpinButton1.Value)
Frame1.PictureAlignment = SpinButton1.Value
End Select
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。