# 大家帮忙看一看这是不是 VB6 的 bug

Posted by Sephiroth on May 26, 1999 at 17:06:00:

近来在写作 AX Control 时发现一个问题:

假设 UserControl.Name = MyCtrl, 它有一个 PropertyPage.Name = MyPage
在 UserControl 上设定两个属性存放图片:

1. PicCtrl As StdPicture:
只能从 MyCtrl 的 properties window 设定图片
2. PicPage As StdPicture:
只能从属性页 MyPage 设定图片 (将 Don't show in property
browser 打勾)

MyCtrl 的程式如下:(前面的宣告我就省略了...)

Public Property Get PicCtrl() As StdPicture
Set PicCtrl = mobjPicCtrl
End Property

Public Property Set PicCtrl(vData As StdPicture)
Set mobjPicCtrl = vData
PropertyChanged "PicCtrl"
PaintPicture mobjPicCtrl, 0, 0
End Property

Public Property Get PicPage() As StdPicture
Set PicPage = mobjPicPage
End Property

Public Property Set PicPage(vData As StdPicture)
Set mobjPicPage = vData
PropertyChanged "PicPage"
PaintPicture mobjPicPage, 0, 100
End Property

Private Sub UserControl_Paint()
PaintPicture mobjPicCtrl, 0, 0
PaintPicture mobjPicPage, 0, 100
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropertyBag
Set mobjPicCtrl = .ReadProperty("PicCtrl")
Set mobjPicPage = .ReadProperty("PicPage")
End With
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropertyBag
.WriteProperty "PicCtrl", mobjPicCtrl
.WriteProperty "PicPage", mobjPicPage
End With
End Sub

MyPage 的程式如下:(不重要的地方我也省略了)
在 MyPage 上面放一个 PictureBox.Name = pic,
一个 Common Dialog.Name = cdl
在 pic 的 MouseDown 写以下程式:

Private Sub pic_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Select Case Button
Case vbLeftButton
With cdl
.Filter = "*.gif;*.bmp;*.dib;*.jpg;*.wmf;*.emf;*.ico;*.cur|*.gif;*.bmp;*.dib;*.jpg;*.wmf;*.emf;*.ico;*.cur"
.ShowOpen
If Err.Number Then
Err.Clear
Else
Set pic.Picture = LoadPicture(cdl.FileName)
Set SelectedControls(0).PicPage = pic.Picture
End If
End With
Case vbRightButton
Set pic(Index).Picture = Nothing
End Select
End Sub

Private Sub PropertyPage_SelectionChanged()
Set pic.Picture = SelectedControls(0).PicPage
End Sub

这程式只有在一种状况下会出错, 如果 PicPage 的图片是 icon 而且是
16 色以上的 icon, 那么在设定完成之后, 关闭 Form 再打开, 无论如何
PicPage 都会变成只有 16 色的 icon; 反之, 如果我是设定 PicCtrl
是一个 24 bit色的 icon 呢? 读取之后, 并不会发生颜色错乱的问题.
至于其它格式的图档(jpeg/pcx/gif/bmp)则不会发生问题, 其它格式则没
试过. 不知这是 VB6 的 bug 或是程式的问题?

Follow Ups:

- 不对! 不对! 应该还有问题存在 Sephiroth 17:37:35 5/26/99 (0)
- 发现问题所在 Sephiroth 17:27:36 5/26/99 (0)