2017-05-21 20 views
0

Mono에서 약간의 작업을하고 있습니다. 창 크기가 바뀔 때마다 이미지가 다시 그려지기를 원합니다. 그러나 ExposeEvent 또는 ConfigureEvent 응용 프로그램에 대한 메서드를 추가하면 응용 프로그램이 떨어집니다. 그것은 무엇일까요? 다음은 일을 충돌 어쩌면, 내 코드EventHandler를 추가 한 후 GTK # 응용 프로그램이 작동을 멈 춥니 다.

using System; 
using System.IO; 
using Gtk; 

public partial class AuthWind: Gtk.Window 
{ 
    FileStream bgstream; 
    public AuthWind() : base (Gtk.WindowType.Toplevel) 
    { 
     bgstream = File.Open ("noise-texture.png", System.IO.FileMode.Open); 
     Build(); 
     HBox mainCont = new HBox (false, 0); 
     ConfigureEvent += DrawBG; 
     Gdk.Pixbuf bgbuf = new Gdk.Pixbuf(bgstream, this.Allocation.Width, this.Allocation.Height); 
     Gdk.Pixmap bgmap = null; 
     Gdk.Pixmap useless = null; 
     bgbuf.RenderPixmapAndMask (out bgmap, out useless, 0); 
     Style st = new Style(); 
     st.SetBgPixmap (StateType.Normal, bgmap); 
     this.Style = st; 
    } 

    void DrawBG(object obj, EventArgs e) 
    { 
     Gdk.Pixbuf bgbuf = new Gdk.Pixbuf(bgstream, this.Allocation.Width, this.Allocation.Height); 
     Gdk.Pixmap bgmap = null; 
     Gdk.Pixmap useless = null; 
     bgbuf.RenderPixmapAndMask (out bgmap, out useless, 0); 
     Style st = new Style(); 
     st.SetBgPixmap (StateType.Normal, bgmap); 
     this.Style = st; 
    } 

    protected void OnDeleteEvent (object sender, DeleteEventArgs a) 
    { 
     Application.Quit(); 
     a.RetVal = true; 
    } 
} 

답변

0

긴 검색 후 해결책을 찾았습니다. 먼저 pixbuf는 한 번 만들어 져서 클래스 변수로 저장되어야합니다. 그런 다음 이벤트 처리기에서 ScaleSimple 메서드를 사용해야합니다. Pixbuf 클래스의 메서드입니다. 이 방법은 pixbuf의 크기를 조정하고 필요한 너비와 높이로 새로운 것을 만듭니다. 이벤트에 관해서 ... 작업하고자하는 윈도우에 Gdk.Event의 번호를 추가해야합니다. 그 후 구성 이벤트가 작동해야합니다.

0

당신은 bgstream가 열려 유지하지만 스트림을 되감기되지 않습니다입니까?

또한 충돌에 대한 전체 스택 추적을 게시하십시오.

+0

이상하게 들릴지 모르지만 응용 프로그램이 컴파일되고 정상적으로 실행되지만 ConfigureEvent는 단지 DrawBG 메서드를 시작하지 않습니다. –