[Windows Mobile]使用 AlphaMobileControls 實現透明控制項
2009-11-04 17:26
746 查看
1. 簡介
在 Windows Form Application 中,想要讓控制項透明,只要設定一些簡單的屬性 ( 例如 BackColor = Color.Transparent ) 即可,但在智慧型裝置專案中,就不是簡單的事情,使用 AlphaBlend API
是最常見的作法,而本文介紹使用 AlphaMobileControls 控制項來達成。
2. 方法
2.1 下載與使用
到 此處
下載 AlphaMobileControls
新增智慧型裝置專案,並且加入現有專案,把 AlphaMobileControls 專案
將 AlphaMobileControls 編譯後,在工具箱中就會看到 AlphaMobileControls 元件,接著只要把元件拖曳到 Form 上就可以使用了
不過由於程式碼中,會用到 AlphaImage 類別,因此將 AlphaMobileControls.dll 加入參考中
並於程式碼中 using
view plain
copy to clipboard
print
?
using
AlphaMobileControls;
2.2 加入圖檔
將背景透明的圖檔加入專案內,並且在屬性裡,設定為嵌入資源
2.3 程式撰寫
表單配置如下圖所示,由上往下為 三個為 AlphaImageButton,三個 PictureBox,一個 AlphaImageButton,一個 AlphaLabel
以下程式碼功能為 三個為 AlphaImageButton,三個 PictureBox 顯示相同的圖檔,而最底下的 AlphaImageButton 點選後,AlphaLabel 顯示 Button Clicked!
view plain
copy to clipboard
print
?
using
System;
using
System.Linq;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
AlphaMobileControls;
namespace
SmartDeviceProject1
{
public
partial
class
Form1 : AlphaForm
// 將 Form1 繼承 AlphaForm
{
public
Form1()
{
InitializeComponent();
// 表單中最上面三個 alphaImageButton 載入圖檔
alphaImageButton2.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.1.png"
);
alphaImageButton3.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.2.png"
);
alphaImageButton4.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.3.png"
);
alphaLabel1.Text = "Alpha Mobile Controls"
;
// 表單最底下 alphaImageButton 載入圖檔
alphaImageButton1.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1.png"
);
alphaImageButton1.ActiveBackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1_Pushed.png"
);
alphaImageButton1.DisabledBackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1_Disabled.png"
);
}
// 當 alphaImageButton1 Click 時
private
void
alphaImageButton1_Click(
object
sender, EventArgs e)
{
alphaLabel1.Text = "Button Clicked!"
;
// alphaLabel1 顯示 Button Clicked!
}
}
}
執行結果
最上面三個 AlphaImageButton,圖檔透明的部份顯示透明,但三個 PictureBox 則顯示白色。下方AlphaImageButton 點選後,AlphaLabel 顯示 Button Clicked!
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和按鈕透明
在 Windows Form Application 中,想要讓控制項透明,只要設定一些簡單的屬性 ( 例如 BackColor = Color.Transparent ) 即可,但在智慧型裝置專案中,就不是簡單的事情,使用 AlphaBlend API
是最常見的作法,而本文介紹使用 AlphaMobileControls 控制項來達成。
2. 方法
2.1 下載與使用
到 此處
下載 AlphaMobileControls
新增智慧型裝置專案,並且加入現有專案,把 AlphaMobileControls 專案
將 AlphaMobileControls 編譯後,在工具箱中就會看到 AlphaMobileControls 元件,接著只要把元件拖曳到 Form 上就可以使用了
不過由於程式碼中,會用到 AlphaImage 類別,因此將 AlphaMobileControls.dll 加入參考中
並於程式碼中 using
view plain
copy to clipboard
?
using
AlphaMobileControls;
using AlphaMobileControls;
2.2 加入圖檔
將背景透明的圖檔加入專案內,並且在屬性裡,設定為嵌入資源
2.3 程式撰寫
表單配置如下圖所示,由上往下為 三個為 AlphaImageButton,三個 PictureBox,一個 AlphaImageButton,一個 AlphaLabel
以下程式碼功能為 三個為 AlphaImageButton,三個 PictureBox 顯示相同的圖檔,而最底下的 AlphaImageButton 點選後,AlphaLabel 顯示 Button Clicked!
view plain
copy to clipboard
?
using
System;
using
System.Linq;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
AlphaMobileControls;
namespace
SmartDeviceProject1
{
public
partial
class
Form1 : AlphaForm
// 將 Form1 繼承 AlphaForm
{
public
Form1()
{
InitializeComponent();
// 表單中最上面三個 alphaImageButton 載入圖檔
alphaImageButton2.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.1.png"
);
alphaImageButton3.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.2.png"
);
alphaImageButton4.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.3.png"
);
alphaLabel1.Text = "Alpha Mobile Controls"
;
// 表單最底下 alphaImageButton 載入圖檔
alphaImageButton1.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1.png"
);
alphaImageButton1.ActiveBackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1_Pushed.png"
);
alphaImageButton1.DisabledBackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1_Disabled.png"
);
}
// 當 alphaImageButton1 Click 時
private
void
alphaImageButton1_Click(
object
sender, EventArgs e)
{
alphaLabel1.Text = "Button Clicked!"
;
// alphaLabel1 顯示 Button Clicked!
}
}
}
using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using AlphaMobileControls; namespace SmartDeviceProject1 { public partial class Form1 : AlphaForm // 將 Form1 繼承 AlphaForm { public Form1() { InitializeComponent(); // 表單中最上面三個 alphaImageButton 載入圖檔 alphaImageButton2.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.1.png"); alphaImageButton3.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.2.png"); alphaImageButton4.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.3.png"); alphaLabel1.Text = "Alpha Mobile Controls"; // 表單最底下 alphaImageButton 載入圖檔 alphaImageButton1.BackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1.png"); alphaImageButton1.ActiveBackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1_Pushed.png"); alphaImageButton1.DisabledBackgroundImage = AlphaImage.CreateFromResource("SmartDeviceProject1.Resources.Btn1_Disabled.png"); } // 當 alphaImageButton1 Click 時 private void alphaImageButton1_Click(object sender, EventArgs e) { alphaLabel1.Text = "Button Clicked!"; // alphaLabel1 顯示 Button Clicked! } } }
執行結果
最上面三個 AlphaImageButton,圖檔透明的部份顯示透明,但三個 PictureBox 則顯示白色。下方AlphaImageButton 點選後,AlphaLabel 顯示 Button Clicked!
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和按鈕透明
相关文章推荐
- [Windows Mobile]使用 AlphaMobileControls 實現透明控制項
- [Windows Mobile]使用 AlphaMobileControls 實現透明控制項
- AlphaMobileControls 控件的使用 AlphaImageButton
- AlphaMobileControls 控件的使用 AlphaImageButton
- AlphaControls 控件的使用
- 3.取色精灵V2.0-非模态对话框自建消息队列、VS2008风格对话框、使用Common Controls、悬浮透明窗口、使用SLIDER控件
- 自定义RGB位图使用Alpha通道处理透明效果
- 使用Windows Mobile Test Framework进行Windows Mobile程序的自动化测试 - (1)微软Windows Mobile Test Framework简介
- 在Windows Mobile 5中使用DirectShow控制摄像头
- Unity3D ShaderLab 使用alpha参数创建透明效果
- 使用 jQuery Mobile API 实现细粒度的自定义控制
- Windows Mobile下使用HTML控件 Mobile
- Asp.net 使用GDI+实现alpha透明效果
- windows mobile开发循序渐进(6)windows mobile device center 使用问题
- 使用squid配置透明代理并对上网行为进行控制
- 在Windows Mobile 5中使用DirectShow控制摄像头-转
- 使用Windows Mobile Test Framework进行Windows Mobile程序的自动化测试 - (2) 小试牛刀
- 在Windows Mobile 5中使用DirectShow控制摄像头
- Delphi 皮肤控件AlphaControls的使用
- 使用Windows Mobile Test Framework进行Windows Mobile程序的自动化测试 - (2) 小试牛刀