C# Creating and manipulating images inside an image

Fonzy

Newcomer
Joined
Dec 14, 2004
Messages
2
Hi, Can anyone give an example or point me in the direction on how I can create an app which has a main picturebox, then on a button press it creates an image inside the picture box which can then be moved. Also when the mouse hovers over the image inside the picturebox it brings up a tooltip. Oh and the ability to move the images after they are in place.

Thanks.
 
Sounds like you would add pictures to the inside of a picturebox by doing something like:

PictureBix PBx = new PictureBox
'set properties.
MainPB.Controls.Add(PBx)

Then, you would use the Dragging events of the picturebox so that you can drag the picture around inside of the picturebox, DragEnter, DragOver, DragLeave, and DragDrop.
.DoDragDrop starts the DragDrop process.

I'm sure you know how to use a tooltip, but you can get one from the toolbox and experiment with it. :)
They're pretty easy to use if you haven't used them yet.
 
I've just started out in c# so am still learning its querks. I used to use java so its not all that different. Thanks to your advice ive put another picturebox in a main picturebox.

My idea is to have a button which creates several pictureboxs inside a main picturebox and stores them in a collection object, if there is such a thing. The next thing is how do you write an event handler to allow dragging and dropping of pictureboxes that are created at runtime? And how does it identify which picturebox is being selected?

The event handlers for objects seems hard coded, eg

Code:
private void picturebox_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
		{
			// do something
		}

or does sender have which object is being dragged?
 
The first thing you do is start the DragDrop operation.

From my drag drop sample article:

Set your destination's .AllowDrop to True
In your source's Mousedown, call its .DoDragDrop event.
In the destination's .DragEnter event, check for .GetDataPresent and set the e.Effect.
In the .DragDrop event, it is done!

:)
Tutorial is in VB.NET at XVBT, but here it is: http://www.xtremevbtalk.com/showthread.php?t=164308
 
Back
Top