有两个form,想在form1调用form2里,将form2显示在form1中textbox的下方form1里的button1.click里调用form2Form2 frm = new Form2();
Form2.show();
//这里如何控制form2的显示位置,在form1里的某个控件之下,或者
显示在form1中某个控件相同的位置
Form2.show();
//这里如何控制form2的显示位置,在form1里的某个控件之下,或者
显示在form1中某个控件相同的位置
解决方案 »
- 一个公共的CS类,如何动态的给它提供参数
- 急问!谁用过sqlite数据库或者其他小型数据库,VB.NET有没有这方面的框架可用呢?
- 求解,web.config设置为StateServer,如何对在线用户进行统计(含用户名)?
- windows live api 登录 获取个人信息 求解
- 用文本编辑器空格变成了问号~
- 在WINFORM中,我想用DataGrid控件绑定数据库中某一个表,但是没找到属性生成器,请问怎么绑定啊?
- C#下如何保护文件不被删除或修改(包括改名和内容改写)
- 。NET组件中找不到 microsoft.web.ui.webcontrols,怎么办啊?
- 问个OdbcDataReader 的小问题.......
- VS2010开发的程序无法在其他电脑运行
- WPF ComboBox 这种效果怎么实现 分不多就100
- 这VS2008的BUG吗
Form2.show();
panel.Controls.Add(frm);
设置location
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
int x=this.Location.X+this.控件名.Location.X;
int y=this.Location.Y+this.控件名.Location.Y+this.控件名.Size.Height;
int y=this.Location.Y+this.控件名.Location.Y+this.控件名.Size.Height;这样的location定位不到控件那里
先把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;
}
}
}
窗体.Top+控件.Top
其余代码不变,把调用时的代码改为:
Point p=this.控件.PointToScreen(this.控件.Location);
int x=p.X;
int y=p.Y+this.控件.Size.Height;
这个是把控件坐标转换成屏幕坐标,所以就不需要考虑容器问题了。
form2.location = this.控件.PointToScreen(0,this.控件.height);