Microsoft Visual Studio

Microsoft Visual Studio CShap Timer

1. File> New Project

2. Drag and Drop over Form1:
– label1
– timer1

You will not see the timer component inside the form because it has not a visual rapresentation, it will be added under the component bar, below the graphic form.

3. Click over timer1 and on the right on the ‘Properties’ windows set:
Enabled: True
Interval: 1000 (millisecons), so it refresh every 1 second

4. Double Click timer1 to add the handle inside 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 TimerTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.Second.ToString(); // it renders: 15 16 17 18 etc...
        }
    }
}

By |C# .NET, Microsoft Visual Studio|Commenti disabilitati su Microsoft Visual Studio CShap Timer

Microsoft Visual Studio – Click – DoubleClick – OnMouse – MouseEnter – MouseLeave

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);
}
...
By |C# .NET, Microsoft Visual Studio|Commenti disabilitati su Microsoft Visual Studio – Click – DoubleClick – OnMouse – MouseEnter – MouseLeave

Microsoft Visual Studio – WebBrowser

Load a Web Page inside a Form

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:
– Button
– WebBrowser

4. On the right column in the Property Window under the ‘Design’ section (Progettazione) change (Name):
– Button -> button1
– PictureBox -> webBrowser1

6. Double-click the button to create the button1_Click event handler, and add the following code in 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 Test_WebBrowser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            {
                webBrowser1.Url = new Uri("http://www.lucedigitale.com/");
            }
        }
    }
}

7. Run

By |C# .NET, Microsoft Visual Studio|Commenti disabilitati su Microsoft Visual Studio – WebBrowser

Microsoft Visual Studio – Picture Box – Get www Image

Load an image from a url into a PictureBox

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:
– Button
– PictureBox

4. On the right column in the Property Window under the ‘Design’ section (Progettazione) change (Name):
– Button -> button1
– PictureBox -> pictureBox1

5. Double-click the button to create the button1_Click event handler, and add the following code in 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 Test_ImageStream
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string url = "http://www.lucedigitale.com/principale/images/logo.png";

            {
                pictureBox1.Load(url);
            }
        }
    }
}

6. Run

By |C# .NET, Microsoft Visual Studio|Commenti disabilitati su Microsoft Visual Studio – Picture Box – Get www Image

Microsoft Visual Studio – Picture Box

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:
– Button
– PictureBox

4. On the right column in the Property Window under the ‘Design’ section (Progettazione) change (Name):
– Button -> myButton
– PictureBox -> myPictureBox

5. Double-click the button to create the myButton_Click event handler, and add the following code in Form1.cs

Size


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 PictureBoxTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        } // end public Form1

        private void myButton_Click(object sender, EventArgs e)
        {
            myPictureBox.Size = new Size(100, 100);
        }// end myButton_Click
    }// end class Form1
}// end namespace 

6. Run

Visible

...
myPictureBox.Visible = false;
...

Location

...
myPictureBox.Location = new Point(300, 300);// pixels x y
...
By |C# .NET, Microsoft Visual Studio|Commenti disabilitati su Microsoft Visual Studio – Picture Box