我现在把 splitContainer1 控件分成了
1 2 两个区(一行两列)
由于在程序运行的时候 
1 2 这两个区是可以随意改变的
我怎么得到 2 这个区左上角相对于显示器左上角的左边

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication22
    {
        public partial class Form1 : Form
        {
            Point P1, P2;        public Form1()
            {
                InitializeComponent();
            }        private void splitContainer1_Panel1_Resize(object sender, EventArgs e)
            {
                P1 = splitContainer1.Panel1.PointToScreen(new Point(0, 0));
                this.Text = "panel1 - (x:" + P1.X + ",y:" + P1.Y + ") panel2 - (x:" + P2.X + ",y:" + P2.Y+")"; 
            }        private void splitContainer1_Panel2_Resize(object sender, EventArgs e)
            {
                P2 = splitContainer1.Panel2.PointToScreen(new Point(0, 0));
                this.Text = "panel1 - (x:" + P1.X + ",y:" + P1.Y + ") panel2 - (x:" + P2.X + ",y:" + P2.Y + ")";
            }        private void Form1_Move(object sender, EventArgs e)
            {
                P1 = splitContainer1.Panel1.PointToScreen(new Point(0, 0));
                P2 = splitContainer1.Panel2.PointToScreen(new Point(0, 0));
                this.Text = "panel1 - (x:" + P1.X + ",y:" + P1.Y + ") panel2 - (x:" + P2.X + ",y:" + P2.Y + ")"; 
            }
        }
    }
      

  2.   

    建议用:
    int left = this.splitContainer1.PointToScreen(new Point(this.splitContainer1.Panel2.Left, this.splitContainer1.Panel2.Top)).X;也可以用(这种方法可能有些误差,因为控件边界宽度问题):
    int left = 0;
    Control parentControl = this.splitContainer1.Panel2;
    while (parentControl != null)
    {
        left += parentControl.Left;
        parentControl = parentControl.Parent;
    }