小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

如何:定義工具欄按鈕的圖標

 嘿嘿天亮了 2012-06-14

如何:定義工具欄按鈕的圖標


Note注意

ToolStrip 控件替換了 ToolBar 控件并添加了功能;但是也可選擇保留 ToolBar 控件以備向后兼容和將來使用。

ToolBar 按鈕能夠在其中顯示圖標,以便于用戶標識。具體的實現(xiàn)方法是,向 ImageList 組件(Windows 窗體)組件添加圖像,然后將 ImageList 組件與 ToolBar 控件關聯(lián)起來。

以編程方式設置工具欄按鈕的圖標

  1. 在過程中,實例化 ImageList 組件和 ToolBar 控件。

  2. 在同一過程中,向 ImageList 組件分配一個圖像。

  3. 在同一過程中,向 ToolBar 控件分配 ImageList 控件,然后分配各個工具欄按鈕的 ImageIndex 屬性。

    在下面的代碼示例中,圖標位置的路徑設置是“My Documents”文件夾。這樣做是因為可假定大多數(shù)運行 Windows 操作系統(tǒng)的計算機都包含此目錄。這還將允許具有最低系統(tǒng)訪問級別的用戶安全地運行應用程序。下面的示例假定一個已添加了 PictureBox 控件的窗體。

    按照上述步驟,您應該已經(jīng)編寫出類似于下面顯示的代碼。

    Public Sub InitializeMyToolBar()
    ' Instantiate an ImageList component and a ToolBar control.
       Dim ToolBar1 as New ToolBar
       Dim ImageList1 as New ImageList
    ' Assign an image to the ImageList component.
    ' You should replace the bold image
    ' in the sample below with an icon of your own choosing.
       Dim myImage As System.Drawing.Image = _ 
          Image.FromFile Image.FromFile _
          (System.Environment.GetFolderPath _
          (System.Environment.SpecialFolder.Personal) _
          & "\Image.gif")
       ImageList1.Images.Add(myImage)
    ' Create a ToolBarButton.
       Dim ToolBarButton1 As New ToolBarButton()
    ' Add the ToolBarButton to the ToolBar.
       ToolBar1.Buttons.Add(toolBarButton1)
    ' Assign an ImageList to the ToolBar.
       ToolBar1.ImageList = ImageList1
    ' Assign the ImageIndex property of the ToolBarButton.
       ToolBarButton1.ImageIndex = 0
    End Sub
    
    

    public void InitializeMyToolBar()
    {
       // Instantiate an ImageList component and a ToolBar control.
       ToolBar toolBar1 = new  ToolBar(); 
       ImageList imageList1 = new ImageList();
       // Assign an image to the ImageList component.
       // You should replace the bold image 
       // in the sample below with an icon of your own choosing.
       // Note the escape character used (@) when specifying the path.
       Image myImage = Image.FromFile
       (System.Environment.GetFolderPath
       (System.Environment.SpecialFolder.Personal)
       + @"\Image.gif");
       imageList1.Images.Add(myImage);
       // Create a ToolBarButton.
       ToolBarButton toolBarButton1 = new ToolBarButton();
       // Add the ToolBarButton to the ToolBar.
       toolBar1.Buttons.Add(toolBarButton1);
       // Assign an ImageList to the ToolBar.
       toolBar1.ImageList = imageList1;
       // Assign ImageIndex property of the ToolBarButton.
       toolBarButton1.ImageIndex = 0;
    }
    
    

    public:
       void InitializeMyToolBar()
       {
          // Instantiate an ImageList component and a ToolBar control.
          ToolBar ^ toolBar1 = gcnew  ToolBar(); 
          ImageList ^ imageList1 = gcnew ImageList();
          // Assign an image to the ImageList component.
          // You should replace the bold image 
          // in the sample below with an icon of your own choosing.
          Image ^ myImage = Image::FromFile(String::Concat
             (System::Environment::GetFolderPath
             (System::Environment::SpecialFolder::Personal),
             "\\Image.gif"));
          imageList1->Images->Add(myImage);
          // Create a ToolBarButton.
          ToolBarButton ^ toolBarButton1 = gcnew ToolBarButton();
          // Add the ToolBarButton to the ToolBar.
          toolBar1->Buttons->Add(toolBarButton1);
          // Assign an ImageList to the ToolBar.
          toolBar1->ImageList = imageList1;
          // Assign ImageIndex property of the ToolBarButton.
          toolBarButton1->ImageIndex = 0;
       }
    

請參見

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多