一般窗体的位置如何确定,如何设置窗体的显示位置。
继承自DockContent的窗体的位置如何获取呢?
对于继承自DockContent的窗体,下面几个API并不能取得正确的结果。
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int Left;        // x position of upper-left corner
            public int Top;         // y position of upper-left corner
            public int Right;       // x position of lower-right corner
            public int Bottom;      // y position of lower-right corner
        }        [DllImport("User32.dll")]
        private static extern bool ClientToScreen(IntPtr hwnd, ref Point lpPoint); 

解决方案 »

  1.   

    StartPosition属性,我记得好象有四个枚举
      

  2.   

    直接取得窗体的 top值和left值就可以了,用不着api
      

  3.   

    API函数  SetWindowPos 设置窗体显示位置GetWindowRect是得到窗体在桌面上 矩形
    ClientToScreen将指定客户区 坐标  转换成 桌面坐标
      

  4.   


    top,left是相对于父窗口的位置,设置owner属性为某个窗口,并不能表示此窗口是父窗口。还有继承自weifenluo的DockContent的窗口这些表示位置的属性都没有什么用处。
      

  5.   

    C#中所有控件包括窗体都有类似于PointToClient、PointToScreen的方法,是专门用于一系列坐标的变换操作的,比方说:从屏幕坐标变换到控件坐标或者是容器坐标等等,楼主不妨一试~
      

  6.   

    继承自weifenluo的DockContent的控件的任何Form拥有的表示位置的值都是0,0。