2007年6月8日金曜日

booでDnD

IronPythonでDnDをbooでまねしてみる。
さすがにあんまり変わらんかな。

namespace DnD

import System
import System.Collections
import System.Drawing
import System.Windows.Forms
import System.Windows.Forms.DragDropEffects
import System.Windows.Forms.DataFormats

class MainForm(System.Windows.Forms.Form):
    def constructor():
        InitializeComponent()

    private components as System.ComponentModel.IContainer = null
   
    protected override def Dispose(disposing as bool):
        if disposing:
            if components is not null:
                components.Dispose()
        super(disposing)
   
    def InitializeComponent():
        self.listBox1 = System.Windows.Forms.ListBox()
        self.SuspendLayout()
        #
        # listBox1
        #
        self.listBox1.AllowDrop = true
        self.listBox1.Dock = System.Windows.Forms.DockStyle.Fill
        self.listBox1.FormattingEnabled = true
        self.listBox1.ItemHeight = 12
        self.listBox1.Location = System.Drawing.Point(0, 0)
        self.listBox1.Name = "listBox1"
        self.listBox1.Size = System.Drawing.Size(292, 268)
        self.listBox1.TabIndex = 0
        self.listBox1.DragEnter += self.ListBox1DragEnter as System.Windows.Forms.DragEventHandler
        self.listBox1.DragDrop += self.ListBox1DragDrop as System.Windows.Forms.DragEventHandler
        #
        # MainForm
        #
        self.AutoScaleDimensions = System.Drawing.SizeF(6, 12)
        self.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        self.ClientSize = System.Drawing.Size(292, 271)
        self.Controls.Add(self.listBox1)
        self.Name = "MainForm"
        self.Text = "MainForm"
        self.ResumeLayout(false)

    private listBox1 as System.Windows.Forms.ListBox
   
    private def ListBox1DragEnter(sender as object, e as System.Windows.Forms.DragEventArgs):
        if e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop):
            e.Effect = DragDropEffects.All
        else:
            e.Effect = DragDropEffects.None
   
    private def ListBox1DragDrop(sender as object, e as System.Windows.Forms.DragEventArgs):
        data = e.Data.GetData(DataFormats.FileDrop, false) as (string)
        for s in data:
            print self.listBox1.Items.Add(s)

[STAThread]
def Main(argv as (string)):
    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(false)
    Application.Run(MainForm())



0 件のコメント:

コメントを投稿