public static Point GetPosition() { var w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); return new Point(w32Mouse.X, w32Mouse.Y); }
public static IntPoint GetCursorPos() { Win32Point position = new Win32Point(0, 0); NativeMethods.GetCursorPos(ref position); return new IntPoint(position.x, position.y); }
public static int[] GetMousePosition() { Win32Point w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); int[] pos = new int[2]; pos[0] = w32Mouse.X; pos[1] = w32Mouse.Y; return pos; }
/// <summary> /// Returns the mouse cursor location. This method is necessary during /// a drag-drop operation because the WPF mechanisms for retrieving the /// cursor coordinates are unreliable. /// </summary> /// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param> public static Point GetMousePosition(Visual relativeTo) { Win32Point mouse = new Win32Point(); GetCursorPos(ref mouse); // Using PointFromScreen instead of Dan Crevier's code (commented out below) // is a bug fix created by William J. Roberts. Read his comments about the fix // here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx return relativeTo.PointFromScreen(new Point((double)mouse.X, (double)mouse.Y)); }
public static Point ScreenToClient(FrameworkElement element, IntPoint point) { PresentationSource source = PresentationSource.FromVisual(element); Win32Point winPt = new Win32Point(point.X, point.Y); NativeMethods.ScreenToClient(((HwndSource)source).Handle, ref winPt); Point offset = source.CompositionTarget.TransformFromDevice.Transform(new Point(winPt.x, winPt.y)); return source.RootVisual.TransformToDescendant(element).Transform(offset); }
public static IntPoint ClientToScreen(FrameworkElement element, Point point) { PresentationSource source = PresentationSource.FromVisual(element); point = element.TransformToAncestor(source.RootVisual).Transform(point); Point offset = source.CompositionTarget.TransformToDevice.Transform(new Point(point.X, point.Y)); Win32Point winPt = new Win32Point((int)offset.X, (int)offset.Y); NativeMethods.ClientToScreen(((HwndSource)source).Handle, ref winPt); return new IntPoint(winPt.x, winPt.y); }
public static Point GetMousePosition(Visual relativeTo) { Win32Point mouse = new Win32Point(); GetCursorPos(ref mouse); System.Windows.Interop.HwndSource presentationSource = (System.Windows.Interop.HwndSource)PresentationSource.FromVisual(relativeTo); ScreenToClient(presentationSource.Handle, ref mouse); GeneralTransform transform = relativeTo.TransformToAncestor(presentationSource.RootVisual); Point offset = transform.Transform(new Point(0, 0)); return new Point(mouse.X - offset.X, mouse.Y - offset.Y); }
/// <summary> /// Returns the mouse cursor location. This method is necessary during /// a drag-drop operation because the WPF mechanisms for retrieving the /// cursor coordinates are unreliable. /// </summary> /// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param> public static Point GetMousePosition( Visual relativeTo ) { Win32Point mouse = new Win32Point(); GetCursorPos( ref mouse ); // Using PointFromScreen instead of Dan Crevier's code (commented out below) // is a bug fix created by William J. Roberts. Read his comments about the fix // here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx return relativeTo.PointFromScreen( new Point( (double)mouse.X, (double)mouse.Y ) ); #region Commented Out //System.Windows.Interop.HwndSource presentationSource = // (System.Windows.Interop.HwndSource)PresentationSource.FromVisual( relativeTo ); //ScreenToClient( presentationSource.Handle, ref mouse ); //GeneralTransform transform = relativeTo.TransformToAncestor( presentationSource.RootVisual ); //Point offset = transform.Transform( new Point( 0, 0 ) ); //return new Point( mouse.X - offset.X, mouse.Y - offset.Y ); #endregion // Commented Out }
public static Point GetMousePosition(Visual relativeTo) { Win32Point mouse = new Win32Point(); GetCursorPos(ref mouse); System.Windows.Interop.HwndSource presentationSource = (System.Windows.Interop.HwndSource)PresentationSource.FromVisual(relativeTo); ScreenToClient(presentationSource.Handle, ref mouse); GeneralTransform transform = relativeTo.TransformToAncestor(presentationSource.RootVisual); Point offset = transform.Transform(new Point(0, 0)); // // Point p = new Point(mouse.X - offset.X, mouse.Y - offset.Y); // System.Diagnostics.Debug.WriteLine(string.Format("mouse {0:0.0}|{1:0.0} offset {2:0.0}|{3:0.0} res {4:0.0}|{5:0.0}", // mouse.X, mouse.Y, offset.X, offset.Y, p.X, p.Y)); return new Point(mouse.X - offset.X, mouse.Y - offset.Y); }
private static extern bool ClientToScreen (IntPtr hWnd, ref Win32Point point);
internal int iGroup; // version 6 common control internal LVHITTESTINFO_V6(LVHITTESTINFO_INTERNAL htinfo) { pt = htinfo.pt; flags = htinfo.flags; iItem = htinfo.iItem; iSubItem = htinfo.iSubItem; iGroup = htinfo.iGroup; }
// Methods public static Point GetCursorPos() { Win32Point pt = new Win32Point(); GetCursorPos(ref pt); return new Point((double)pt.X, (double)pt.Y); }
public static uint MouseMoveBy(Win32Point p) { return(MouseMoveBy(p.X, p.Y)); }
static extern bool ScreenToClient(IntPtr hWnd, ref Win32Point lpPoint);
public static Point GetMousePosition() { Win32Point point = new Win32Point(); GetCursorPos(ref point); return new Point(point.x, point.y); }
internal static extern bool GetCursorPos([Out] out Win32Point pt);
private static extern int SendMessage(IntPtr hWnd, int ByVal, int wParam, Win32Point lParam);
public static extern bool GetCursorPos(ref Win32Point lpPoint);
private static extern bool ScreenToClient(IntPtr hwnd, ref Win32Point pt);
private static extern int ScreenToClient(IntPtr handle, ref Win32Point point);
private static extern void GetCursorPos(out Win32Point point);
/// <summary> /// Notifies the DragDropHelper that the current Control received /// a DragOver event. /// </summary> /// <param name="cursorOffset">The current cursor's offset relative to the window.</param> /// <param name="effect">The accepted drag drop effect.</param> public static void DragOver(System.Drawing.Point cursorOffset, DragDropEffects effect) { Win32Point pt = SwfDragDropLibExtensions.ToWin32Point(cursorOffset); s_instance.DragOver(ref pt, (int)effect); }
internal static extern bool GetCursorPos(ref Win32Point pt);
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (SettingMode) { Win32Point point = new Win32Point(); GetCursorPos(ref point); this.txtPosX.Text = point.X.ToString(); this.txtPosY.Text = point.Y.ToString(); } }
private static extern bool GetCursorPos(ref Win32Point pt);
/// <summary> /// Returns the current mouse pointer position /// </summary> /// <returns>x,y location of mouse pointer</returns> private Point getCursorPos() { Win32Point w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); return new Point(w32Mouse.X, w32Mouse.Y); }
private void recolor(int from, int to) { int sel_start = richTextBox1.SelectionStart; int sel_len = richTextBox1.SelectionLength; Win32Point scroll_pos = new Win32Point(); SendMessage(richTextBox1.Handle, EM_GETSCROLLPOS, 0, ref scroll_pos); LockWindowUpdate(richTextBox1.Handle); richTextBox1.Hide(); bool is_name = false; int name_start = 0; string the_name = ""; richTextBox1.Select(from, to - from); richTextBox1.SelectionBackColor = space_back; richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Regular); bool is_string = false; int string_start = 0; bool is_char = false; int char_start = 0; bool is_comment = false; int comment_start = 0; string richTextBox1_Text = richTextBox1.Text; char prev_char = '\0'; char cur_char = '\0'; for (int i = from; i < to + 1; i++) { if (i > from) { prev_char = cur_char; } if (i < to) { cur_char = richTextBox1_Text[i]; } else { cur_char = '\0'; } if (ok_for_name(cur_char)) { if (!is_name) { name_start = i; is_name = true; } the_name += cur_char; } else { if (spacesToolStripMenuItem.Checked) { if (!(is_comment || is_string || is_char)) { if (cur_char == '\t') { richTextBox1.Select(i, 1); richTextBox1.SelectionBackColor = tab_back; } } } if (is_name) { int name_len = i - name_start; if (syntaxHighlightingToolStripMenuItem.Checked && keywords.Contains(the_name)) { richTextBox1.Select(name_start, name_len); if (is_comment) { richTextBox1.SelectionColor = Color.Silver; } else { richTextBox1.SelectionColor = Color.White; } } else if (perWordHighlightingToolStripMenuItem.Checked) { int hash = the_name.GetHashCode(); int name_R = 192 + (hash % 32) * 2; int name_G = 192 + ((hash / 32) % 32) * 2; int name_B = 192 + ((hash / 32 / 32) % 32) * 2; if (is_comment || is_string || is_char) { name_R = 192 + (name_R - 192) / 2; name_G = 192 + (name_G - 192) / 2; name_B = 192 + (name_B - 192) / 2; } richTextBox1.Select(name_start, name_len); richTextBox1.SelectionColor = Color.FromArgb(name_R, name_G, name_B); } else { richTextBox1.Select(name_start, name_len); richTextBox1.SelectionColor = Color.Silver; } is_name = false; the_name = ""; } if (commentsToolStripMenuItem.Checked) { if ((cur_char == '#' || cur_char == '-' || cur_char == '/' || cur_char == '%') && (prev_char == '\n' || i == from)) { is_comment = true; comment_start = i; } if (cur_char == '\n' || i == to) { if (is_comment) { richTextBox1.Select(comment_start, i - comment_start); richTextBox1.SelectionBackColor = comment_back; richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Italic); } is_comment = false; is_string = false; is_char = false; } } if (stringsToolStripMenuItem.Checked) { if (cur_char == '\"' && prev_char != '\\') { is_string = !is_string; if (is_string) { string_start = i; } else { richTextBox1.Select(string_start + 1, i - string_start - 1); richTextBox1.SelectionBackColor = string_back; richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Italic); } } if (cur_char == '\'' && prev_char != '\\') { is_char = !is_char; if (is_char) { char_start = i; } else { richTextBox1.Select(char_start + 1, i - char_start - 1); richTextBox1.SelectionBackColor = char_back; richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Italic); } } } } } richTextBox1.Show(); richTextBox1.Select(sel_start, sel_len); SendMessage(richTextBox1.Handle, EM_SETSCROLLPOS, 0, ref scroll_pos); LockWindowUpdate((IntPtr)0); }
static System.Drawing.Point GetMousePosition() { Win32Point w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); return new System.Drawing.Point(w32Mouse.X, w32Mouse.Y); }
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref Win32Point pt);
/// <summary> /// Returns the mouse cursor location. This method is necessary during /// a drag-drop operation because the WPF mechanisms for retrieving the /// cursor coordinates are unreliable. /// </summary> /// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param> public static Point GetMousePosition(Visual relativeTo) { Win32Point mouse = new Win32Point(); GetCursorPos(ref mouse); return relativeTo.PointFromScreen(new Point((double)mouse.X, (double)mouse.Y)); }
static extern bool ClientToScreen(IntPtr hWnd, ref Win32Point lpPoint);
/// <summary> /// Converts a System.Windows.Point value to a DragDropLib.Win32Point value. /// </summary> /// <param name="pt">Input value.</param> /// <returns>Converted value.</returns> public static Win32Point ToWin32Point(this Point pt) { Win32Point wpt = new Win32Point(); wpt.x = pt.X; wpt.y = pt.Y; return wpt; }
private static extern bool GetCursorPos( ref Win32Point pt );
public static Point GetCursorPos(Visual relativeTo) { Win32Point pt = new Win32Point(); GetCursorPos(ref pt); return relativeTo.PointFromScreen(new Point((double)pt.X, (double)pt.Y)); }
public static PointF GetMousePosition() { Win32Point w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); return new PointF(w32Mouse.X, w32Mouse.Y); }
public void OneClickComboBoxCell () { Form form = null; try { // Create a form, a text label, and a data-grid-view. form = new Form (); Label label = new Label (); label.Text = "Label"; label.Parent = form; ClickableDataGridView dgv = new ClickableDataGridView (); dgv.Parent = form; // Create a combo-box column. DataGridViewComboBoxColumn cbCol = new DataGridViewComboBoxColumn (); cbCol.HeaderText = "Name"; dgv.Columns.Add (cbCol); // .NET requires that all possible values for combo-boxes // in a column are added to the column. cbCol.Items.Add ("Item1"); cbCol.Items.Add ("Item2"); cbCol.Items.Add ("Item3"); cbCol.Items.Add ("Item4"); // Set up the contents of the data-grid. dgv.Rows.Add ("Item1"); dgv.Rows.Add ("Item2"); // Select the cell. dgv.CurrentCell = dgv.Rows[0].Cells[0]; // Focus the data-grid-view. (Without this, its Leave // event won't get called when something outside of the // data-grid-view gets focused.) dgv.Focus (); // Show the form, let it draw. form.Show (); Application.DoEvents (); // Locate the drop-down button. (This code is taken from mono-winforms, // from the private method DataGridViewComboBoxCell.CalculateButtonArea(), // and was then hacked mercilessly.) Rectangle button_area = Rectangle.Empty; { int border = 3 /* ThemeEngine.Current.Border3DSize.Width */; const int button_width = 16; Rectangle text_area = dgv.GetCellDisplayRectangle (0, 0, false); button_area.X = text_area.Right - button_width - border; button_area.Y = text_area.Y + border; button_area.Width = button_width; button_area.Height = text_area.Height - 2 * border; } // Click on the drop-down button. int x = button_area.X + (button_area.Width / 2); int y = button_area.Y + (button_area.Height / 2); if (Environment.OSVersion.Platform == PlatformID.Win32NT && Type.GetType ("Mono.Runtime") == null) { // Calling OnMouseDownInternal () in Win32 doesn't work. // My best guess as to why is that the WinForms ComboBox // is a wrapper around the ComCtl control, e.g. similar // to the reason that Paint event-handlers don't work on // TreeView. So we go through all this rigamarole to // simulate a mouse click. // First, get the location of the desired mouse-click, in // data-grid-view coordinates. Win32Point ptGlobal = new Win32Point (); ptGlobal.x = x + dgv.Location.X; ptGlobal.y = y + dgv.Location.Y; // Convert that to screen coordinates. ClientToScreen (form.Handle, ref ptGlobal); // Move the mouse-pointer there. (Yes, this really appears // to be necessary.) SetCursorPos (ptGlobal.x, ptGlobal.y); // Convert screen coordinates to mouse coordinates. ptGlobal.x *= (65535 / SystemInformation.VirtualScreen.Width); ptGlobal.y *= (65535 / SystemInformation.VirtualScreen.Height); // Finally, fire a mouse-down and mouse-up event. mouse_event (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_ABSOLUTE, ptGlobal.x, ptGlobal.y, 0, 0); mouse_event (MOUSEEVENTF_LEFTUP|MOUSEEVENTF_ABSOLUTE, ptGlobal.x, ptGlobal.y, 0, 0); // Let the system process these events. Application.DoEvents (); } else { // And this is how the same code is done under Linux. // (No one should wonder why I prefer Mono to MS Windows .NET ;-) MouseEventArgs me = new MouseEventArgs (MouseButtons.Left, 1, x, y, 0); DataGridViewCellMouseEventArgs cme = new DataGridViewCellMouseEventArgs (0, 0, x, y, me); dgv.OnMouseDownInternal (cme); dgv.OnMouseUpInternal (cme); } // Make sure that created an editing control. ComboBox cb = dgv.EditingControl as ComboBox; Assert.AreNotEqual (null, cb, "1-1"); // Make sure that dropped down the menu. Assert.AreEqual (true, cb.DroppedDown, "1-2"); // Close the menu. cb.DroppedDown = false; // Change the selection on the menu. cb.SelectedIndex = 2 /* "Item3" */; // Leave the data-grid-view. label.Focus (); // That should have ended editing and saved the value. string cellValue = (string)(dgv.Rows[0].Cells[0].FormattedValue); Assert.AreEqual ("Item3", cellValue, "1-3"); } finally { if (form != null) form.Close (); } }
public static uint MouseMoveToPixel(Win32Point p) { return(MouseMoveToPixel(p.X, p.Y)); }
public static Win32Point GetMousePosition() { Win32Point w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); return w32Mouse; }
/// <summary> /// Gets mouse pointer location relative to top left of monitor, scaling for DPI as required. /// </summary> /// <param name="relative">Window on monitor.</param> /// <returns>Mouse location scaled for DPI.</returns> public static Point GetDPIAwareMouseLocation(Window relative) { Win32Point w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); var scale = UsefulThings.General.GetDPIScalingFactorFOR_CURRENT_MONITOR(relative); Point location = new Point(w32Mouse.X / scale, w32Mouse.Y / scale); return location; }
public static Point CorrectGetPosition(Visual relativeTo) { Win32Point w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); return relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y)); }
public static Vector2 GetMousePosition() { Win32Point w32Mouse = new Win32Point(); GetCursorPos(ref w32Mouse); return new Vector2(w32Mouse.X, w32Mouse.Y); }
public int iSubItem ; // this is was NOT in win95. valid only for LVM_SUBITEMHITTEST public LVHITTESTINFO(LVHITTESTINFO_public htinfo) { pt = htinfo.pt ; flags = htinfo.flags ; iItem = htinfo.iItem ; iSubItem = htinfo.iSubItem ; }
public static extern IntPtr WindowFromPoint(Win32Point pt);
private static extern bool ScreenToClient( IntPtr hwnd, ref Win32Point pt );
public int iGroup ; // version 6 common control public LVHITTESTINFO_V6(LVHITTESTINFO_public htinfo) { pt = htinfo.pt ; flags = htinfo.flags ; iItem = htinfo.iItem ; iSubItem = htinfo.iSubItem ; iGroup = htinfo.iGroup ; }
public static uint MouseMoveTo(Win32Point p, bool virtualDesk = false) { return(MouseMoveTo(p.X, p.Y, virtualDesk)); }