最近做C/S.有个问题想请教各位有经验的。
一个大的picturebox1里面添加一个小的子控件picturebox2 。当picturebox1的mouse_enter时显示picturebox2,mouse_leave的时候picturebox2不可见。
问题是如何当picturebox1进入时让picturebox2获得焦点并且可以执行点击事件呢?
小女子第一次发帖,希望能有积极的回应!!谢谢大家啦!
一个大的picturebox1里面添加一个小的子控件picturebox2 。当picturebox1的mouse_enter时显示picturebox2,mouse_leave的时候picturebox2不可见。
问题是如何当picturebox1进入时让picturebox2获得焦点并且可以执行点击事件呢?
小女子第一次发帖,希望能有积极的回应!!谢谢大家啦!
pictureBox2.BringToFront();
使之处于最上方,不用时,再调用:
pictureBox2.SendToBack();
不就可以了吗?
如果还不行,加我好友好了,或者发邮件到:
[email protected]
我也在做类似的界面。
况且我是现在可见的状态下和点击的动作中执行pictruebox2的事件。
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
this.pictureBox2.Visible = true;
pictureBox2_Click(sender, e);
} private void pictureBox2_Click(object sender, EventArgs e)
{
if (this.pictureBox2.Visible==false)
{
this.pictureBox1.Focus();
}
} private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.pictureBox2.Visible = false;
}在BOX2的CLICK事件里加断点,自己看看,是不是要这样的效果
pictureBox1_MouseLeave事件
这样就不会出现冲突了
{
this.pictureBox2.Visible = true;
} private void pictureBox2_MouseEnter(object sender, EventArgs e)
{
this.pictureBox2.Visible = true;
} private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.pictureBox2.Visible = false;
}
我那一个人也没
都过去看看http://topic.csdn.net/u/20100416/10/db615811-504d-4ff7-a1fe-6cee172d9973.html?82211
补充一点 。pictureBox1和pictureBox2都是动态添加的。
难道这个问题就没有人能解决么? 是不是我的想法太勉强了??!
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
this.pictureBox2.Visible = true;
pictureBox2_Click(sender, e);
} private void pictureBox2_Click(object sender, EventArgs e)
{
if (this.pictureBox2.Visible==false)
{
this.pictureBox1.Focus();
} this.pictureBox1.MouseLeave += new EventHandler(pictureBox1_MouseLeave);
} private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.pictureBox2.Visible = false;
this.pictureBox1.MouseLeave -= new EventHandler(pictureBox1_MouseLeave);
}这样呢
这是我的代码 pb2代表picturebox2,pb代表picturebox1.就是点击事件进不去?还请帮忙找出问题所在。 pb2.MouseEnter += new EventHandler(pb2_MouseEnter);
pb2.Click += new EventHandler(pbView_Click); pb.MouseEnter += new EventHandler(pb_MouseEnter);
pb.MouseLeave += new EventHandler(pb_MouseLeave); private void pbView_Click(object sender, EventArgs e)
{
MessageBox.Show("click");
}
private void pb_MouseEnter(object sender, EventArgs e)
{
PictureBox pbView = ((PictureBox)sender);
if (pbView.Controls.Count == 0) return;
pbView.Controls[0].Visible = true;
}
private void pb_MouseLeave(object sender, EventArgs e)
{
PictureBox pbView = ((PictureBox)sender);
if (pbView.Controls.Count == 0) return;
pbView.Controls[0].Visible = false;
}
private void pb2_MouseEnter(object sender, EventArgs e)
{
PictureBox pbView = ((PictureBox)sender);
pbView.Visible = true;
}
{
PictureBox pbView = ((PictureBox)sender);
if (pbView.Controls.Count == 0) return;
pbView.Controls[0].Visible = true;
}这段代码有些问题。 你可以把一个picturebox嵌入到另一个pciturebox里面?
你试一下
{
PictureBox pbView = ((PictureBox)sender);
pbView.Visible = true;
}
//改成
private void pb2_MouseEnter(object sender, EventArgs e)
{
pb.MouseLeave += new EventHandler(pb_MouseLeave);
PictureBox pbView = ((PictureBox)sender);
pbView.Visible = true;
}当然 前边就不要在注册pb鼠标离开事件了
{
this.pb.MouseEnter += new EventHandler(pb_MouseEnter);
this.pb2.Click += new EventHandler(pb2_Click);
} void pb_MouseEnter(object sender, EventArgs e)
{
pb2.Visible = true;
this.pb.MouseEnter -= pb_MouseEnter;
} void pb_MouseLeave(object sender, EventArgs e)
{
this.pb.MouseEnter += pb_MouseEnter;
pb2.Visible = false;
this.pb.MouseLeave -= pb_MouseLeave;
} void pb2_Click(object sender, EventArgs e)
{
MessageBox.Show("ae");
this.pb.MouseLeave += pb_MouseLeave; }
在方法 private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
.................
}里加个判断,判断鼠标的当前位置是不是还在pictureBox1的显示范围内,如果是就一直让pictureBox2显示,反之就让pictureBox2隐藏,这样当鼠标从pictureBox1进入pictureBox2时,pictureBox2就不会失去焦点
确实可以点击picturebox2的点击事件 但是pictbox1的移入移出又有问题了……
// Determines if the mouse points to a ListViewItem.
Point clientMousePoint = this.PointToClient(currentMousePoint);
if (this.pictureBox1.Bounds.Contains(clientMousePoint))
{
this.pictureBox2.Visible = true;
}
else
this.pictureBox2.Visible = false;
{
this.pictureBox2.Visible = true;
pictureBox2_Click(sender, e);
} private void pictureBox2_Click(object sender, EventArgs e)
{
if (this.pictureBox2.Visible==false)
{
this.pictureBox1.Focus();
}
} private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.pictureBox2.Visible = false;
}
看看实在身事件里面额啊