title: TextBoxButton click event
body: <p>I use flowing code to create TextBoxButton Control . when I write code in " TextBoxButton_Click" void at main class , it work fine. but when I drag this custom control on form , how can manage click event when I double click on this control ? how can determine user clicked textbox or button that inside textbox?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace CustomControl
  {
      public class TextBoxButton : TextBox
      {
          [System.Runtime.InteropServices.DllImport("user32.dll")]
          private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
  
          public Button mbutton;
          public Button button
          {
              get { return mbutton; }
              set { this.mbutton = value; }
          }
          protected override void OnCreateControl()
          {
              this.Controls.Add(this.mbutton);
              SetRightToLeft();
              base.OnCreateControl();
          }
          private void SetRightToLeft()
          {
              if (RightToLeft == RightToLeft.Yes)
              {
                  mbutton.Dock = DockStyle.Left;
              }
              else
              {
                  mbutton.Dock = DockStyle.Right;
              }
          }
          protected override void OnRightToLeftChanged(EventArgs e)
          {
              SetRightToLeft();
              base.OnRightToLeftChanged(e);
          }
          public TextBoxButton()
          {
              mbutton = new Button();
              mbutton.Width = 20;
              mbutton.Cursor = Cursors.Hand;
              mbutton.Click += TextBoxButton_Click;
              // Send EM_SETMARGINS to prevent text from disappearing underneath the button
              SendMessage(Handle, 0xd3, (IntPtr)2, (IntPtr)(mbutton.Width &lt;&lt; 16));
  
          }
  
          private void TextBoxButton_Click(object sender, EventArgs e)
          {
                        }
      }
  }
  </code></pre>