I'm quite new to drawing shapes, graphics, bitmaps etc. I googled for a few days,but still havent got a real clue what to do, so please help me:
I want to draw a floorplan wit开发者_StackOverflow中文版h certain objects(represented as circles) moving on it. When I click on a object, it needs to show something.
So far, I ve been able to draw some circles on a graphic and been able to move the dots by clearing the graphic every time. Ofcourse, this isnt a real solution, since I cant keep track of the different objects on the floorplan (which i need for my clickevent and movings).
I hope I explained my problem ok here.
This is the (stripped version of the) sourcecode that gets called every second: (dev (of type Device) is the object i want to draw)
Graphics gfx = FloorplanTabPage.CreateGraphics();
gfx.Clear(Color.White);
foreach (Device dev in _deviceList)
{
Pen myPen = new Pen(Color.Black) { Width = 10 };
if(dev.InRoom != null)
{
myPen.Color = Color.DarkOrchid;
int x = dev.InRoom.XPos + (dev.InRoom.Width / 2) - 5;
int y = (dev.InRoom.YPos + (dev.InRoom.Height / 2) - 5;
if (dev.ToRoom != null)
{
x = (x + (dev.ToRoom.XPos + (dev.ToRoom.Width / 2)) / 2;
y = (y + (dev.ToRoom.YPos + (dev.ToRoom.Height / 2)) / 2;
}
gfx.DrawEllipse(myPen, x, y, 10, 10);
gfx.DrawString(dev.Name, new Font("Arial", 10), Brushes.Purple, x, y - 15);
}
}
I think the easiest solution is to use WPF for this.
If you do not want to use WPF, then I suggest writing your own custom winforms control for each object you want on your floorplan, drawing a circle when the control paints itself. This will give you full control of how the control looks and behaves.
UPDATE: there are plenty of tutorials on this, for example http://www.codeproject.com/KB/miscctrl/ScrollingTextControlArtic.aspx
精彩评论