タイトル : Re^4: ドラッグアンドドロップで悩んでいます・・・ 投稿日 : 2006/01/16(Mon) 22:29 投稿者 : 花ちゃん
他にいい方法があるかも知れませんが(クリップボードのフォーマットを追加する等) カラー値を文字型に変換して渡してやれば比較的簡単です。 (ColorTranslator で変換して下さい) Form にPictureBox を2個貼り付けて下記のコードを試して見て下さい。 Private Sub PictureBox1_MouseDown(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown PictureBox2.AllowDrop = True PictureBox1.DoDragDrop(ColorTranslator.ToWin32( _ PictureBox1.BackColor).ToString, DragDropEffects.Copy) End Sub Private Sub PictureBox2_DragDrop(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop Dim col As Integer = Integer.Parse(e.Data.GetData(DataFormats.Text, True)) PictureBox2.BackColor = ColorTranslator.FromWin32(col) PictureBox2.AllowDrop = False End Sub Private Sub PictureBox2_DragEnter(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter If e.Data.GetDataPresent(DataFormats.Text) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub |