I am creating a fixed size, windows form to be used as a tooltip, because I needs to control 'Opacity', that a regular tooltip does not allow. The issue I am having is that the form does correctly appear near my mouse pointer when hovering over the grid, but occasionally I see it flash very briefly outside the grid client area. It mostly happens when I first start the hover action. The flash is the result of the form momentarily appearing in the top left corner of the monitor outside of my client area. Any thoughts on why the form briefly appears outisde of the client area?
Code:
private void BidGrid_MouseMove(object sender, MouseEventArgs e) { try { // Hover code if (EnableTooltips) ShowHoverForm(BidGrid, new Point(e.X, e.Y), BidRowDictionary, true); } catch (Exception ex) { MessageBox.Show("Exception BidGrid_MouseMove :" + ex.Message); } } private void ShowHoverForm(BufferedDataGridView grid, Point mouseCoordinates, Dictionary<string, Lev2Order> dictionary, bool isBid) { DataGridView.HitTestInfo hit = grid.HitTest(mouseCoordinates.X, mouseCoordinates.Y); if (hit.RowIndex != -1) { if(hoverForm == null) hoverForm = new HoverForm(); if(isBid) hoverForm.Location = PointToScreen(new Point(mouseCoordinates.X + 10, mouseCoordinates.Y + 40)); else hoverForm.Location = PointToScreen(new Point(AskGrid.Left + mouseCoordinates.X + 10, mouseCoordinates.Y + 40)); hoverForm.ForeColor = gridLayout.HoverTooltipColor.TextColour; hoverForm.BackColor = gridLayout.HoverTooltipColor.BackGroundColour; hoverForm.Opacity = Convert.ToDouble(gridLayout.HoverOpacity/100); //Confirm the new location is within the lev2 bounds Rectangle rect = new Rectangle(this.PointToScreen(new Point(0, 0)), this.Size); if (rect.Contains(hoverForm.Location.X, hoverForm.Location.Y)) { Trace.WriteLine("Hover location within lev2 bounds"); hoverForm.Show(); } else Trace.WriteLine("Hover location OUTSIDE lev2 bounds"); } else { if(hoverForm != null) { hoverForm.Close(); hoverForm = null; } } }
Comment