Exemple #1
0
        private object findControl(int x, int y)
        {
            //Point newPoint = this.PointToScreen(new Point(x, y));
            //POINT windowPoint = POINT.FromPoint(newPoint);
            POINT  windowPoint = new POINT(x, y);
            IntPtr found       = NativeUtils.WindowFromPoint(windowPoint);

            // we have a valid window handle
            if (found != IntPtr.Zero)
            {
                // give it another try, it might be a child window (disabled, hidden .. something else)
                // offset the point to be a client point of the active window
                if (NativeUtils.ScreenToClient(found, ref windowPoint))
                {
                    // check if there is some hidden/disabled child window at this point
                    IntPtr childWindow = NativeUtils.ChildWindowFromPoint(found, windowPoint);
                    if (childWindow != IntPtr.Zero)
                    { // great, we have the inner child
                        found = childWindow;
                    }
                }

                object c = Control.FromHandle(found);

                /*if (c is MenuStrip)//MenuStrip继承自ToolStrip
                 * {
                 *  MenuStrip m = c as MenuStrip;
                 *  c = m.GetItemAt(windowPoint.ToPoint());
                 * }
                 * else*/if (c is ToolStripDropDownMenu)
                {
                    ToolStripDropDownMenu m = c as ToolStripDropDownMenu;
                    c = m.GetItemAt(windowPoint.ToPoint());
                }
                else if (c is ToolStrip)
                {
                    ToolStrip m = c as ToolStrip;
                    c = m.GetItemAt(windowPoint.ToPoint());
                }

                return(c);
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
 protected override void WndProc(ref Message m) {                
   if (m.Msg == 0x202&&!letClicked) {//WM_LBUTTONUP = 0x202
        int x = m.LParam.ToInt32() & 0x00ff;
        int y = m.LParam.ToInt32() >> 16;
        ToolStripItem item = ts.GetItemAt(new Point(x, y));                    
        //check if the first item (the Print Button) is clicked
        if (item != null && ts.Items.IndexOf(item) == 0) {
          if (MessageBox.Show("Do you want to print?", "Print confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
              return;//discard message
          else {
                 letClicked = true;
                 item.PerformClick();
           }
         }
    }
    base.WndProc(ref m);
    if (letClicked) letClicked = false;
 }
Exemple #3
0
        public static ToolStripItem GetItemAtDeep(this ToolStrip toolstrip, Point screenPos)
        {
            if (!toolstrip.Visible)
            {
                return(null);
            }

            Point         toolStripLocalPos = toolstrip.PointToClient(screenPos);
            ToolStripItem item = toolstrip.GetItemAt(toolStripLocalPos);

            if (item != null)
            {
                return(item);
            }

            ToolStripDropDownItem dropItem = toolstrip.GetActiveDropDown();

            if (dropItem != null)
            {
                return(dropItem.DropDown.GetItemAtDeep(screenPos));
            }

            return(null);
        }
        public static ToolStripItem GetItemAtDeep(this ToolStrip t, Point screenPos)
        {
            if (!t.Visible)
            {
                return(null);
            }

            Point         toolStripLocalPos = t.PointToClient(screenPos);
            ToolStripItem item = t.GetItemAt(toolStripLocalPos);

            if (item != null)
            {
                return(item);
            }

            ToolStripDropDownItem dropItem = t.Items.OfType <ToolStripDropDownItem>().FirstOrDefault(i => i.DropDown.Visible);

            if (dropItem != null)
            {
                return(dropItem.DropDown.GetItemAtDeep(screenPos));
            }

            return(null);
        }
Exemple #5
0
 private void mainToolStrip_MouseEnter(object sender, EventArgs e)
 {
     ToolStrip       ts  = ((ToolStrip)sender);
     ToolStripButton tsb = (ToolStripButton)ts.GetItemAt(395, 792);
 }