标题:c# winfrom panel 的mouseleave怎么用啊
只看楼主
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
得分:0 
透明不是用这个panel1.Visible = false;

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-09-24 17:09
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
得分:0 
看看行不行..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MouseMoveAndMouseLeave
{
   
public partial class Form1 : Form
   
{
        
private bool isMouseInPanel;
        
private bool isMouseInButton;
        
public event EventHandler OnMouseLeavePanelRegion;

        
public Form1()
        
{
            
InitializeComponent();
            
this.panel1.BorderStyle = BorderStyle.Fixed3D;
            
this.isMouseInButton = true;
            
this.isMouseInPanel = false;

            
this.panel1.MouseLeave += new EventHandler(panel1_MouseLeave);
            
this.panel1.MouseEnter += new EventHandler(panel1_MouseEnter);
            
this.button1.MouseEnter += new EventHandler(button1_MouseEnter);
            
this.button1.MouseLeave += new EventHandler(button1_MouseLeave);
            
this.OnMouseLeavePanelRegion += new EventHandler(Form1_OnMouseLeavePanelRegion);
        
}

      
void button1_MouseLeave(object sender, EventArgs e)
        
{
            
this.isMouseInButton = false;
        
}

        
void Form1_OnMouseLeavePanelRegion(object sender, EventArgs e)
        
{
            
if (!this.isMouseInButton && !this.isMouseInPanel)
            
{
               
this.panel1.Visible = false;
            
}
        
}

        
void button1_MouseEnter(object sender, EventArgs e)
        
{
            
this.isMouseInButton = true;
        
}

        
void panel1_MouseEnter(object sender, EventArgs e)
        
{
            
this.isMouseInPanel = true;
            
this.OnMouseLeavePanelRegion(null, null);
        
}

        
void panel1_MouseLeave(object sender, EventArgs e)
        
{
            
this.isMouseInPanel = false;
            
this.OnMouseLeavePanelRegion(null, null);
        
}

   
}
}

 
2009-09-24 17:21
zhwbo123789
Rank: 2
等 级:论坛游民
帖 子:25
专家分:23
注 册:2009-3-23
得分:0 
呵呵 谢谢12楼的 要的就是这效果
2009-09-24 17:28
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
得分:0 
那个有问题..

换个方法试试

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace MouseMoveAndMouseLeave
{
   
public partial class Form1 : Form
   
{
        
private bool isMouseInPanel;
 
        
public Form1()
        
{
            
InitializeComponent();
            
this.panel1.BorderStyle = BorderStyle.Fixed3D;
            
this.isMouseInPanel = false;
            
this.panel1.MouseEnter += new EventHandler(panel1_MouseEnter);
        
}
 
        
void panel1_MouseEnter(object sender, EventArgs e)
        
{
            
this.MouseEnter += new EventHandler(Form1_MouseEnter);
        
}
 
        
void Form1_MouseEnter(object sender, EventArgs e)
        
{
            
this.panel1.Visible = false;
        
}
   
}
}
收到的鲜花
  • zhwbo1237892009-09-28 09:01 送鲜花  3朵   附言:我很赞同
2009-09-24 17:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-286661-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028603 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved