2017-05-21 8 views
0

Monoで小さなアプリケーションを開発しています。私はバックグラウンドにイメージを持ちたいと思っています。そして、ウィンドウサイズが変化しているときは常にイメージを再描画しなければなりません。しかし、ExposeEventまたはConfigureEventのためのメソッドを追加すると、アプリケーションが落ちます。それは何でしょうか?ここで あなたはbgstreamオープンを維持するが、ストリームの巻き戻しをしていない私のコード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の番号を追加する必要があります。その後、configureイベントが働く必要があります。

0

あり、多分それは、物事をクラッシュ?

また、クラッシュの完全なスタックトレースを投稿してください。

+0

アプリケーションがコンパイルされて正常に実行されるようになりましたが、ConfigureEventは単にDrawBGメソッドを起動しません。 –

関連する問題