我正在做一个UML类图分析器。
当我已经把语法分析的结果存在于一条链表中,现在我要逐步分析链表中信息,存在的问题是:
如何在界面上显示类似于Enterprise  Architect 那样的矩形框,里面包含了文字的信息,而且以移动会把文字和矩形框全部移动。
那在生成位图是先生成一个矩形,然后再在矩形中绘制文字么? 然后拖动又是什么原理呢

解决方案 »

  1.   

    public class TextRectangle : Control
        {        [System.Runtime.InteropServices.DllImport("user32.dll")]
            public static extern int ReleaseCapture();
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            public static extern int SendMessage(IntPtr hWnd, uint uMsg, uint wParam, uint lParam);
            public const uint WM_SYSCOMMAND = 0x112;
            public const uint SC_MOVE = 0xF012;
            protected override void OnPaint(PaintEventArgs e)
            {
                Rectangle rect=Bounds;
                e.Graphics.FillRectangle(Brushes.AliceBlue, rect);
                e.Graphics.DrawRectangle(Pens.Black, rect);
                e.Graphics.DrawString(Text, Font, Brushes.Blue, rect.Location);
            }
            protected override void OnMouseMove(MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Left)
                {
                    base.OnMouseMove(e);
                    return;                
                }
                ReleaseCapture();
                SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE, 0);
            }
        }一个简单的例子,LZ可以改成更多的Shape
      

  2.   

    OnPaint里面两句写错了,应该是
                e.Graphics.FillRectangle(Brushes.AliceBlue, 0, 0, rect.Width, rect.Height);
                e.Graphics.DrawRectangle(Pens.Black, 0, 0, rect.Width - 1, rect.Height - 1);
      

  3.   

    UML类图的各个图形代表什么意思?