LEADTOOLS ナレッジベース

[RasterImageViewer] ドラッグ&ドロップに対応していますか?

RasterImageViewerコントロールでは、AllowDropプロパティをTrueに設定することによりドラッグ&ドロップを利用して画像を表示することができます。

以下は、RasterImageViewer1からRasterImageViewer2へドラッグ&ドロップして画像を表示するサンプルです。

サンプルコード(VB.NET)

Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.WinForms

Public Class Form1

    Dim codecs As RasterCodecs

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        codecs = New RasterCodecs

        RasterImageViewer1.Image = codecs.Load("test.jpg")
        RasterImageViewer1.SizeMode = RasterPaintSizeMode.Fit
        RasterImageViewer2.SizeMode = RasterPaintSizeMode.Fit

        RasterImageViewer2.AllowDrop = True
    End Sub

    Private Sub RasterImageViewer1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RasterImageViewer1.MouseDown
        RasterImageViewer1.DoDragDrop(RasterImageViewer1.Image, DragDropEffects.All)
    End Sub

    Private Sub RasterImageViewer2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RasterImageViewer2.DragDrop
        RasterImageViewer2.Image = e.Data.GetData(DataFormats.Serializable, True)
    End Sub

    Private Sub RasterImageViewer2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RasterImageViewer2.DragEnter
        e.Effect = DragDropEffects.All
    End Sub
End Class

サンプルコード(C#)

using Leadtools;
using Leadtools.Codecs;
using Leadtools.WinForms;

public class Form1
{
   
    RasterCodecs codecs;
   
    private void Form1_Load(object sender, System.EventArgs e)
    {
        codecs = new RasterCodecs();
       
        rasterImageViewer1.Image = codecs.Load("test.jpg");
        rasterImageViewer1.SizeMode = RasterPaintSizeMode.Fit;
        rasterImageViewer2.SizeMode = RasterPaintSizeMode.Fit;

        rasterImageViewer2.AllowDrop = true;
    }
   
    private void rasterImageViewer1_MouseDown(object sender, MouseEventArgs e)
    {
        rasterImageViewer1.DoDragDrop(rasterImageViewer1.Image, DragDropEffects.All);
    }

    private void rasterImageViewer2_DragDrop(object sender, DragEventArgs e)
    {
        rasterImageViewer2.Image = (Leadtools.RasterImage)e.Data.GetData(DataFormats.Serializable, true);
    }

    private void rasterImageViewer2_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.All;
    }
}

0 コメント

記事コメントは受け付けていません。