Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi ,

i have a control panel, and contains different picturbox to display pictures on the control. these picturboxs also moveable using Multithreading. i want that to draw the path of movement of each picture. please.
any suggestion please.
code is given below. agentbox is picturbox; ratimage is bitmap image for each picturebox.
C#
}
 Graphics g = Graphics.FromImage(ratImage);
               Pen pColor = new Pen(Color .Black );
               pColor.Width = 3;
               Brush bb = pColor.Brush;
               g.FillEllipse(bb, new Rectangle(new Point(agentBox.Width / 2, agentBox.Height / 2), new Size(20, 20)));
               

               this.agentBox.Image = ratImage;
               this.agentBox.SizeMode = PictureBoxSizeMode.StretchImage;
               
    
               agentBox.Left = p.X;
               agentBox.Top = p.Y;               
               
               


               Graphics gControlPanle = panel101.CreateGraphics();
               GraphicsPath agentPath = new GraphicsPath();
               
                   agentPath.AddLine(this.fromPoint , this.toPoint );
                   agentPath.FillMode = FillMode.Winding;
                  

                   gControlPanle.DrawPath(pColor, agentPath);
}
Posted
Comments
BillWoodruff 8-Feb-14 10:40am    
To begin to understand what you are doing, I'd need to know where Points 'fromPoint and 'toPoint come from, and see the code for 'DrawPath.

Is it the case that user selects a certain PictureBox and moves it within your ContainerControl/Form and you draw lines based on its movement ?
Muhammad Tufail 1979 8-Feb-14 15:46pm    
thank you so much on your kind reply.
Actually i have 4 pictures , and want to move it. from one point ( fromPoint) to another point (toPoint) each pictures movement is control by separate thread. during this execution i choose these points according to my criteria. Now each thread put picture in the picturebox and then i start moving by changing the left and top position of picturebox by 5.
my problem is... that the line successfully drawn by every picturebox ( picture) but when any of these picturebox comeback on the same root or cross the path of another picture so it wipe up ( delete ) that path. i dont know how to permanent draw the path so that by the movement of any other picturebox should not delete.
Muhammad Tufail 1979 8-Feb-14 16:12pm    
i also did try to take a bitmap image and keep it as a background image of the control. then every thread of picture should take a clone of this picture , draw it self picturebox at specific postion and to make it again the background image, but the problem comes that " the object already in used" by another process. i don't know how to remove this problem??
i also did try to use only one picture for background image every small picture( from 4) should draw on it and to move every one and do the process. but then the problem comes that when one make a clone of background image so it also contains other 3 pictures and thus it makes a continues track of all the 4 pictures. ( a long trail)
BillWoodruff 9-Feb-14 9:28am    
Sorry, Muhammad, I am afraid I cannot visualize what you are trying to achieve here. I am not clear if the user of your application moves PictureBoxes, or if they are moved by your application automatically when certain conditions are met. And, I am not clear exactly how the lines are drawn.

1 solution

If you want to draw on control, why would you draw on a bitmap (which of course you can do)?

You main mistake is using CreateGraphics. Of course, you can do it, too, but this is not what you want, to successfully get animated, interactive, or even static graphics. You need to use instance of System.Drawing.Graphics passed to the method System.Windows.Forms.Control.OnPaint you can override, or, alternatively to your event handle of the event System.Windows.Forms.Control.Paint. For further detail, please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

For some a bit more advanced topics, such as threading with graphics, please see also these two:
How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^].

—SA
 
Share this answer
 

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