2013-05-31 30 views
2

我的表單有一個GroupBbox MouseEvents的問題。GUI GroupPanel MouseEvents

我試圖做一些圖形用戶界面gadgetries(對接,不透明..)。

下面是一個例子:

Picute

我已經鏈接的所有(GUI)-Objects這兩個功能。

private void MyMouseMove(object sender, MouseEventArgs e) 
{ 
    this.Opacity = 1; 
} 

private void MyMouseLeave(object sender, EventArgs e) 
{ 
    this.Opacity = 0.5; 
} 

..expect組板,因爲他們沒有MouseMoveMouseLeave事件。他們可以添加嗎?標準面板也有它們。

我真的很喜歡該GroupPanels(帶有邊框和文本)的佈局,這就是爲什麼我希望能夠用GroupBox解決這個問題。

我創建的小工具只有在光標位於表單之外時纔會被觸發。 (如果不活躍或活躍,則無關緊要)。也許有另外一種方法來觸發它,比MouseMoveMouseLeave

+0

所以,你要當用戶進入/離開某個組框更改透明度? –

+1

GroupPanels,又名GroupBoxes,確實有這些鼠標事件。問題是當鼠標進入GroupBox的子控件之一時,它會觸發MouseLeave事件。使用計時器可能是最好的解決方案,請參閱[Winform - 確定鼠標是否已經離開用戶控制](http://stackoverflow.com/a/425361/719186)。 – LarsTech

回答

0

使用定時器可能是最簡單的解決方案!
謝謝LarsTech鏈接到這個 'Winform - determine if mouse has left user control'問題。

我能夠繼續我的項目與下面的這個示例。

public partial class Form1 : Form 
{ 
    private Timer timer1; 
    public Form1() 
    { 
     InitializeComponent(); 
     this.Opacity = 0.5D; 
     timer1 = new Timer(); 
     timer1.Interval = 200; 
     timer1.Tick += timer1_Tick; 
     timer1.Enabled = true; 
    } 

    private void timer1_Tick(object sender, EventArgs e) 
    { 
     if (this.DesktopBounds.Contains(Cursor.Position)) 
      this.Opacity = 1D; 
     else 
      this.Opacity = 0.5D; 
    } 
} 

學分轉到:Hans Passant