Skip to content

Drawing on panel in proper layout.

Tehseen Ahmed

Asked Sep 27, 2012, 1:34 AM EDT1 answer
Share
LinkedInX
Hi
I want to draw rectangles and lines on panel (c#),but i want to draw like in proper layout.
First thing is there is possibility to draw on flowLayoutPanel(c#).
because i want to draw in proper lines and columns.
if not then is there any other way to do this?
Thanks in advance :)    

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You Can Use this code for line and columns also------------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            int y;
            int x;
            private void panel1_MouseClick(object sender, MouseEventArgs e)
            {
                Point p = new Point(e.Y, e.X);
                x = p.X;
                y = p.Y;
                panel1.Invalidate();
            }

            private void panel1_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = panel1.CreateGraphics();
                Pen p = new Pen(Color.Black);
                if (listBox1.SelectedIndex == 0)
                {
                    SolidBrush sb = new SolidBrush(Color.Red);
                    g.DrawEllipse(p, x - 50, y - 50, 100, 100);
                    g.FillEllipse(sb, x - 50, y - 50, 100, 100);
                }
                if (listBox1.SelectedIndex == 1)
                {
                    SolidBrush sb = new SolidBrush(Color.Red);
                    g.DrawRectangle(p, x - 50, y - 50, 100, 100);
                    g.FillRectangle(sb, x - 50, y - 50, 100, 100);
                }
            }
        }
    }
    0