Hi all
am a beginner in C#
iam making a Drawing application
the user will choose the x-y position , width ,hight , the shape and the color he want
and then press the Draw button
i coded the button and it work properly and draw the shape in the same form
but i need the drawing to be done in another form
How can i do it ??
please help me

with respect
JeeJ

Recommended Answers

All 5 Replies

What have you done so far? What sort of object are your drawing onto?
--Taylby

Thanks for replaying Taylby

this is my code ^_^

namespace Drawing_Application
{
    public partial class Form1 : Form
    {
        Pen p;
        SolidBrush b;
        Color c;
        public Form1()
        {
            InitializeComponent();
                
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int x = Convert.ToInt32(textBox1.Text);
            int y = Convert.ToInt32(textBox2.Text);
            int w = Convert.ToInt32(textBox3.Text);
            int h = Convert.ToInt32(textBox4.Text);
            Graphics g = base.CreateGraphics();
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    {
                        if (radioButton1.Checked)
                            g.DrawEllipse(p, x, y, w, h);
                        if (radioButton4.Checked)
                            g.DrawLine(p, x, y, w, h);
                        if (radioButton3.Checked)
                            g.DrawRectangle(p, x, y, w, h);
                        if (radioButton2.Checked)
                          {
                            if (w == h)
                                g.DrawRectangle(p, x, y, w, h);
                            else
                                g.DrawRectangle(p, x, y, w, w);
                          }// if end 
                    break; 
                    }//case 0 end 

                case 1:
                    {
                        p = new Pen(b);
                       if (radioButton1.Checked)
                           g.DrawEllipse(p, x, y, w, h);
                       if (radioButton4.Checked)
                           g.DrawLine(p, x, y, w, h);
                       if (radioButton3.Checked)
                           g.DrawRectangle(p, x, y, w, h);
                       if (radioButton2.Checked)
                       {
                           if (w == h)
                               g.DrawRectangle(p, x, y, w, h);
                           else
                               g.DrawRectangle(p, x, y, w, w);

                       }// if end 

                        break;
                    }// case 1 end 
                case 2: {
                    p = new Pen(c);
                if (radioButton1.Checked)
                    g.DrawEllipse(p, x, y, w, h); 
                if (radioButton4.Checked)
                    g.DrawLine(p, x, y, w, h);
                if (radioButton3.Checked)
                    g.DrawRectangle(p, x, y, w, h);
                if (radioButton2.Checked)
                {
                    if (w == h)
                        g.DrawRectangle(p, x, y, w, h);
                    else
                        g.DrawRectangle(p, x, y, w, w);

                } // if end 
                    break;
                }// case 2 end 
            } // switch end 

 }//Button click end 


        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {


            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    {
                        
                        if (colorDialog1.ShowDialog() == DialogResult.OK)
                                p = new Pen(colorDialog1.Color);
                        else
                            p = new Pen(Color.Black);
                        break;
                    }//case 0 end 

                case 1:
                    {
                        if (colorDialog1.ShowDialog() == DialogResult.OK)
                               b = new SolidBrush(colorDialog1.Color);
                        else
                            b = new SolidBrush(Color.Black);
                        break;
                    }// case 1 end
 
                case 2:
                    {
                        c = Form1.DefaultBackColor;
                        break;
                    }// case 2 end 
            } // switch end 
        }// combobox1_selected... end 

    }// class end 
} // application end

and lately the colorDialog is not working :(
i feel depressed

Ok, so glancing through your code you have no reference to a second form. Create the form with a method to accept a Graphic object. Then when you want to triger this then you pass your object to the child form as a parameter and handle it. You say you have it working on your main form, so it should be pretty easy to transpose. Also You seam to be repeating your work in the case statement, try to extract this into a method.

--taylby

Thanks alot
i will try it now ^_^

Let me know how it goes and use the code tag to display your code, makes it a lot easier to read.
--Taylby

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.