有如下要求,在Form1中有許多Button,現在是new Form2時,Form2的show位置要緊靠Button,Button位置不同Form2的位置就不同,而不是WindowsDefaultBounds,CenterParent,CenterScreen,Manual之類。
有辦法嗎?

解决方案 »

  1.   

    Form2 f = new Form2();
    f.Location = Button.Location;
      

  2.   

    use "Control.PointToScreen" method
      

  3.   

    嗯Control.PointToScreen
    +
    Control.Location
    +
    Control.Size
      

  4.   

    Form2 f = new Form2();
                Point p = this.PointToScreen(button1.Location);     
                p.X = p.X +  button1.Width;
                p.Y = p.Y + button1.Height; 
                f.StartPosition = FormStartPosition.Manual; 
                f.SetDesktopBounds(p.X, p.Y, f.Width, f.Height);   
               f.ShowDialog(this);