views:

40

answers:

1

Hi all, 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 with 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);
            }   
      }
+1  A: 

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

Gerrie Schenck
I would like to use WPF (already tried), but got the idea that it would things only more complicated, since it started to bother me with Threading issues almost instantly.Any tutorial or examplecode I can look into is welcome.As far as I found out, there are like 10000 ways te do something similar, but thats only more confusing to a WPF newbie like myself
SirLenz0rlot
Thanks a lot, at least I now know what to look for. I'll post my solution as soon as i have it
SirLenz0rlot
I think this is gonna work out well for me! thanks for helping out the newbie :)
SirLenz0rlot