hakeの日記

Windows環境でプログラミングの勉強をしています。

ファイル選択 その2

VisualuRubyの勉強 その5

VRCommonDialogをインクルードして、openFilenameDialogを使用する方法もあった。こっちだとファイル以外のダイアログも簡単に呼べそう。

require 'vr/vruby'
require 'vr/vrcontrol'

class MyForm < VRForm

include VRCommonDialog

  def construct
    self.caption = 'form1'
    self.move(137,124,500,400)
    addControl(VRButton,'button1',"file",320,72,48,25)
    addControl(VREdit,'edit1',"",48,72,256,25)
  end 

  def button1_clicked
    file = openFilenameDialog([["すべて","*.*"],["Ruby Script","*.rb"]])
#   file = SWin::CommonDialog::openFilename(self,[["すべて","*.*"],["Ruby Script","*.rb"]])

    @edit1.text = file if file
  end
end 

VRLocalScreen.start(MyForm)