C#.NET 中 我先是启动了一个Form1,然后在Form1里面有个Button, 点击一下。又启动了Form2(我是让Form2和Form1对齐的,紧挨着Form1 this.Left =f1.Left+f1.Width;
this.Top=f1.Top;)。现在我想让Form1永远成为焦点,而且在拖动或是最小化或是关闭Form1时,Form2也随之变化,Form2永远跟着Form1 ,永远紧挨着他,在没关掉Form1之前事关不掉Form2的,我应该如何做呢,请大侠帮忙
this.Top=f1.Top;)。现在我想让Form1永远成为焦点,而且在拖动或是最小化或是关闭Form1时,Form2也随之变化,Form2永远跟着Form1 ,永远紧挨着他,在没关掉Form1之前事关不掉Form2的,我应该如何做呢,请大侠帮忙
private void Form1_LocationChanged(object sender, EventArgs e)
{ }
然后把FORM2的动作写到里面
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{
public partial class Form1 : Form
{
Form2 f2 = new Form2();
int y;
Rectangle rect;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
y = this.Location.X + this.Width;
rect = new Rectangle(y, this.Location.Y,300, 300);
f2.StartPosition = FormStartPosition.Manual;
f2.Bounds = rect;
f2.Show();
} private void Form1_Move(object sender, EventArgs e)
{ Rectangle R2=new Rectangle (this.Location.X +this .Width ,this .Location.Y,300,300);
f2.Bounds = R2;
this.Focus(); }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.Hide ();
}
else
{
}
}
}
}
保你行,积分全给我吧,不行找我,给你大包发送。
欢迎大家来的我博客
http://blog.csdn.com/csdbfans
楼主的要求估计得需要在form1中鼠标拖动和windows消息里进行处理吧.