Haris Bogdanovi wrote:
> Hi.
> I'm trying to paint in DC context:
> 
> # ---------------------------------------------------
> 
> frame = Frame.new(nil, -1, "")
> 
> frame.paint { |dc|
> 
>     dc.draw_line(50, 50, 100, 100)                                #  for
> this I don't see the line
> 
>     dc.draw_bitmap(Bitmap.new('c:\img.bmp'),0,0)        # and for this
> program crashes
> 
> }
> 
> # -----------------------------------------------------------
> 
> Does anyone know why is this happening ?
> 
> Thanks.

It appears to me that you cannot draw on a DC before the window is 
created. The following shows nothing with Ruby 1.9 on my Ubuntu Jaunty 
machine:

=======================================
#!/usr/bin/env ruby
#Encoding: UTF-8
require "wx"

class GUI < Wx::App
  include Wx

  def on_init
    @mainwindow = Frame.new(nil, -1, "Test", DEFAULT_POSITION, 
Size.new(400, 400))

    @mainwindow.paint{|dc| dc.draw_line(0, 0, 100, 100)}

    @mainwindow.show
  end

end

x = GUI.new
x.main_loop
=======================================

But if you use the #paint method after the window has been created, 
everything works fine:

=======================================
#!/usr/bin/env ruby
#Encoding: UTF-8
require "wx"

class GUI < Wx::App
  include Wx

  def on_init
    @mainwindow = Frame.new(nil, -1, "Test", DEFAULT_POSITION, 
Size.new(400, 400))

    Timer.after(2000){@mainwindow.paint{|dc| dc.draw_line(0, 0, 100, 
100)}}

    @mainwindow.show
  end

end

x = GUI.new
x.main_loop
=======================================

Marvin
-- 
Posted via http://www.ruby-forum.com/.