[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Letting a click fall through

Posted on 2006-11-28
2
Medium Priority
?
292 Views
Last Modified: 2010-04-16
I have a UserControl with a PictureBox control on it (Docking set to FILL) and then on that PictureBox I have another PictureBox.

How can I let a MouseDown event on either PictureBox fall through to the UserControl, such that the UserControl can respond to the MouseDown?
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
sabeesh earned 2000 total points
ID: 18034293
YOu have to write a delegate to trap the mouse down event
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 18050404
Can you give me an example?

Here is my MainForm source:


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.PictureBox pictureBox1;
            private System.Windows.Forms.PictureBox pictureBox2;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            private int startX, startY;
            private int startGPX, startGPY;
            private WindowsApplication2.GamePiece gamePiece1;
            private WindowsApplication2.GamePiece gamePiece2;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.pictureBox1 = new System.Windows.Forms.PictureBox();
                  this.pictureBox2 = new System.Windows.Forms.PictureBox();
                  this.gamePiece1 = new WindowsApplication2.GamePiece();
                  this.gamePiece2 = new WindowsApplication2.GamePiece();
                  this.SuspendLayout();
                  //
                  // pictureBox1
                  //
                  this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                  this.pictureBox1.Location = new System.Drawing.Point(104, 80);
                  this.pictureBox1.Name = "pictureBox1";
                  this.pictureBox1.TabIndex = 0;
                  this.pictureBox1.TabStop = false;
                  //
                  // pictureBox2
                  //
                  this.pictureBox2.BackColor = System.Drawing.SystemColors.ActiveCaption;
                  this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                  this.pictureBox2.Location = new System.Drawing.Point(328, 216);
                  this.pictureBox2.Name = "pictureBox2";
                  this.pictureBox2.TabIndex = 1;
                  this.pictureBox2.TabStop = false;
                  this.pictureBox2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseUp);
                  this.pictureBox2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseMove);
                  this.pictureBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseDown);
                  //
                  // gamePiece1
                  //
                  this.gamePiece1.Location = new System.Drawing.Point(320, 128);
                  this.gamePiece1.Name = "gamePiece1";
                  this.gamePiece1.Size = new System.Drawing.Size(40, 40);
                  this.gamePiece1.TabIndex = 5;
                  //
                  // gamePiece2
                  //
                  this.gamePiece2.Location = new System.Drawing.Point(144, 184);
                  this.gamePiece2.Name = "gamePiece2";
                  this.gamePiece2.Size = new System.Drawing.Size(40, 40);
                  this.gamePiece2.TabIndex = 6;
                  this.gamePiece2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.gamePiece2_MouseUp_1);
                  this.gamePiece2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.gamePiece2_MouseMove_1);
                  this.gamePiece2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.gamePiece2_MouseDown_1);
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(504, 334);
                  this.Controls.Add(this.gamePiece2);
                  this.Controls.Add(this.gamePiece1);
                  this.Controls.Add(this.pictureBox2);
                  this.Controls.Add(this.pictureBox1);
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.Load += new System.EventHandler(this.Form1_Load);
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void pictureBox2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        pictureBox2.Location = new Point(pictureBox2.Left + e.X - startX, pictureBox2.Top + e.Y - startY);
                  }

            }

            private void pictureBox2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        startX = e.X;
                        startY = e.Y;
                  }

            }

            private void pictureBox2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        Rectangle pb1 = new Rectangle(pictureBox1.Location, pictureBox1.Size);
                        Rectangle pb2 = new Rectangle(pictureBox2.Location, pictureBox2.Size);
                        if (pb1.IntersectsWith(pb2))
                        {
                              //MessageBox.Show("Overlapping");
                              pictureBox2.Location = pictureBox1.Location;
                        }
                        else
                        {
                              //MessageBox.Show("NOT Overlapping");
                        }
                  }

            }

            private void Form1_Load(object sender, System.EventArgs e)
            {
            
            }

            private void gamePiece2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        Rectangle pb1 = new Rectangle(this.gamePiece1.Location, this.gamePiece1.Size);
                        Rectangle pb2 = new Rectangle(this.gamePiece2.Location, this.gamePiece2.Size);
                        if (pb1.IntersectsWith(pb2))
                        {
                              //MessageBox.Show("Overlapping");
                              this.gamePiece2.Location = this.gamePiece1.Location;
                        }
                        else
                        {
                              //MessageBox.Show("NOT Overlapping");
                        }
                  }            
            }

            private void gamePiece2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        startGPX = e.X;
                        startGPY = e.Y;
                  }
            }

            private void gamePiece2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        this.gamePiece2.Location = new Point(this.gamePiece2.Left + e.X - startGPX, this.gamePiece2.Top + e.Y - startGPY);
                  }
            }

            private void gamePiece2_MouseUp_1(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        Rectangle pb1 = new Rectangle(this.gamePiece1.Location, this.gamePiece1.Size);
                        Rectangle pb2 = new Rectangle(this.gamePiece2.Location, this.gamePiece2.Size);
                        if (pb1.IntersectsWith(pb2))
                        {
                              //MessageBox.Show("Overlapping");
                              this.gamePiece2.Location = this.gamePiece1.Location;
                        }
                        else
                        {
                              //MessageBox.Show("NOT Overlapping");
                        }
                  }
            }

            private void gamePiece2_MouseMove_1(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        this.gamePiece2.Location = new Point(this.gamePiece2.Left + e.X - startGPX, this.gamePiece2.Top + e.Y - startGPY);
                  }
            }

            private void gamePiece2_MouseDown_1(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  if (e.Button == MouseButtons.Left)
                  {
                        this.gamePiece2.Location = new Point(this.gamePiece2.Left + e.X - startGPX, this.gamePiece2.Top + e.Y - startGPY);
                  }
            }

            
      }
}




Here is my UserControl source:

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace WindowsApplication2
{
      /// <summary>
      /// Summary description for GamePiece.
      /// </summary>
      public class GamePiece : System.Windows.Forms.UserControl
      {
            private System.Windows.Forms.PictureBox pictureBoxImage;
            private System.Windows.Forms.PictureBox pictureBoxHealth;
            private System.Windows.Forms.ToolTip toolTipInfo;
            private System.ComponentModel.IContainer components;

            public GamePiece()
            {
                  // This call is required by the Windows.Forms Form Designer.
                  InitializeComponent();

                  // TODO: Add any initialization after the InitializeComponent call

            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if(components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Component Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.components = new System.ComponentModel.Container();
                  this.pictureBoxImage = new System.Windows.Forms.PictureBox();
                  this.pictureBoxHealth = new System.Windows.Forms.PictureBox();
                  this.toolTipInfo = new System.Windows.Forms.ToolTip(this.components);
                  this.SuspendLayout();
                  //
                  // pictureBoxImage
                  //
                  this.pictureBoxImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                  this.pictureBoxImage.Location = new System.Drawing.Point(0, 0);
                  this.pictureBoxImage.Name = "pictureBoxImage";
                  this.pictureBoxImage.Size = new System.Drawing.Size(32, 32);
                  this.pictureBoxImage.TabIndex = 0;
                  this.pictureBoxImage.TabStop = false;
                  this.pictureBoxImage.MouseHover += new System.EventHandler(this.pictureBoxImage_MouseHover);
                  //
                  // pictureBoxHealth
                  //
                  this.pictureBoxHealth.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                  this.pictureBoxHealth.Location = new System.Drawing.Point(4, 24);
                  this.pictureBoxHealth.Name = "pictureBoxHealth";
                  this.pictureBoxHealth.Size = new System.Drawing.Size(20, 5);
                  this.pictureBoxHealth.TabIndex = 1;
                  this.pictureBoxHealth.TabStop = false;
                  //
                  // GamePiece
                  //
                  this.Controls.Add(this.pictureBoxHealth);
                  this.Controls.Add(this.pictureBoxImage);
                  this.Name = "GamePiece";
                  this.Size = new System.Drawing.Size(40, 40);
                  this.Load += new System.EventHandler(this.GamePiece_Load);
                  this.ResumeLayout(false);

            }
            #endregion

            private void GamePiece_Load(object sender, System.EventArgs e)
            {
                  this.toolTipInfo.SetToolTip(this.pictureBoxHealth,"Health");
                  this.toolTipInfo.SetToolTip(this.pictureBoxImage,"My name is Tom");
            }

            private void pictureBoxImage_MouseHover(object sender, System.EventArgs e)
            {
                  //this.toolTipInfo.
            }
      }
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question