iT邦幫忙

DAY 27
2

Windows Mobile系列 第 27

[Windows Mobile]在表單中顯示背景圖片

在智慧型裝置專案的表單中,顯示背景圖片
更多文章,請到我在點部落所建立的部落格「.NET菜鳥自救會」閱讀
http://www.dotblogs.com.tw/chou/

  1. 簡介
    在智慧型裝置專案的表單中,顯示背景圖片

  2. 方法
    在 Windows Forms 應用程式中,Form 的屬性中有 BackgroundImage,如下圖所示,可以用來設定背景圖片,但在智慧型裝置專案的表單中,並沒有此屬性
    在此想到的方法是寫程式將圖片描繪上去,首先我們想把圖片加入專案中,並將圖片的屬性,複製到輸出目錄改為永遠複製。

接著撰寫以下程式碼,將圖片讀入,並且覆寫 OnPaintBackground 方法,其功能為繪製控制項的背景;將圖片顯示部分撰寫於其中。

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;

namespace SmartDeviceBI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Bitmap bmpBackgroundImage;
        Rectangle RectBackgroundImage;

        private void Form1_Load(object sender, EventArgs e)
        {
            bmpBackgroundImage = new Bitmap(@"\Program Files\SmartDeviceBI\Water.jpg");
            RectBackgroundImage = new Rectangle(0, 0, bmpBackgroundImage.Width, bmpBackgroundImage.Height);
        }

        // 覆寫 OnPaintBackground 事件
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.DrawImage(bmpBackgroundImage, this.ClientRectangle, RectBackgroundImage, GraphicsUnit.Pixel);
        }
    }
}
  1. 執行結果

上一篇
[Windows Mobile]電腦與行動裝置同步操作軟體 : MyMobiler
下一篇
[Windows Mobile]Splash Screen
系列文
Windows Mobile41
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言