我想在鼠标悬停时更改按钮的backgroundImage
属性,如下所示:
private void btnGetHardwareID_MouseEnter(object sender, EventArgs e)
{
btnGetHardwareID.BackgroundImage = (System.Drawing.Image)(Properties.Resources._11949847771696668271pill_button_green_benji__01_svg_med);
btnGetHardwareID.Refresh();
}
private void btnGetHardwareID_MouseLeave(object sender, EventArgs e)
{
btnGetHardwareID.BackgroundImage = (System.Drawing.Image)(Properties.Resources._11949847771793996117pill_button_purple_benji_01_svg_med);
btnGetHardwareID.Refresh();
}
btnGetHardwareID的属性如下:
// btnGetHardwareID
//
this.btnGetHardwareID.BackColor = System.Drawing.Color.Transparent;
this.btnGetHardwareID.BackgroundImage = global::Travian.Properties.Resources._11949847771793996117pill_button_purple_benji_01_svg_med;
this.btnGetHardwareID.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.btnGetHardwareID.FlatAppearance.BorderSize = 0;
this.btnGetHardwareID.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnGetHardwareID.Font = new System.Drawing.Font("Cambria", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnGetHardwareID.ForeColor = System.Drawing.Color.White;
this.btnGetHardwareID.Location = new System.Drawing.Point(31, 53);
this.btnGetHardwareID.Name = "btnGetHardwareID";
this.btnGetHardwareID.Size = new System.Drawing.Size(160, 40);
this.btnGetHardwareID.TabIndex = 25;
this.btnGetHardwareID.Text = "Get My Hardware-ID";
this.btnGetHardwareID.UseVisualStyleBackColor = false;
this.btnGetHardwareID.Click += new System.EventHandler(this.btnGetHardwareID_Click);
this.btnGetHardwareID.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnGetHardwareID_MouseDown);
this.btnGetHardwareID.MouseEnter += new System.EventHandler(this.btnGetHardwareID_MouseEnter);
this.btnGetHardwareID.MouseLeave += new System.EventHandler(this.btnGetHardwareID_MouseLeave);
this.btnGetHardwareID.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnGetHardwareID_MouseUp);
现在的问题是,在MouseEnter时的backgroundImage如下所示:
![Mouse Enter](https://istack.dev59.com/Ok8iU.webp)
![Mouse Leave](https://istack.dev59.com/K53aq.webp)
编辑: 原始图像如下:
![red button - original - png format](https://istack.dev59.com/LxpnJ.webp)
![green button - original - png format](https://istack.dev59.com/os8fo.webp)
![main form - background-image](https://istack.dev59.com/azd0G.webp)