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? 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? Thanks in advance! PD: gmcs -r:System.Windows.Forms -r:System.Drawing *.cs ... -- Phillip N. <[EMAIL PROTECTED]>
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Text;
namespace ThreadFormProblem
{
public class Agent : Control
{
Image img = Image.FromFile("Libre.png");
Point offset;
ToolTip tip = new ToolTip();
bool mouseDown = false;
Point mouseOffset;
public Agent(int x, int y)
{
Size = img.Size;
offset = new Point(Size.Width/2-5, Size.Height/2-5);
Position = new Point(x,y);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
BackColor = Color.Transparent;
}
//center of the object...
public Point Position
{
get {return new Point(Location.X+offset.X, Location.Y + offset.Y);}
set { Location = new Point(value.X-offset.X, value.Y-offset.Y); }
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(img, 0,0);
e.Graphics.DrawString("Hello!",Font ,Brushes.Green,10,10,StringFormat.GenericTypographic);
e.Graphics.DrawRectangle(Pens.Green, offset.X, offset.Y, 7,7);
}
protected override void OnMouseDown (MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
this.SendToBack();
tip.Show("Move it!",this, e.Location);
mouseOffset.X = -e.X - SystemInformation.FrameBorderSize.Width;
mouseOffset.Y = -e.Y - SystemInformation.FrameBorderSize.Height - SystemInformation.FrameBorderSize.Height;
mouseDown = true;
}
protected override void OnMouseUp (MouseEventArgs e)
{
mouseDown=false;
tip.Hide(this);
}
protected override void OnMouseMove (MouseEventArgs e)
{
if (mouseDown)
{
Point pos = Control.MousePosition;
pos.Offset(mouseOffset);
Position = pos;
}
}
}
}
<<attachment: Libre.png>>
using System;
using System.Windows.Forms;
namespace ThreadFormProblem
{
class MainClass
{
Window w = new Window();
public void Run()
{
Application.EnableVisualStyles();
Application.Run(w);
}
public static void Main(string[] args)
{
MainClass m = new MainClass();
m.Run();
}
}
}using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
namespace ThreadFormProblem
{
public class Window : Form
{
Random r = new Random();
List<Agent> l = new List<Agent>();
public Window()
{
for (int i=0; i<2; i++)
{
int x = (int) (Width* r.NextDouble());
int y = (int) (Height* r.NextDouble());
l.Add(new Agent(x,y));
Controls.Add(l[i]);
}
BackColor = Color.Blue;
}
protected override void OnResize (EventArgs e)
{
this.Invalidate();
}
}
}
_______________________________________________ Mono-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-list
