[Mono-list] Windows.Forms Controls Drawing

Robert Jordan robertj at gmx.net
Thu Dec 11 14:26:59 EST 2008


Hi,

Phillip N. wrote:
> Hello all,
> 
> Im writing a program with Windows Forms, and got a problem i have no
> solution jet.
> Im attaching the files related.
> 
> The problems are:
> 
> 1.- You can see two "Agents" in forms. They are transparent in the sense
> that you can see the form background below them. But the are not
> transparent with each other. Just move them so one get below the other.
> In the real version, im drawing much more than two Agents, and the
> probability of a overlap is high... 
> How can i make them transparent to each other too?

WinForms does not support this. It supports transparency
between the control and its parent only if there is no other
control inbetween, which happens if you move the images over
each other.

> 2.- When you move the agents after moving the Window, the movement start
> to be not correct (it starts moving from another point in the form). Is
> this a bug in my application?

Try this:

		Point lastMousePosition;

		protected override void OnMouseDown (MouseEventArgs e)
		{
			if (e.Button != MouseButtons.Left)
				return;

			this.BringToFront();
			tip.Show("Move it!",this, e.Location);
			lastMousePosition = e.Location;
			mouseDown = true;
		}

		protected override void OnMouseMove (MouseEventArgs e)
		{
			if (mouseDown) {
				int diffX = e.X - lastMousePosition.X;
				int diffY = e.Y - lastMousePosition.Y;
				// set Left & Top at once
				Location = new Point (Left + diffX, Top + diffY);
			}
		}

Robert



More information about the Mono-list mailing list