C# 鼠标经过与离开时,按钮颜色变换问题。十分感谢!!! 本帖最后由 bdmh 于 2014-09-16 10:46:07 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ..那你得添加鼠标离开时,颜色变回原来一般搞漂亮点就是两张背景图片,一张平时的,一张鼠标经过的,经过的时候换,离开的时候换回来只要属性方法不是私有的都可以继承,例如把private换成protected或public这些问题,百度一下就知道 搞2个PIXBOX 哈哈,鼠标移上去的时候隐藏一个,离开的时候隐藏另外一个,反正只能一个显示就可以了, private void pic_ok_MouseLeave(object sender, EventArgs e) { pic_ok.Image = Properties.Resources.离开; } Quote: 引用 2 楼 q309079549 的回复:主要这个图片不是固定的,我是给别人调用的。 有没有办法呢? 晕,就是鼠标经过时,图片按钮变白,然后鼠标离开后,就像刚加载那样。。 试了几种方法都不行1.鼠标经过时,获取当前坐标的颜色,然后离开时再赋值给他,因为按钮也是图片,所以获取的是按钮图片上的颜色2.调用 this.Controls.Clear(); GC.Collect(); this.InitializeComponent();但是这样导致窗口最大化不了,因为最大化的时候,鼠标就已经离开了按钮位置 图片非固定的文件名可以参数传递进去啊我试了,不可以。picturebox是最小化,最大化,关闭按钮。图片按钮是透明的,经过的时候改了背景色,离开的时候变换成之前的图片,但是背景色没变回来 其实我没看懂……又是图片按钮,又是picturebox,又是最大化/最小化,又是透明楼主想要实现什么? 一个主窗体上有3个picturebox,picturebox分别放了三个背景图片,最小化,最大化,关闭。然后别人继承我这个form后,就不需要再进行画这三个按钮了,然后别人继承了后,会更改form的背景图。然后又希望鼠标经过这三个按钮时,能跟360那样,经过的时候背景色变成白的,离开时就变成背景色了。 我也不知道这个做啥用,上司要求,说以后省事。。 不知道360啥样,哈哈实现了个 鼠标放上去图片消失,变为背景色变为红色,鼠标移开,变为透明背景,恢复图片点击关闭窗口如下的pictureBox2,你自己换个图片用就行了Form1.cspublic partial class Form1 : Form { public Form1() { InitializeComponent(); } private void pictureBox2_Click(object sender, EventArgs e) { this.Close(); } private Image tmpImg = null; private void pictureBox2_MouseHover(object sender, EventArgs e) { this.pictureBox2.BackColor = Color.Red; tmpImg = this.pictureBox2.Image; this.pictureBox2.Image = null; } private void pictureBox2_MouseLeave(object sender, EventArgs e) { this.pictureBox2.BackColor = Color.Transparent; this.pictureBox2.Image = tmpImg; this.pictureBox2.Refresh(); } }Form1.desiner.cspartial class Form1 { /// <summary> /// 必要なデザイナー変数です。 /// </summary> private System.ComponentModel.IContainer components = null; /// <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.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); this.SuspendLayout(); // // pictureBox1 // this.pictureBox1.Image = global::TestPictureBox.Properties.Resources.excel_2003_01; this.pictureBox1.InitialImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.InitialImage"))); this.pictureBox1.Location = new System.Drawing.Point(182, 3); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(26, 21); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; // // pictureBox2 // this.pictureBox2.Image = global::TestPictureBox.Properties.Resources.dll_old; this.pictureBox2.InitialImage = ((System.Drawing.Image)(resources.GetObject("pictureBox2.InitialImage"))); this.pictureBox2.Location = new System.Drawing.Point(225, 3); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(26, 21); this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox2.TabIndex = 0; this.pictureBox2.TabStop = false; this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click); this.pictureBox2.MouseLeave += new System.EventHandler(this.pictureBox2_MouseLeave); this.pictureBox2.MouseHover += new System.EventHandler(this.pictureBox2_MouseHover); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.pictureBox2); this.Controls.Add(this.pictureBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox pictureBox2; } http://blog.csdn.net/yuwenge/article/details/5185281 谢谢了, 最后用ptrMin.BackColor = Color.Transparent; 解决了 关于学Ado.net的疑惑[非技术] 关于VS2008编译后的程序 请教:如何修改自定义控件里面的属性 C# 如何实现 一个 控件形式的软键盘 [散分前5名每人20] 100分的帖子沉底了! 关于OWC的使用技巧--能否将说明放到顶部显示 毕业设计!delphi 7 + sql 或delphi +Access MD5加密对被加密字符串的长度有限制吗? [问题分享]VS2013自带的Newtonsoft导致的编译异常 通过lock(fileName) 防止对文件的并发访问,安全吗?如不安全,用什么代替? “不能将此属性设置为空字符串。 求助 新闻内文怎么分页显示呢?
{
pic_ok.Image = Properties.Resources.离开; }
GC.Collect();
this.InitializeComponent();
但是这样导致窗口最大化不了,因为最大化的时候,鼠标就已经离开了按钮位置
文件名可以参数传递进去啊
我试了,不可以。
picturebox是最小化,最大化,关闭按钮。图片按钮是透明的,经过的时候改了背景色,离开的时候变换成之前的图片,但是背景色没变回来
又是图片按钮,又是picturebox,又是最大化/最小化,又是透明
楼主想要实现什么?
实现了个 鼠标放上去图片消失,变为背景色变为红色,鼠标移开,变为透明背景,恢复图片
点击关闭窗口
如下的pictureBox2,你自己换个图片用就行了
Form1.cs
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void pictureBox2_Click(object sender, EventArgs e)
{
this.Close();
} private Image tmpImg = null; private void pictureBox2_MouseHover(object sender, EventArgs e)
{
this.pictureBox2.BackColor = Color.Red;
tmpImg = this.pictureBox2.Image;
this.pictureBox2.Image = null;
} private void pictureBox2_MouseLeave(object sender, EventArgs e)
{
this.pictureBox2.BackColor = Color.Transparent;
this.pictureBox2.Image = tmpImg;
this.pictureBox2.Refresh();
}
}Form1.desiner.cs
partial class Form1
{
/// <summary>
/// 必要なデザイナー変数です。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <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.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = global::TestPictureBox.Properties.Resources.excel_2003_01;
this.pictureBox1.InitialImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.InitialImage")));
this.pictureBox1.Location = new System.Drawing.Point(182, 3);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(26, 21);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Image = global::TestPictureBox.Properties.Resources.dll_old;
this.pictureBox2.InitialImage = ((System.Drawing.Image)(resources.GetObject("pictureBox2.InitialImage")));
this.pictureBox2.Location = new System.Drawing.Point(225, 3);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(26, 21);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox2.TabIndex = 0;
this.pictureBox2.TabStop = false;
this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click);
this.pictureBox2.MouseLeave += new System.EventHandler(this.pictureBox2_MouseLeave);
this.pictureBox2.MouseHover += new System.EventHandler(this.pictureBox2_MouseHover);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.ResumeLayout(false); } #endregion private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
}