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

Microsoft Visual Studio – DateTimePicker

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
– DateTimePicker

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

5. Double-click the button to create the myButton_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 DateTimePickerTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        } // end public Form1

        private void myButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show(myDateTimePicker.Value.ToString());
            // result: 30/12/2016 16:14:38
            MessageBox.Show(myDateTimePicker.Value.ToShortDateString());
            // result: 30/12/2016
        }// end myButton_Click
    }// end class Form1
}// end namespace DateTimePickerTest

6. Run

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

Microsoft Visual Studio – ComboBox

1. Run Visual Studio

2. File> New project, select ‘C# windows Form Application’ and give it a name.
I name it ‘ButtonsTest’

3. In your hard drive you fill find in the folder ‘ButtonsTest’/ButtonsTest/ here C# files

4. On the right column select Form1.cs, on the left open the toolbox, drag and drop over the Form:
– Button
– ComboBox

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

and for the ComboBox> Properties> Items> write:
stringone
stringtwo
stringthree

6. Double-click the button to create the myButton_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 ButtonsTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        } // end public Form1

        private void myButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(myComboBox.Text))
            {
                MessageBox.Show("No Item is Selected");
            }
            else
            {
                MessageBox.Show(myComboBox.Text);
            }

        }// end myButton_Click
    }// end class Form1
}// end namespace ButtonsTest

7. Run

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

Microsoft Visual Studio – CheckedListBox

1. Run Visual Studio

2. File> New project, select ‘C# windows Form Application’ and give it a name.
I name it ‘ButtonsTest’

3. In your hard drive you fill find in the folder ‘ButtonsTest’/ButtonsTest/ here C# files

4. On the right column select Form1.cs, on the left open the toolbox, drag and drop over the Form:
– Button
– CheckedListBox

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

and for the CheckedListBox> Properties> Items> write:
stringone
stringtwo
stringthree

6. Double-click the button to create the myButton_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 ButtonsTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        } // end public Form1

        private void myButton_Click(object sender, EventArgs e)
        {
            // Determine if there are any items checked.
            if (myCheckedListBox.CheckedItems.Count != 0)
            {
                // If so, loop through all checked items and print results.
                string s = "";
                for (int x = 0; x <= myCheckedListBox.CheckedItems.Count - 1; x++)
                {
                    s = s + "Checked Item " + (x + 1).ToString() + " = " + myCheckedListBox.CheckedItems[x].ToString() + "\n";
                }
                MessageBox.Show(s);
            }
            else
            {
                MessageBox.Show("No one checked");
            }

        }// end myButton_Click
    }// end class Form1
}// end namespace ButtonsTest

7. Run, check the second and the third, click the Button, you will see in the Message Box:
Checked Item 1 = stringtwo
Checked Item 2 = stringthree

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