Tip Customized PictureBox with dynamic movement using mouse

We welcome your tips on the forum here for others to learn from. Thank you for your contributions ahead.
 
Hello, and welcome to the forums.

Do you think you could add your code from your video tutorials to the forums (enclosed in code tags) as well. This would help other users to copy and paste the code you've used. Otherwise you are only forcing them to write out the code step by step as it is demonstrated in your video. Which is rather inconvenient.
 
@TechTips: Can you explain the significance of declaring a constructor that takes an IContainer as a parameter? If it is important, that means that your base PictureBox should have also implemented it, yet, you are not calling the base class to pass the container to it as well.

Also it would help if you explain why for the mouse down event, you don't care which button was pressed when you store the current mouse location, but for the mouse move event, you only care about the left mouse button.

A suggestion:
C#:
this.Left += e.X - location.X;
this.Top += e.Y - location.Y;
can be re-written simply as:
C#:
Location += (Size)e.Location - (Size)location;
Both do the same thing, but the latter makes it obvious that you are computing the delta between the current mouse location (e.Location) and the point where the mouse button was first pressed (location), and then applying that delta to the current bitmap Location. The cast to Size is to take advantage of Point's explicit conversion as well as its support for using the addition and subtraction operators.
 
Last edited:
Back
Top Bottom