0

I am moving pictureboxes on a Form1 via left-clicking on them and dragging them to another position. (i.e., using mousemove, mousedown, mouseup with e.X and e.Y). I also connect lineshapes from one picturebox to another using drag and drop. When dragging the end of a lineshape, however, I don't show the end of the lineshape when it's over a picture box -- indicating that it's ok to drop on a given picturebox.

Question is, after moving pictureboxes to desired positions, there are times when the end of a dragged lineshape disappears over a "ghost" or remnant of a picturebox, which is no longer there. Apparently, the control positions need to be updated any time I move a picturebox. So, after I move pictureboxes around, is there some sort of refresh I need to do on the Form1's controls, so the positions of pictureboxes are updated?

  • 1
    What is a *connecting lineshape*? Can you post some code that can reproduce this behavior? Anyway, try calling `Me.Invalidate(true)` (specifying a region, if it flickers too much) after a drop. Or refresh the Form (more flickering). I'm not really sure what your problem/context is, so... – Jimi Dec 29 '19 at 18:02
  • Solved the issue. The lineshape end was skipping over default pictureboxes sitting on Form1 at design time, which are set to invisible at run time. So I basically filtered on the the names of new pictureboxes added and it solved the issue. Lineshapes are lines that can be drawn on a Form without custom graphics commands; they are part of the Microsoft VBPowerPacks ShapeControls. –  Dec 29 '19 at 18:43

1 Answers1

0

Yes you need to make custom class that inherits panel/picturebox class and at constructor level you need to say me.doublebuffered=true to prevent shadow of dragging picturebox/panel

Also at your code in mouse moving event you need to subtract the current coordinates of the panel from your cursor coordinates to have the image near your cursor

Rosh
  • 11
  • 2
  • I already do the subtracting, since, yes, the control's X,Y will not keep up with the e.X and e.Y of the mouse if not. Not sure about Me.DoubleBuffered=True, as I have never used that -- so will give it a try. I commonly use double buffering for data tables and datagrids. –  Dec 29 '19 at 19:13