参考了WinCE5.0下实现透明背景按钮(.net C#)这篇文章后,本着不模仿的态度去做,结果发现还是原先作者的思路比较好,自己的做法
虽然比较简单当时图片得做很多张,效果其实也差不多,而且可维护性并不强,先把我自己做的贴出来。
希望自己多敲敲,能找出更简单的方案来
目录试图:
效果:
直接贴代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Reflection;
namespace whiteButton2 { public partial class Form1 : Form { private string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);//获取PDA路径 private Bitmap bg, title;//
public Form1() { this.WindowState = FormWindowState.Maximized; this.FormBorderStyle = FormBorderStyle.None; this.ControlBox = false; InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) {
bg = new Bitmap(currentPath + @"\Resources\bg293.jpg"); title = new Bitmap(currentPath + @"\Resources\title.jpg"); }
private void Form1_Paint(object sender, PaintEventArgs e) { Graphics graphics; graphics = e.Graphics; graphics.DrawImage(bg,0,0); graphics.DrawImage(title,0,0); }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image"))); //各类事件及方法 }
private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); }
private void pictureBox3_MouseDown(object sender, MouseEventArgs e) { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox4.Image"))); }
private void pictureBox3_MouseUp(object sender, MouseEventArgs e) { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image"))); }
} }
Form1.Designer.cs界面代码:
namespace whiteButton2 { partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; private System.Windows.Forms.MainMenu mainMenu1;
/// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
#region Windows 窗体设计器生成的代码
/// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.pictureBox3 = new System.Windows.Forms.PictureBox(); this.pictureBox4 = new System.Windows.Forms.PictureBox(); this.SuspendLayout(); // // pictureBox1 // this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point(3, 46); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(111, 40); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp); // // pictureBox2 // this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image"))); this.pictureBox2.Location = new System.Drawing.Point(3, 49); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(112, 39); this.pictureBox2.Visible = false; // // pictureBox3 // this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image"))); this.pictureBox3.Location = new System.Drawing.Point(121, 46); this.pictureBox3.Name = "pictureBox3"; this.pictureBox3.Size = new System.Drawing.Size(110, 40); this.pictureBox3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox3_MouseDown); this.pictureBox3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox3_MouseUp); // // pictureBox4 // this.pictureBox4.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox4.Image"))); this.pictureBox4.Location = new System.Drawing.Point(121, 46); this.pictureBox4.Name = "pictureBox4"; this.pictureBox4.Size = new System.Drawing.Size(110, 40); this.pictureBox4.Visible = false; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoScroll = true; this.ClientSize = new System.Drawing.Size(240, 268); this.Controls.Add(this.pictureBox3); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.pictureBox2); this.Controls.Add(this.pictureBox4); this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.PictureBox pictureBox3; private System.Windows.Forms.PictureBox pictureBox4; } }
PDA目录下如果没有图片会报(指的是PDA端 不是项目根目录下):
解决方法:
通过同步软件把图片目录拷过去
找到 我的WINDOWS移动设备
粘贴进去就好了
最后提供下源码及资源文件:http://download.csdn.net/download/sat472291519/4433251