共用方式為


HOW TO:在升級應用程式中模擬 Visual Basic 6.0 三種狀態的控制項

更新:2007 年 11 月

在 Visual Basic 6.0 中,Picture、DownPicture 和 DisabledPicture 屬性 (Property) 可根據 CheckBox、CommandButton 或 OptionButton 控制項的狀態,用於顯示不同的圖片。例如,核取 CheckBox 控制項時會顯示 DownPicture 影像,如果停用控制項,則會顯示 DisabledPicture 影像。

在 Visual Basic 2008 中,使用 ImageList 控制項得到的效果會與下列範例概述的相同。

注意事項:

首先,檢查您的 Visual Basic 6.0 應用程式。如果 DownPicture 和 DisabledPicture 屬性在設計階段或執行階段並未設定,則其行為在 Visual Basic 2008 中應該相同。

注意事項:

根據目前使用的設定與版本,您所看到的對話方塊與功能表命令可能會與 [說明] 中所描述的不同。若要變更設定,請從 [工具] 功能表中選擇 [匯入和匯出設定]。如需詳細資訊,請參閱 Visual Studio 設定

加入 ImageList 控制項

如果已設定 DownPicture 或 DisabledPicture 屬性,請使用下列步驟修改升級的應用程式。

若要模擬三種狀態的控制項

  1. 針對指派至 Picture、DownPicture 和 DisabledPicture 屬性的影像,判斷其檔案名稱和位置,必要時可將其複製到您的開發電腦上。

  2. 從 [工具箱] 將 ImageList 控制項加入至表單。

  3. 在 [屬性] 視窗中選取 Images 屬性。

  4. 在 [影像集合編輯器] 中,加入三個影像以用於 Picture、用於 DownPicture,然後用於 DisabledPicture。

  5. 如果有任何屬性 (Property) 於執行階段進行設定,請移除程式碼。如果於設計階段設定了屬性,請將下列程式碼加入至表單的 Load 事件:

    ' Assign the first image (Picture) to the Image property.
    CheckBox1.Image = ImageList1.Images(0)
    
  6. 若要於執行階段顯示 DownPicture 影像,請將下列程式碼加入至 CheckBox 控制項的 CheckedChanged 事件。

    If CheckBox1.Checked = True Then
      ' Assign the second image (DownPicture) to the Image property.
      CheckBox1.Image = ImageList1.Images(1)
    Else
      ' Assign the first image (Picture) to the Image property.
      CheckBox1.Image = ImageList1.Images(0)
    End If
    
  7. 若要於執行階段顯示 DisabledPicture 影像,請將下列程式碼加入至 CheckBox 控制項的 EnabledChanged 事件。

    If CheckBox1.Enabled = False Then
      ' Assign the third image (DisabledPicture) to the Image property.
      CheckBox1.Image = ImageList1.Images(2)
    ElseIf CheckBox1.Checked = True Then
      ' Assign the second image (DownPicture) to the Image property
      CheckBox1.Image = ImageList1.Images(1)
    Else
      ' Assign the first image (Picture)to the Image property
      CheckBox1.Image = ImageList1.Images(0)
    End If
    

    應用程式現在應該和 Visual Basic 6.0 中的運作完全相同。

請參閱

概念

Visual Basic 6.0 使用者可用的樣式屬性

Visual Basic 6.0 使用者可用的 CheckBox 控制項

Visual Basic 6.0 使用者可用的 CommandButton 控制項

Visual Basic 6.0 使用者可用的 OptionButton 控制項

Visual Basic 6.0 使用者可用的 OptionButton 控制項

Visual Basic 6.0 使用者可用的使用者控制項