Hey just need to ask a few questions hopefully one of you can answer as i have spent hours trying with no results and my code is a bit unorganised at the moment as im still learning:

(code down bottom)
1.How do you stop your picturebox clearing when the form is minimized?

2.How can you resize a Polygon that has been drawn using a trackbar?

3.How can you use a colordialog to change the color of the "draw.rectangle" and "draw.circle" ect.

4.How do you make the picturebox resize itself when form is maximized?

Thanks in advance Brandon

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

              


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int h = 0;
        int w = 0;
        int randomnumber;
        int randomnumberH;
        
        Color color;


       
        private void Form1_Load(object sender, EventArgs e)
        {          
        }
        private void circle(Color color1)
        {
            Random RandomClass = new Random();
            randomnumber = RandomClass.Next(1000);
            randomnumberH = RandomClass.Next(600);
            Graphics paper = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(color1, 5);
            paper.DrawEllipse(pen1, randomnumber,randomnumberH, h,w);

        }
        private void square(Color color1)
        {

            Random RandomClass = new Random();
            randomnumber = RandomClass.Next(1000);
            randomnumberH = RandomClass.Next(600);
            Graphics paper = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(color, 5);
            paper.DrawRectangle(pen1, randomnumber, randomnumberH, h,w);

        }
   
        private void triangle(Color color1)
        {
            int point1;
            int point2;
            int point3;
            int point4;
            int point5;
            int point6;

          

            Random RandomClass = new Random();
            randomnumber = RandomClass.Next(1000);
            randomnumberH = RandomClass.Next(600);

            int randomnumberB = randomnumber;
            int randonnumberC = randomnumberH;



            point1 = 125 + randomnumberB;
            point2 = 50 + randonnumberC;
            point3 = 100 + randomnumberB;
            point4 = 100 + randonnumberC;
            point5 = 150 + randomnumberB;
            point6 = 100 + randonnumberC;

            Graphics paper = pictureBox1.CreateGraphics();

            Point[] polygonPoints = new Point[3];
            Pen pen1 = new Pen(color, 5);

            polygonPoints[0] = new Point(point1 , point2) ;
            polygonPoints[1] = new Point(point3 , point4 );
            polygonPoints[2] = new Point(point5 , point6 );

           paper.DrawPolygon(pen1, polygonPoints);

        }


        public void Choice()
        {
            if (radioButton4.Checked)
            {
                color = Color.Red;
            }
            else
                if (radioButton5.Checked)
                {
                    color = Color.Green;
                }
                else if (radioButton6.Checked)
                {
                    color = Color.Blue ;
                }
                

        }

        private void button1_MouseClick(object sender, MouseEventArgs e)
        {

            Choice();

            click();


        }


        private void button1_Click(object sender, EventArgs e)
        {

            Choice();

            click();

           
           
        }
        private void click()
    {
        if (radioButton1.Checked)
        {
            circle(color);
        }
        if (radioButton2.Checked)
        {
            square(color);
        }
        if (radioButton3.Checked)
        {
            triangle(color);       
        }
    }
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            h = trackBar1.Value;
            w = trackBar1.Value;
          

            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            pictureBox1.Refresh();
        }

        private void drawPictureToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
        }

        private void drawPictureToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Choice();
            click();
        }

        private void clearToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pictureBox1.Refresh();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}

An easy way to persist drawn images is to do the drawing onto a separate Bitmap object, and then set the PictureBox's Image property.

Suppose that the center has coordinates (c,d), s is the scaling factor in the x direction and t is the scaling factor in the y direction. For any point P with coordinates (x,y) you want to transform P by

x is transformed to s(x - c) + c
y is transformed to t(y - d) + d

This article has been dead for over six months. Start a new discussion instead.