有两个form,想在form1调用form2里,将form2显示在form1中textbox的下方form1里的button1.click里调用form2Form2 frm = new Form2();
Form2.show();
//这里如何控制form2的显示位置,在form1里的某个控件之下,或者
显示在form1中某个控件相同的位置

解决方案 »

  1.   

    Form2 frm = new Form2();
    Form2.show();
    panel.Controls.Add(frm);
    设置location
      

  2.   

    public Form2(int x,int y){
    this.location=new Point(x,y);
    InitializeComponent();
    } Form1调用时:
    int x=this.Location.X;
    int y=this.Location.Y+this.Size.Height;
    Form2 f2=new Form2(x,y);
    f2.show();
    另外需要把Form2的StartPosition设置为Manual
      

  3.   

    补充,如果想显示在某个控件的下方只需要更改为
    int x=this.Location.X+this.控件名.Location.X;
    int y=this.Location.Y+this.控件名.Location.Y+this.控件名.Size.Height;
      

  4.   

    对LOCATION进行编程咯,把位置计算好就可以了。
      

  5.   

    location 是相对于它的容器的吧?如果form1 是Mdi 子窗体,的控件是在form1 的某个panel内的int x=this.Location.X+this.控件名.Location.X;
    int y=this.Location.Y+this.控件名.Location.Y+this.控件名.Size.Height;这样的location定位不到控件那里
      

  6.   

    晕,这么简单的问题:
    先把Form的TextBox1控件的Modifiers属性设置为publicForm1:
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2(this);
                f2.Show();
            }
    Form2:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication2
    {
        public partial class Form2 : Form
        {
            Form1 f1 = new Form1();
            public Form2(Form1 frm1)
            {
                f1 = frm1;
                InitializeComponent();        }        private void Form2_Load(object sender, EventArgs e)
            {
                this.Left = f1.textBox1.Left + f1.Left;
                this.Top = f1.textBox1.Top+ f1.textBox1.Height+f1.Top;
            }
        }
    }
      

  7.   

    那就直接
    窗体.Top+控件.Top
      

  8.   

    呵呵,再给你个MDI的方法。
    其余代码不变,把调用时的代码改为:
    Point p=this.控件.PointToScreen(this.控件.Location);
    int x=p.X;
    int y=p.Y+this.控件.Size.Height;
    这个是把控件坐标转换成屏幕坐标,所以就不需要考虑容器问题了。
      

  9.   

    能不能详细说下你窗体的结构?我测试用的是父窗体Form3,子窗体是上面的Form1,可以实现效果。
      

  10.   

    解决了,如下即可
    form2.location = this.控件.PointToScreen(0,this.控件.height);