PictureBox visible and invisible

image_pdfimage_print

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class ListText : Form {

private Button choose = new Button();
private ListBox animalList = new ListBox( );
private ListBox things = new ListBox( );
private TextBox text = new TextBox( );
private PictureBox picture = new PictureBox();
private PictureBox photo = new PictureBox();
private CheckBox show = new CheckBox();
private CheckBox author = new CheckBox();

private Bitmap moon = new Bitmap(“winter.jpg”);

public ListText( ) {
Text = “List Text”;
choose.Text = “Choose”;
show.Text = “Show a bitmap”;
author.Text = “Show another bitmap”;

Size = new Size(400, 300);
choose.Size = new Size(100,20);
text.Size = new Size(150,50);
photo.Size = new Size(100,100);

choose.Location = new Point(20,30);
animalList.Location = new Point(30 + choose.Width, 30);
things.Location = new Point(40 + choose.Width + animalList.Width, 30);
text.Location = new Point(20, 150);
photo.Location = new Point(40 + text.Width, 150);
picture.Location = new Point(60 + text.Width + photo.Width, 150);
show.Location = new Point(20,70);
author.Location = new Point(20,110);

animalList.SelectionMode = SelectionMode.MultiSimple;
things.SelectionMode = SelectionMode.One;
text.Multiline = true;
picture.Image = (Image)moon;
picture.Visible = false;
photo.Image = Image.FromFile(“winter.jpg”);
photo.Visible = false;
BackColor = Color.White;
choose.BackColor = Color.Pink;

animalList.Items.Add(“A”);
animalList.Items.Add(“B”);
animalList.Items.Add(“C”);
animalList.Items.Add(“D”);
animalList.Items.Add(“E”);
things.Items.Add(“1”);
things.Items.Add(“2”);
things.Items.Add(“3”);
things.Items.Add(“4”);

Controls.Add(animalList);
Controls.Add(things);
Controls.Add(choose);
Controls.Add(text);
Controls.Add(picture);
Controls.Add(show);
Controls.Add(author);
Controls.Add(photo);

choose.Click += new EventHandler(Choose_Click);
things.SelectedIndexChanged += new EventHandler(Things_Changed);
show.CheckedChanged += new EventHandler(Picture_Changed);
author.CheckedChanged += new EventHandler(Photo_Changed);
}

protected void Choose_Click(object sender, EventArgs e) {
for(int i = 0; i < animalList.SelectedItems.Count; i++){ Console.WriteLine(animalList.SelectedItems[i].ToString()); } } protected void Things_Changed(object sender, EventArgs e) { text.Text = "You selected " + things.SelectedItem; } protected void Picture_Changed(Object sender, EventArgs e) { if (show.Checked) picture.Visible = true; else picture.Visible = false; Invalidate(); } protected void Photo_Changed(Object sender, EventArgs e) { if (author.Checked) photo.Visible = true; else photo.Visible = false; Invalidate(); } static void Main() { Application.Run(new ListText()); } } [/csharp]