2016-08-18 3 views
0

나는 monodevelop/C#/gdk를 조금 실험하고 있는데, 노출 이벤트를 올바르게 처리하고있는 DrawingArea을 가진 윈도우를 만들 수 있었다.왜`ButtonPressEvent`가 나오지 않는가

그러나 마우스 다운 이벤트는 발송되지 않으며 이유를 이해할 수 없습니다. 대표단은 GUI 디자이너에 의해 자동 생성 코드에서 설정 한 :

this.da.ExposeEvent += new global::Gtk.ExposeEventHandler (this.OnDAExposeEvent); 
this.da.ButtonPressEvent += new global::Gtk.ButtonPressEventHandler (this.OnDAButtonPressEvent); 
this.da.MotionNotifyEvent += new global::Gtk.MotionNotifyEventHandler (this.OnDAMotionNotifyEvent); 

이 내 초기화 코드 :

public MainWindow() : base (Gtk.WindowType.Toplevel) 
    { 
     Build(); 
     Gdk.Color col = new Gdk.Color(); 
     col.Red = col.Green = col.Blue = 0x8888; 
     da.ModifyBg(StateType.Normal, col); 
     var p = "wr/wn/wb/wq/wk/wp/br/bn/bb/bq/bk/bp".Split ('/'); 
     for (int i = 0; i < p.Length; i++) { 
      pieces[p[i]] = new ImageSurface("/home/agriffini/x/chessboard/i" + p [i] + ".png"); 
     } 
     da.Events |= (Gdk.EventMask.ButtonPressMask 
         | Gdk.EventMask.ButtonReleaseMask 
         | Gdk.EventMask.KeyPressMask 
         | Gdk.EventMask.PointerMotionMask); 
    } 

라는 결코 극복 핸들러 함수 OnDAButtonPressEvent이 (중단 점을 배치하여 확인하지만 그곳에).

누락 된 부분은 무엇입니까?

답변

0

콘솔 출력을보고 문제를 발견했습니다.

위젯이 실현되기 전에 이벤트 마스크를 설정해야한다는 것이 문제입니다.

이것은 monodvelop와 gui 디자이너를 사용할 때 자동 생성 된 Build 메서드가 실현되기 전에 적절한 시간에 이벤트 마스크를 설정하므로 widget-> properties-> events에서 gui를 사용하여 설정해야한다는 것을 의미합니다.

Build을 호출하기 전에 이벤트 마스크를 코드에 설정하면 작동하지 않습니다 (위젯은 아직 생성되지 않았습니다). 그 호출 후에도 마스크를 설정하지 않으면 (이미 실현되었습니다).

관련 문제