2011-09-10 2 views
1

こんにちはみんなは、すべてがうまく、私は、次の(苦労)疑問に思ってドロップFlowLayoutPanel上に

あるホープ:

は、私は私が誰の上に画像ボックスのいずれかを移動することができるようにしたい5 flowLayoutPanelsと5 PictureBoxesを持っています私が行っている

- 実行時にFLPとは、私は時間のためにそれにされて、現在は病気の私のプライドを飲み込むまし

....レイアウトパネルがFLP.controls.Add()に追加してい次のように動作させるには、ここで手動でwhiを指定する必要がありますCH PixBoxは、FLPと交差し、私は文

Private Sub cpbPic1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cpbPic1.MouseUp 
    If (flpDock1.HasChildren = False) Then 'Test to see if panel is filled 
     If CBool(CustomPictureBox.IntersectingObjects(cpbPic1, flpDock1)) Then 
      flpDock1.Controls.Add(cpbPic1) 'Add Pic to Panel 
    End If 
End Sub 

CPB場合25はいけない:CustomPictureBox

+1

これは何をドラッグ&ドロップが行うことにしましたが、うまく.NETでサポートされているがallowdropを有効にする必要があります –

答えて

1

あなたは常にこの操作を行うことができます:

Private Sub cpbPic1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cpbPic1.MouseUp, cpbPic2.MouseUp, cpbPic3.MouseUp,cpbPic4.MouseUp,cpbPic5.MouseUp 
    If Not flpDock1.HasChildren Then 'Test to see if panel is filled 
     If CBool(CustomPictureBox.IntersectingObjects(TryCast(sender,CustomPictureBox), flpDock1)) Then 
      flpDock1.Controls.Add(TryCast(sender,CustomPictureBox)) 'Add Pic to Panel 
    End If 
End Sub 

これはコードの量を削減するあなたがよ大幅に書く必要がありますが、私がここで行ったように、イベントハンドラがフラグを立てるオブジェクトを渡すという事実をどのように利用するかについて考えるなら、この量をさらに減らすことができます。

はまた、あなたがいる限り、彼らが同じイベント

+0

あなたの素早い応答をありがとう - しかし、私が間違っている場合は私を修正します - "e"はオブジェクトではありませんEventArgs - .netはあなたがコンパイルすることを許可しません(私が間違っている場合は私を修正します) しかし、キャスト送信者 - しかし、私はcpbに戻ってきます –

+0

私はそれをしようとしました、平均をキャストする - 。ネットは私にそれをすることを許可しませんでした。しかし、病気はそれを強く続ける –

+0

*******私は言及するのを忘れているかもしれません。********** cpb.IntersectingObejctsは、何かが交差するかどうかをチェックするCPBクラス内の共有関数です - おそらく私はFLPクラスのために同じことをする必要があります –

1

を上げると、ハンドラ内のオブジェクトの任意の大きな量(と思う)を使用することができるだけでなく、これはあなたがやりたいことのために回避することができます。 あなたもflowpanelsに(私の悪い英語のため申し訳ありませんが)これはあなたを助けること

Private Function FindControl(ByVal ControlName As String, ByVal CurrentControl As Control) As Control 
' get the control you need 
    Dim ctr As Control 
    For Each ctr In CurrentControl.Controls 
     If ctr.Name = ControlName Then 
      Return ctr 
     Else 
      ctr = FindControl(ControlName, ctr) 
      If Not ctr Is Nothing Then 
       Return ctr 
      End If 
     End If 
    Next ctr 
End Function 

Private Sub me_DragEnter(sender As Object, e As DragEventArgs) Handles FLP1.DragEnter,FLP2.DragEnter,FLP3.DragEnter 
' call the copy effect 
    If (e.Data.GetDataPresent(DataFormats.Text)) Then 
     e.Effect = DragDropEffects.Copy 
    End If 
End Sub 
Private Sub me_DragDrop(sender As Object, e As DragEventArgs) Handles FLP1.DragDrop,FLP2.DragDrop,FLP3.DragDrop 
' get the FLp you're gonna drop the control onto 
    Dim c As control =FindControl(e.Data.GetData(DataFormats.Text), me) 
    sender.Controls.Add(c) 
    end sub 


    Private Sub Pictureboxs_MouseDown(sender As Object, e As MouseEventArgs) Handles Label1.MouseDown, PB.MouseDown 
    sender.DoDragDrop(sender.Name, DragDropEffects.Copy) 

End Sub 

希望:)

関連する問題