I need to pass the value for maxColumns to a method that will be used repeatedly by other items. How can I go about passing maxColumns in this scenario?
public partial class ValResults : Form
{
public ValResults()
{
InitializeComponent();
this.Table1Requirements();
}
private void Table1Requirements()
{
int maxColumns = 6;
this.table1LayoutPanelPrime.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPaint);
}
void tableLayoutPaint(object sender, TableLayoutCellPaintEventArgs e)
{
for (int i = 0; i < maxColumns; i++)
{
if (e.Row == 0 && e.Column == i)
{
Graphics g = e.Graphics;
Rectangle r = e.CellBounds;
g.FillRectangle(Brushes.LightGray, r);
}
}
}
}
If its in the same class, just define the variable at the class level.
private int _maxColumns;
public ValResults()
{
InitializeComponent();
this.Table1Requirements();
SetColumnCount();
}
private void SetColumnCount(){
_maxColumns= 6;
}
void tableLayoutPaint(object sender, TableLayoutCellPaintEventArgs e)
{
for (int i = 0; i < _maxColumns; i++)
{
if (e.Row == 0 && e.Column == i)
{
Graphics g = e.Graphics;
Rectangle r = e.CellBounds;
g.FillRectangle(Brushes.LightGray, r);
}
}
}
you can essentially pre build a function using lambdas...
private void Table1Requirements()
{
int maxColumns = 6;
this.table1LayoutPanelPrime.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPaint(maxColumns));
}
Action<object,TableLayoutCellPaintEventArgs> tableLayoutPaint(int columns)
return (sender, e) =>
{
for (int i = 0; i < columns; i++)
{
if (e.Row == 0 && e.Column == i)
{
Graphics g = e.Graphics;
Rectangle r = e.CellBounds;
g.FillRectangle(Brushes.LightGray, r);
}
}
}
that way you can generate different event handles with different max column settings
Related
private void inkcanvas_StrokeErased(object sender, RoutedEventArgs e)
{
var erasedstrokes = (sender as InkCanvas).Strokes;
aftererasedstrokecollection = erasedstrokes;
foreach (var item in aftererasedstrokecollection)
{
removedstrokes.Add(item);
}
}
private void inkcanvas_StrokeErasing(object sender InkCanvasStrokeErasingEventArgs e)
{
var beforeerased = (sender as InkCanvas).Strokes;
beforeerasedstrokecollection = beforeerased;
foreach (var item in beforeerasedstrokecollection)
{
unremovedstrokes.Add(item);
}
}
private void btnUndo_Click(object sender, RoutedEventArgs e)
{
if (DrawingTool == "Eraser" || DrawingTool == "Delete")
{
int length = removedstrokes.Count;
for (int i = 0; i < length; i++)
{
estroke = removedstrokes[i];
inkcanvas.Strokes.Remove(estroke);
}
for (int i = 0; i < unremovedstrokes.Count; i++)
{
estroke = unremovedstrokes[i];
inkcanvas.Strokes.Add(estroke);
}
}
else
{
if (inkcanvas.Strokes.Count > 0)
{
int i = inkcanvas.Strokes.Count;
inkcanvas.Strokes.RemoveAt(i - 1);
}
}
removedstrokes.Clear();
DrawingTool = "UnDo";
HighlightSelectedButton(sender);
IsDrawing = false;
inkcanvas.EditingMode = InkCanvasEditingMode.None;
}
I want to draw again erased strokes on undo click in WPF. through above code i do this for single stroke but i want to do same for multiple strokes.
please suggest any idea.
how i get only erased point by erasedbypoint method of inkcanvas
I have an image that is chopped into 4 pieces (2x2). I draw them in a random order and if the order of the small pics are correct write out "You win".
If you click on an image then it should be swap with the another next to it.
If you click the left button first change position with the third (right button 2-4). What is the problem with the code?
[![enter image description here][1]][1]
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;
using System.Collections;
namespace SimplePuzzle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonVéletlen_Click(object sender, EventArgs e)
{
Mix();
pictureBox1.Image = Image.FromFile("img\\1.png");
pictureBox2.Image = Image.FromFile("img\\2.png");
pictureBox3.Image = Image.FromFile("img\\3.png");
pictureBox4.Image = Image.FromFile("img\\4.png");
}
int[] arr = new int[4];
void Mix()
{
Random rnd = new Random();
int n = 4;
// Fill array 1-4
for (int i = 0; i < n; i++)
{
arr[i] = i + 1;
}
// Rnd array
for (int j = 0; j < n; j++)
{
int one = rnd.Next(n);
int another = rnd.Next(n);
int temp = arr[one];
arr[one] = arr[another];
arr[another] = temp;
}
for (int i = 0; i < 4; i++)
{
Console.WriteLine(arr[i].ToString());
}
// PictureBox1
if (arr[0]==0)
{
pictureBox1.Left = 0;
pictureBox1.Top = 0;
}
if (arr[0] == 1)
{
pictureBox1.Left = 150;
pictureBox1.Top = 0;
}
if (arr[0] == 2)
{
pictureBox1.Left = 0;
pictureBox1.Top = 150;
}
if (arr[0] == 3)
{
pictureBox1.Left = 150;
pictureBox1.Top = 150;
}
// PictureBox2
if (arr[1] == 0)
{
pictureBox2.Left = 0;
pictureBox2.Top = 0;
}
if (arr[1] == 1)
{
pictureBox2.Left = 150;
pictureBox2.Top = 0;
}
if (arr[1] == 2)
{
pictureBox2.Left = 0;
pictureBox2.Top = 150;
}
if (arr[1] == 3)
{
pictureBox2.Left = 150;
pictureBox2.Top = 150;
}
// PictureBox3
if (arr[2] == 0)
{
pictureBox3.Left = 0;
pictureBox3.Top = 0;
}
if (arr[2] == 1)
{
pictureBox3.Left = 150;
pictureBox3.Top = 0;
}
if (arr[2] == 2)
{
pictureBox3.Left = 0;
pictureBox3.Top = 150;
}
if (arr[2] == 3)
{
pictureBox3.Left = 150;
pictureBox3.Top = 150;
}
// PictureBox4
if (arr[3] == 0)
{
pictureBox4.Left = 0;
pictureBox4.Top = 0;
}
if (arr[3] == 1)
{
pictureBox4.Left = 150;
pictureBox4.Top = 0;
}
if (arr[3] == 2)
{
pictureBox4.Left = 0;
pictureBox4.Top = 150;
}
if (arr[3] == 3)
{
pictureBox4.Left = 150;
pictureBox4.Top = 150;
}
}
void CheckWin()
{
if (pictureBox1.Left==0 && pictureBox1.Top == 0 &&
pictureBox2.Left == 0 && pictureBox2.Top == 0 &&
pictureBox3.Left == 0 && pictureBox3.Top == 0 &&
pictureBox4.Left == 0 && pictureBox4.Top == 0)
{
MessageBox.Show("You have won!");
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBoxKöztes.Image = pictureBox1.Image;
pictureBox1.Image = pictureBox2.Image;
pictureBox2.Image = pictureBoxKöztes.Image;
CheckWin();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
pictureBoxKöztes.Image = pictureBox2.Image;
pictureBox2.Image = pictureBox1.Image;
pictureBox1.Image = pictureBoxKöztes.Image;
CheckWin();
}
private void pictureBox3_Click_1(object sender, EventArgs e)
{
pictureBoxKöztes.Image = pictureBox3.Image;
pictureBox3.Image = pictureBox4.Image;
pictureBox4.Image = pictureBoxKöztes.Image;
CheckWin();
}
private void pictureBox4_Click(object sender, EventArgs e)
{
pictureBoxKöztes.Image = pictureBox4.Image;
pictureBox4.Image = pictureBox3.Image;
pictureBox3.Image = pictureBoxKöztes.Image;
CheckWin();
}
private void buttonFirstCol_Click(object sender, EventArgs e)
{
pictureBoxKöztes.Image = pictureBox1.Image;
pictureBox1.Image = pictureBox3.Image;
pictureBox3.Image = pictureBoxKöztes.Image;
CheckWin();
}
private void buttonSecondCol_Click(object sender, EventArgs e)
{
pictureBoxKöztes.Image = pictureBox2.Image;
pictureBox2.Image = pictureBox4.Image;
pictureBox4.Image = pictureBoxKöztes.Image;
CheckWin();
}
}
}
[1]: https://i.stack.imgur.com/G9dMy.png
The CheckWin() method is the problem.
All you are doing is checking that the left and top of the picture boxes == 0.
But there's no code moving them around, so it can't ever equal true.
I'm working on a multimedia assignment and I found that the Dr is using this.load in the code so...
I don't understand why do we need this event handler as I think we can work without it.
I don't get why do I need such a ready made function and how it would be useful in multimedia programming or gaming programming.
This is my code :
namespace changecolors
{
public class Actor
{
public int X, Y, W, H;
public Color cl;
}
public partial class Form1 : Form
{
List<Actor> L = new List<Actor>();
int pos = -1;
public Form1()
{
this.WindowState = FormWindowState.Maximized;
this.Load += new EventHandler(Form1_Load);
this.KeyDown += new KeyEventHandler(Form1_KeyDown);
this.MouseDown += new MouseEventHandler(Form1_MouseDown);
}
void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
pos = -1;
for (int i = 0; i < L.Count; i++)
{
if (e.X >= L[i].X
&& e.X <= L[i].X + L[i].W
&& e.Y >=L[i].Y
&& e.Y <= L[i].Y + L[i].H)
{
pos = i;
}
}
}
else
{
if (pos > -1)
{
L[pos].Y += 10;
}
}
DrawScene();
}
void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Space:
DrawScene();
break;
}
}
void Form1_Load(object sender, EventArgs e)
{
int V = 100;
Color[] z = { Color.DarkGray, Color.Red, Color.Blue };
for (int i = 0; i < 3; i++)
{
Actor pnn = new Actor();
pnn.X = V;
pnn.Y = 200;
pnn.W = 70;
pnn.H = 170;
pnn.cl = z[i];
V += pnn.W;
L.Add(pnn);
}
}
void DrawScene()
{
Graphics g = this.CreateGraphics();
g.Clear(Color.MistyRose);
for (int i = 0; i < L.Count; i++)
{
SolidBrush br = new SolidBrush(L[i].cl);
g.FillRectangle(br,
L[i].X, L[i].Y,
L[i].W, L[i].H);
}
}
}
}
This title might be a bit not precise, what I am really having is this issue. I plotted a few lines, each is stored in a list, as line path. Then I use IsOutlineVisible to measure if the mouse location is on any of them, if mouse is on one, draw it as a different color or do something.
But it only recognize the last line in the list.
I would attach only the relevant part of the code, but this I really am not too sure where is the problem, so here is the entire code
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
List<GraphicsPath> LineGroup = new List<GraphicsPath>();
Point Latest{get;set;}
List<Point> pointtemp = new List<Point>();
bool startdrawline = true;
bool selectlinestate = false;
int selectedline;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
// Save the mouse coordinates
Latest = new Point(e.X, e.Y);
// Force to invalidate the form client area and immediately redraw itself.
Refresh();
if (startdrawline == false)
{
selectedline = Linesel(LineGroup);
}
}
protected override void OnPaint(PaintEventArgs e)
{
this.DoubleBuffered = true;
var g = e.Graphics;
base.OnPaint(e);
Pen penb = new Pen(Color.Navy,2);
Pen peny=new Pen(Color.Yellow,2);
for (int i = 0; i < LineGroup.Count; i++)
{
if (i == selectedline)
{
g.DrawPath(peny, LineGroup[i]);
}
else
{
g.DrawPath(penb, LineGroup[i]);
}
}
penb.Dispose();
peny.Dispose();
if (startdrawline == true)
{
GraphicsPath tracepath = new GraphicsPath();
Pen penr = new Pen(Color.Red,2);
if (pointtemp.Count == 1)
{
tracepath.AddLine(pointtemp[0], Latest);
}
else if (pointtemp.Count > 1)
{
tracepath.AddLine(pointtemp[1], Latest);
}
g.DrawPath(penr, tracepath);
penr.Dispose();
}
Refresh();
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
startdrawline = false;
pointtemp.Clear();
}
else if (e.Button == MouseButtons.Left )
{
startdrawline = true;
Latest = new Point(e.X, e.Y);
if (pointtemp.Count < 2)
{
pointtemp.Add(Latest);
}
else
{
pointtemp[0] = pointtemp[1];
pointtemp[1] = Latest;
}
if (pointtemp.Count == 2)
{
LineP2P(pointtemp);
}
Refresh();
}
}
private void LineP2P(List<Point> pointtemp){
GraphicsPath path = new GraphicsPath();
path.AddLine(pointtemp[0], pointtemp[1]);
LineGroup.Add(path);
}
private int Linesel(List<GraphicsPath> LineGroup)
{
int selectedline=-1;
for (int i =0; i < LineGroup.Count; i++)
{
Pen pen = new Pen(Color.Navy, 8);
if (LineGroup[i].IsOutlineVisible(Latest, pen))
{
selectedline = i;
}
else if (!LineGroup[i].IsOutlineVisible(Latest, pen))
{
selectedline = -1;
}
label1.Text = selectedline.ToString();
}
return selectedline;
}
}
}
When I put the test label.Text under the if
if (LineGroup[i].IsOutlineVisible(Latest, pen))
{
selectedline = i;
label1.Text = selectedline.ToString();
}
it actually works (varies with lines)
Can anyone identify the cause? Lot of Thanks.
The problem is that you did not break out of the loop once you find your line
lets say the line your mouse is on is at index 0. You are going to call
selectedline = 0 on the first iteration
and then on the second iteration
if (LineGroup[1].IsOutlineVisible(Latest, pen))
would be false so
selectedline = -1;
Thus unless you are mouse is on the last line selectedline will always be -1
What you want to do is probably
selectedline = -1;
for (int i =0; i < LineGroup.Count; i++)
{
Pen pen = new Pen(Color.Navy, 8);
if (LineGroup[i].IsOutlineVisible(Latest, pen))
{
selectedline = i;
break;
}
}
label1.Text = selectedline.ToString();
return selectedline;
Let me explain my problem:
I have a picturebox and this should be used to draw several elements of a listbox.
I gave the picturebox a canvas. by left and rightclick u can put up a rectangle which should preview the element u want to draw on the canvas of the picturebox.
Now this is my problem:
this rectangle should just be a preview and should be erased every time i click on a another position of the picturebox and put up a new rectangle. it should just be drawn on the canvas when i click on the inputbutton.
So how can i preview the chosen elements in the rectangle made by left and rightclick?
I hope my question is clealy enough : /
This is what i did so far:
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 Interaktive_systeme_sta
{
public partial class Bildeditor : Form
{
void drawRect()
{
pbxBild.Refresh();
using (Graphics g = this.pbxBild.CreateGraphics())
{
Pen blackPen = new Pen(Color.Black, 1);
blackPen.DashPattern = new float[] {2,2};
int X = Convert.ToInt32(nupX.Value);
int Y = Convert.ToInt32(nupY.Value);
int B = Convert.ToInt32(nupBreite.Value);
int H = Convert.ToInt32(nupHoehe.Value);
g.DrawRectangle(blackPen, X, Y, B, H);
g.Dispose();
}
}
public Bildeditor()
{
InitializeComponent();
this.MinimumSize = new Size(630,420);
this.MaximumSize = new Size(630, 420);
int canvasWidth = pbxBild.Width;
int canvasHeight = pbxBild.Height;
nupBreite.Maximum = canvasWidth;
nupHoehe.Maximum = canvasHeight;
nupBreite.Minimum = 0;
nupHoehe.Minimum = 0;
nupBreite.Value = canvasWidth;
nupHoehe.Value = canvasHeight;
nupX.Maximum = canvasWidth;
nupY.Maximum = canvasHeight;
nupX.Minimum = 0;
nupY.Minimum = 0;
nupX.Value = 0;
nupY.Value = 0;
drawRect();
}
private void btnZuruecksetzten_Click(object sender, EventArgs e)
{
int canvasWidth = pbxBild.Width;
int canvasHeight = pbxBild.Height;
nupX.Value = 0;
nupY.Value = 0;
nupBreite.Value = canvasWidth-1;
nupHoehe.Value = canvasHeight-1;
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
drawRect();
}
private void pbxBild_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
Point mouseDownLocation = new Point(e.X, e.Y);
switch (e.Button)
{
case MouseButtons.Left:
if (e.X < 0)
{
nupX.Value = 0;
}
else
{
nupX.Value = e.X;
}
if (e.Y < 0)
{
nupY.Value = 0;
}
else
{
nupY.Value = e.Y;
}
break;
case MouseButtons.Right:
if (e.X - nupX.Value < 1)
{
nupBreite.Value = 1;
}
else
{
nupBreite.Value = e.X - nupX.Value;
}
if (e.Y - nupY.Value < 1)
{
nupHoehe.Value = 1;
}
else
{
nupHoehe.Value = e.Y - nupY.Value;
}
break;
}
drawRect();
}
private void nupY_ValueChanged(object sender, EventArgs e)
{
drawRect();
}
private void nupBreite_ValueChanged(object sender, EventArgs e)
{
drawRect();
}
private void nupHoehe_ValueChanged(object sender, EventArgs e)
{
drawRect();
}
private void btnEinfuegen_Click(object sender, EventArgs e)
{
if (lbBildelemente.SelectedIndex == 0)
{
zeichneBild();
}
else if (lbBildelemente.SelectedIndex == 1)
{
zeichneLine();
}
else if (lbBildelemente.SelectedIndex == 2)
{
zeichneRect();
}
else if (lbBildelemente.SelectedIndex == 3)
{
zeichneText();
}
else if (lbBildelemente.SelectedIndex == 4)
{
zeichneKreis();
}
}
private void lbBildelemente_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbBildelemente.SelectedIndex == 0)
{
tbFarbe.Enabled = false;
btnFarbe.Enabled = false;
nupPen.Enabled = false;
tbBild.Enabled = true;
btnBild.Enabled = true;
tbText.Enabled = false;
tbSchrift.Enabled = false;
btnSchrift.Enabled = false;
}
else if (lbBildelemente.SelectedIndex == 1 || lbBildelemente.SelectedIndex == 2 || lbBildelemente.SelectedIndex == 4)
{
tbFarbe.Enabled = true;
btnFarbe.Enabled = true;
nupPen.Enabled = true;
tbBild.Enabled = false;
btnBild.Enabled = false;
tbText.Enabled = false;
tbSchrift.Enabled = false;
btnSchrift.Enabled = false;
}
else if (lbBildelemente.SelectedIndex == 3)
{
tbFarbe.Enabled = true;
btnFarbe.Enabled = true;
nupPen.Enabled = true;
tbBild.Enabled = false;
btnBild.Enabled = false;
tbText.Enabled = true;
tbSchrift.Enabled = true;
btnSchrift.Enabled = true;
}
}
void zeichneBild()
{
Graphics g = pbxBild.CreateGraphics();
int X = Convert.ToInt32(nupX.Value);
int Y = Convert.ToInt32(nupY.Value);
int B = Convert.ToInt32(nupBreite.Value);
int H = Convert.ToInt32(nupHoehe.Value);
Bitmap bitmap = new Bitmap(tbBild.Text);
g.DrawImage(bitmap, X, Y, B, H);
}
// Als zusatzfunktion kann man die Pinseldicke auswählen
void zeichneRect()
{
Graphics g = pbxBild.CreateGraphics();
Pen Pen = new Pen(tbFarbe.BackColor, Convert.ToInt32(nupPen.Value));
int X = Convert.ToInt32(nupX.Value);
int Y = Convert.ToInt32(nupY.Value);
int B = Convert.ToInt32(nupBreite.Value);
int H = Convert.ToInt32(nupHoehe.Value);
g.DrawRectangle(Pen, X, Y, B, H);
}
//zusatzfunktion
void zeichneKreis()
{
Graphics g = pbxBild.CreateGraphics();
Pen Pen = new Pen(tbFarbe.BackColor, Convert.ToInt32(nupPen.Value));
int X = Convert.ToInt32(nupX.Value);
int Y = Convert.ToInt32(nupY.Value);
int B = Convert.ToInt32(nupBreite.Value);
int H = Convert.ToInt32(nupHoehe.Value);
g.DrawEllipse(Pen, X, Y, B, H);
}
void zeichneLine()
{
Graphics g = pbxBild.CreateGraphics();
Pen Pen = new Pen(tbFarbe.BackColor, Convert.ToInt32(nupPen.Value));
int X = Convert.ToInt32(nupX.Value);
int Y = Convert.ToInt32(nupY.Value);
int B = Convert.ToInt32(nupBreite.Value);
int H = Convert.ToInt32(nupHoehe.Value);
g.DrawLine(Pen, X, Y, X+B, Y+H);
}
void zeichneText()
{
Graphics g = pbxBild.CreateGraphics();
Brush brush = new SolidBrush(tbFarbe.BackColor);
int X = Convert.ToInt32(nupX.Value);
int Y = Convert.ToInt32(nupY.Value);
g.DrawString(tbText.Text, fontDialog1.Font, brush, X, Y);
}
private void btnFarbe_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
tbFarbe.BackColor = colorDialog1.Color;
}
}
private void btnSchrift_Click(object sender, EventArgs e)
{
// Show the dialog.
DialogResult result = fontDialog1.ShowDialog();
// See if OK was pressed.
if (result == DialogResult.OK)
{
// Get Font.
Font font = fontDialog1.Font;
// Set TextBox properties.
this.tbSchrift.Text = string.Format(font.Name +"; "+ font.Size +"pt");
}
}
private void btnBild_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Joint Photographic Experts Group (*.jpg)|*.jpg|"
+ "EMF Enhanced Metafile Format (*.emf)|*.emf|"
+ "Graphics Interchange Format (*.gif)|*.gif|"
+ "Bitmap (*.bmp)|*.bmp|"
+ "W3C Portable Network Graphics (*.png)|*.png";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
tbBild.Text = openFileDialog.FileName;
}
}
private void bildbereichLöschenToolStripMenuItem_Click(object sender, EventArgs e)
{
pbxBild.Refresh();
}
private void bildLadenToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Joint Photographic Experts Group (*.jpg)|*.jpg|"
+ "EMF Enhanced Metafile Format (*.emf)|*.emf|"
+ "Graphics Interchange Format (*.gif)|*.gif|"
+ "Bitmap (*.bmp)|*.bmp|"
+ "W3C Portable Network Graphics (*.png)|*.png";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
Graphics g = pbxBild.CreateGraphics();
int X = 0;
int Y = 0;
int B = Convert.ToInt32(pbxBild.Width);
int H = Convert.ToInt32(pbxBild.Height);
Bitmap bitmap = new Bitmap(openFileDialog.FileName);
g.DrawImage(bitmap, X, Y, B, H);
}
}
}
}
I think this is what you need
private void Form1_Load(object sender, EventArgs e)
{
listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItem == "Circle")
{
pictureBox1.Image = circle;
}
}