1. Run Visual Studio
2. File> New project, select ‘C# windows Form Application’ and give it a name.
3. On the right column select Form1.cs, on the left open the toolbox, drag and drop over the Form:
– PictureBox
4. On the right column in the Property Window under the ‘Design’ section (Progettazione) change (Name):
– PictureBox -> myPictureBox
5. Double-click the PictureBox to create the myPictureBox_Click event handler, and add the following code in Form1.cs
Click
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MouseTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} // end public Form1
private void myPictureBox_Click(object sender, EventArgs e)
{
myPictureBox.Size = new Size(100, 100);
}
}// end class Form1
}// end namespace
6. Run
DoubleClick
Form1.Designer.cs
namespace MouseTest
{
partial class Form1
{
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Pulire le risorse in uso.
/// </summary>
/// <param name="disposing">ha valore true se le risorse gestite devono essere eliminate, false in caso contrario.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Codice generato da Progettazione Windows Form
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent()
{
this.myPictureBox = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.myPictureBox)).BeginInit();
this.SuspendLayout();
//
// myPictureBox
//
this.myPictureBox.Image = global::ButtonsTest.Properties.Resources.andrea_tonin;
this.myPictureBox.InitialImage = null;
this.myPictureBox.Location = new System.Drawing.Point(12, 12);
this.myPictureBox.Name = "myPictureBox";
this.myPictureBox.Size = new System.Drawing.Size(195, 195);
this.myPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.myPictureBox.TabIndex = 1;
this.myPictureBox.TabStop = false;
this.myPictureBox.DoubleClick += new System.EventHandler(this.myPictureBox_DoubleClick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(740, 374);
this.Controls.Add(this.myPictureBox);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.myPictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox myPictureBox;
}
}
Notice:
myPictureBox -> this.myPictureBox.DoubleClick += new System.EventHandler(this.myPictureBox_DoubleClick);
Into Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MouseTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} // end public Form1
private void myPictureBox_DoubleClick(object sender, EventArgs e)
{
myPictureBox.Size = new Size(50, 50);
}
}// end class Form1
}// end namespace ButtonsTest
Notice:
private void myPictureBox_DoubleClick(object sender, EventArgs e)
{
myPictureBox.Size = new Size(50, 50);
}
MouseHover
Change the code event as show below:
Form1.Designer.cs
...
this.myPictureBox.MouseHover += new System.EventHandler(this.myPictureBox_MouseHover);
...
Form1.cs
...
private void myPictureBox_MouseHover(object sender, EventArgs e)
{
myPictureBox.Size = new Size(50, 50);
}
...
MouseEnter
Change the code event as show below:
Form1.Designer.cs
...
this.myPictureBox.MouseEnter += new System.EventHandler(this.myPictureBox_MouseEnter);
...
Form1.cs
...
private void myPictureBox_MouseEnter(object sender, EventArgs e)
{
myPictureBox.Size = new Size(50, 50);
}
...
MouseLeave
Change the code event as show below:
Form1.Designer.cs
...
this.myPictureBox.MouseLeave += new System.EventHandler(this.myPictureBox_MouseLeave);
...
Form1.cs
...
private void myPictureBox_MouseLeave(object sender, EventArgs e)
{
myPictureBox.Size = new Size(50, 50);
}
...