Click here to Skip to main content
16,015,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm creating an application which the user is able to select the line he/she draw. He/She can also right click it and a context menu strip will pop out. Any Ideas?

Regards :-D
Posted

The way to do this is to store the position of the line in your code, and as the mouse moves, check if it's crossing the line. If you want to draw more than one object, you'd have a collection of objects in your code, your paint method would draw them and your mouse move code would iterate over them to see if your mouse was touching one.
 
Share this answer
 
Comments
holyoxx 30-Aug-10 19:39pm    
That means, I need to use a separate class for the lines to make it as an object?
Here I managed to do it using a hard coded rectangle.
<pre lang="cs">
        private bool selectGraph = false;
        private Rectangle myrec = new Rectangle(50, 50, 100, 100);
        private Graphics g;
        
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            g = panel1.CreateGraphics();
            SolidBrush sb = new SolidBrush(Color.Blue);
            Pen p = new Pen(Color.Blue, 5);
            g.DrawRectangle(p, myrec);
            g.FillRectangle(sb, myrec);
        }
  
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            Point mPT = new Point(e.X, e.Y);
            if (e.Button == MouseButtons.Left)
            {
                if (myrec.Contains(mPT))
                {
                    selectGraph = true;
                    button1.Enabled = true;
                }
                else
                {
                    selectGraph = false;
                    button1.Enabled = false;
                }
            }
            Invalidate();
        }



But what I want is a runtime draw line. :doh:
 
Share this answer
 
Problem Solved. Use Microsoft VisualBasic PowerPack 3.0 :laugh:
 
Share this answer
 
Comments
Christian Graus 31-Aug-10 1:39am    
You should not push 'answer' to add questions or comments. Yes, to do it properly you write classes. I don't know what VB Powerpack offers in this way, but if it solves your problem, that's good. If you find you need more control, then you need to do what I suggested.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900