110,534
社区成员
发帖
与我相关
我的任务
分享
void but_MouseHover(object sender, EventArgs e)
{
Button bu = sender as Button;
int x = this.Location.X + bu.Location.X - f6.Width;
int y = this.Location.Y + bu.Location.Y + f6.Height - bu.Height - 25;
f6.Location = new Point(x, y);
f6.Lable1 = bu.Text;
f6.Show();
this.Activate();//少了这句会使当前窗体失去焦点补上去
}
public partial class Form5 : Form
{
public Form5()
{
//InitializeComponent();
this.SuspendLayout();
//
// Form5
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(144, 398);
this.Name = "Form5";
this.Text = "Form5";
this.Load += new System.EventHandler(this.Form5_Load);
this.ResumeLayout(false);
}
Form6 f6 = new Form6();
private void Form5_Load(object sender, EventArgs e)
{
f6.Show();
f6.Hide();
for (int i = 0; i < 5; i++)
{
Button but = new Button();
but.Location = new Point(50, i * 100);
but.Size = new Size(50, 50);
but.Text = "文本" + i;
but.MouseHover += new EventHandler(but_MouseHover);
but.MouseLeave += new EventHandler(but_MouseLeave);
this.Controls.Add(but);
}
}
void but_MouseLeave(object sender, EventArgs e)
{
f6.Hide();
}
void but_MouseHover(object sender, EventArgs e)
{
Button bu = sender as Button;
int x = this.Location.X + bu.Location.X - f6.Width;
int y = this.Location.Y + bu.Location.Y + f6.Height - bu.Height - 25;
f6.Location = new Point(x, y);
f6.Lable1 = bu.Text;
f6.Show();
}
public partial class Form6 : Form
{
Label label1 = new Label();
public Form6()
{
InitializeComponent();
label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
}
public string Lable1
{
set { label1.Text = value; }
}
}