[Gtk-sharp-list] don't able to repaint

Franz Burgmann franz.burgmann@web.de
Sat, 03 Jan 2004 09:52:25 +0100


hi all,

I'm trying now for a few hours to get a little animation running, but 
the only thing I see is the result. The steps before will not be brought 
to screen.

Somebody an idea?

Thanks


using Gtk;
using GtkSharp;
using System;
using System.Threading;

class Animation {
   
    Window win;
    HBox hbox;
    Button[] buttons;
    Gdk.Color black, red;
   
    Animation() {
       
        black = new Gdk.Color( 0, 0, 0 );
        red = new Gdk.Color( 200, 0, 0 );
       
        win = new Window( "" );
        win.Resize( 300, 60 );
        win.DeleteEvent += new DeleteEventHandler( OnWinDelete );
               
        Start();
    }
 
//Start()
    void Start() {
       
        Random r = new Random();
        int k = 0;
        while( k < 20 ) {
            int pos = 0;
            int posNew;
            do {
                posNew = r.Next( 0, 10 );
            } while( pos == posNew );
            pos = posNew;
           
            buttons = null;
            buttons = new Button[ 10 ];
            for( int i = 0; i < 10; i++ ) {
                buttons[ i ] = new Button();
                buttons[ i ].Sensitive = false;
            }                 
           
            for( int i = 0; i < 10; i++ ) {
                if( i == pos ) {
                    buttons[ i ].ModifyBg( StateType.Insensitive, red );
                }
                else {
                    buttons[ i ].ModifyBg( StateType.Insensitive, black );
                }
            }
            Paint();
            Thread.Sleep( 100 );
            k++;
        }           
    }
   
//Paint()
    void Paint() {
       
        if( hbox != null ) {
            win.Remove( hbox );
            hbox = null;
        }
        hbox = new HBox( true, 0 );
        for( int i = 0; i < 10; i++ ) {
            hbox.PackStart( buttons[ i ] );
        }
       
        win.Add( hbox );
        win.ShowAll();      
       
    }
   
//OnWinDelete()
    void OnWinDelete( object s, DeleteEventArgs a ) {
        Application.Quit();
    }
  
//Main()
    static void Main() {
        Application.Init();
        new Animation();
        Application.Run();
    }
}