zoukankan      html  css  js  c++  java
  • [Windows Mobile]使用 AlphaMobileControls 實現透明控制項

     

    1. 簡介

    在 Windows Form Application 中,想要讓控制項透明,只要設定一些簡單的屬性 ( 例如 BackColor = Color.Transparent ) 即可,但在智慧型裝置專案中,就不是簡單的事情,使用 AlphaBlend API 是最常見的作法,而本文介紹使用 AlphaMobileControls 控制項來達成。

    2. 方法

    2.1 下載與使用

    此處 下載 AlphaMobileControls

    image

    新增智慧型裝置專案,並且加入現有專案,把 AlphaMobileControls 專案

    image image image

    將 AlphaMobileControls 編譯後,在工具箱中就會看到 AlphaMobileControls 元件,接著只要把元件拖曳到 Form 上就可以使用了

    image image

    不過由於程式碼中,會用到 AlphaImage 類別,因此將 AlphaMobileControls.dll 加入參考中

    image image

    並於程式碼中 using

    1. using  AlphaMobileControls;  

    2.2 加入圖檔

    將背景透明的圖檔加入專案內,並且在屬性裡,設定為嵌入資源

    image

    2.3 程式撰寫

    表單配置如下圖所示,由上往下為 三個為 AlphaImageButton,三個 PictureBox,一個 AlphaImageButton,一個 AlphaLabel

     image

    以下程式碼功能為 三個為 AlphaImageButton,三個 PictureBox 顯示相同的圖檔,而最底下的 AlphaImageButton 點選後,AlphaLabel 顯示 Button Clicked!

    1. using  System;  
    2. using  System.Linq;  
    3. using  System.Collections.Generic;  
    4. using  System.ComponentModel;  
    5. using  System.Data;  
    6. using  System.Drawing;  
    7. using  System.Text;  
    8. using  System.Windows.Forms;  
    9.   
    10. using  AlphaMobileControls;  
    11.   
    12. namespace  SmartDeviceProject1  
    13. {  
    14.     public  partial  class  Form1 : AlphaForm   // 將 Form1 繼承 AlphaForm   
    15.     {  
    16.         public  Form1()  
    17.         {  
    18.             InitializeComponent();  
    19.             // 表單中最上面三個 alphaImageButton 載入圖檔   
    20.             alphaImageButton2.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.1.png" );  
    21.             alphaImageButton3.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.2.png" );  
    22.             alphaImageButton4.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.3.png" );  
    23.   
    24.             alphaLabel1.Text = "Alpha Mobile Controls" ;  
    25.             // 表單最底下 alphaImageButton 載入圖檔   
    26.             alphaImageButton1.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1.png" );  
    27.             alphaImageButton1.ActiveBackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1_Pushed.png" );  
    28.             alphaImageButton1.DisabledBackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1_Disabled.png" );  
    29.         }  
    30.   
    31.         // 當 alphaImageButton1 Click 時   
    32.         private   void  alphaImageButton1_Click( object  sender, EventArgs e)  
    33.         {  
    34.             alphaLabel1.Text = "Button Clicked!" ;   // alphaLabel1 顯示 Button Clicked!   
    35.         }  
    36.     }  
    37. }  

    執行結果

    最上面三個 AlphaImageButton,圖檔透明的部份顯示透明,但三個 PictureBox 則顯示白色。下方AlphaImageButton 點選後,AlphaLabel 顯示 Button Clicked!

    image image

    3. 結語

    本文提供 AlphaMobileControls 實現透明控制項,而實際上常見的使用方式為 AlphaBlend 與 Imaging API,以下提供一些網址,讓對透明控制項興趣的可以參考

    Imaging Structures

    AlphaBlend

    Alphablending with NETCF

    Transparent label in compact framework

    UI Framework for .NET Compact Framework 3.5

    iPhone UI

    4. 參考

    Windows Mobile实现透明控件

    C#實現label和按鈕透明

  • 相关阅读:
    OCP-1Z0-052-V8.02-116题
    OCP-1Z0-052-V8.02-6题
    OCP-1Z0-052-V8.02-5题
    使用rman恢复控制文件
    Matlab-质点的运动
    Matlab中checkerboard-创建棋盘图像(二)
    OCP-1Z0-052-V8.02-4题
    OCP-1Z0-052-V8.02-3题
    Matlab中checkerboard-创建棋盘图像(一)
    OCP-1Z0-052-V8.02-1题
  • 原文地址:https://www.cnblogs.com/xyzlmn/p/3168451.html
Copyright © 2011-2022 走看看