PictureSizeMode 属性示例

下例用 PictureSizeMode 属性来演示图片的三种显示选项:原样显示图片、改变图片尺寸但保持其原有比例、以及让图片填满整个空间。

窗体包含:

  • 名为 Frame1 的框架。
  • 名为 SpinButton1 的数值调节钮。
  • 名为 TextBox1 的文本框。
  • 名为 OptionButton1 到 OptionButton3 的三个选项按钮控件。

注意 该示例是 PictureAlignment 属性示例的增强版,两个属性相互补充。所增强的是三个选项按钮事件的子程序,它们控制图像是否被修剪、放大或伸展。

Dim Alignments(5)

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"
        
    '指定存在于系统上的位图
    UserForm_Frame1.Picture = LoadPicture(".\AddinSkin\Icons\winstock.ICO")
    
    UserForm_SpinButton1.Min = 0
    UserForm_SpinButton1.Max = 4
    UserForm_SpinButton1.Value = 0
    
    UserForm_TextBox1.Text = Alignments(0)
    UserForm_Frame1.PictureAlignment = UserForm_SpinButton1.Value
    
    UserForm_OptionButton1.Caption = "Crop"
    UserForm_OptionButton1.Value = True
    UserForm_OptionButton2.Caption = "Stretch"
    UserForm_OptionButton3.Caption = "Zoom"
End Sub

Sub UserForm_OptionButton1_Click()
    If UserForm_OptionButton1.Value = True Then
        UserForm_Frame1.PictureSizeMode = 0
    End If
End Sub

Sub UserForm_OptionButton2_Click()
    If UserForm_OptionButton2.Value = True Then
        UserForm_Frame1.PictureSizeMode = 1
    End If
End Sub

Sub UserForm_OptionButton3_Click()
    If UserForm_OptionButton3.Value = True Then
        UserForm_Frame1.PictureSizeMode = 3
    End If
End Sub

Sub UserForm_SpinButton1_Change()
    UserForm_TextBox1.Text = Alignments( UserForm_SpinButton1.Value)
    UserForm_Frame1.PictureAlignment =  UserForm_SpinButton1.Value
End Sub

Sub UserForm_TextBox1_Change()
    Select Case UserForm_TextBox1.Text
    Case "0"
        UserForm_TextBox1.Text = Alignments(0)
        UserForm_Frame1.PictureAlignment = 0
    Case "1"
        UserForm_TextBox1.Text = Alignments(1)
        UserForm_Frame1.PictureAlignment = 1
    Case "2"
        UserForm_TextBox1.Text = Alignments(2)
        UserForm_Frame1.PictureAlignment = 2
    Case "3"
        UserForm_TextBox1.Text = Alignments(3)
        UserForm_Frame1.PictureAlignment = 3
    Case "4"
        UserForm_TextBox1.Text = Alignments(4)
        UserForm_Frame1.PictureAlignment = 4
    Case Else
        UserForm_TextBox1.Text = Alignments( UserForm_SpinButton1.Value)
        UserForm_Frame1.PictureAlignment = UserForm_SpinButton1.Value
    End Select
End Sub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70