Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a picture box in wpf.
code is ..
HTML
<DockPanel Height="237">
                           <WindowsFormsHost Height="237">
                               <wf:PictureBox x:Name="LiveImage" MouseDown="LiveImage_MouseDown"/>
                           </WindowsFormsHost>
                       </DockPanel>


C#
private void LiveImage_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
       {

           if (IsCropFrame)
           {
               try
               {

                   CropPicture = new PictureBox();
                   CropPicture.CreateControl();
                   CropPicture.Width = 132;
                   CropPicture.Height = 170;
                   CropPicture.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

                   cropPen = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);
                   LiveImage.CreateGraphics().DrawRectangle(cropPen, cropX, cropY, 132, 170);
                   IsCropFrame = false;
                   CropPicture.MouseDown += new System.Windows.Forms.MouseEventHandler(CropPicture_MouseDown);
                   CropPicture.MouseMove += new System.Windows.Forms.MouseEventHandler(CropPicture_MouseMove);
                   CropPicture.MouseUp += new System.Windows.Forms.MouseEventHandler(CropPicture_MouseUp);

                   //if (e.Button == MouseButtons.Left)
                   //{
                   //    //var dragImage = new Bitmap((Bitmap)picBox.Image, picBox.Size);
                   //    var dragImage = (Bitmap)CropPicture.Image;
                   //    IntPtr icon = dragImage.GetHicon();
                   //   // Cursor.Current = new Cursor(icon);
                   //   DoDragDrop(CropPicture.Image, DragDropEffects.Copy);
                   //    SystemDLL.User32.DestroyIcon(CropPicture);
                   //}

               }
               catch (Exception ex)
               {
               }
           }
           else
           {
           }
       }>

C#
private void CropPicture_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    dragging = true;
    dragPoint = new System.Drawing.Point(e.X, e.Y);
}
private void CropPicture_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (dragging)
        CropPicture.Location = new System.Drawing.Point(CropPicture.Location.X + e.X - dragPoint.X, CropPicture.Location.Y + e.Y - dragPoint.Y);
}
private void CropPicture_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
    dragging = false;
}

None of mouse events of CropPicture box is occurred.


Now I want to drag a CropPicture box in another place of LiveImage picture box.
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900