unvell / ReoGrid

Fast and powerful .NET spreadsheet component, support data format, freeze, outline, formula calculation, chart, script execution and etc. Compatible with Excel 2007 (.xlsx) format and working on .NET 3.5 (or client profile), WPF and Android platform.
https://reogrid.net
MIT License
1.32k stars 390 forks source link

Hot to get windows screen coordinates of cell boundaries #431

Open DaniRK opened 3 years ago

DaniRK commented 3 years ago

My WinForms application needs to display a dialog form when clicking certain cells. The dialog should be shown to the right of the clicked cell. Example: if the cell is displayed as a rectangle with screen coordinates left = 500, right=700, top=300, bottom =320, than the dialog's form location should be at left=701.

It seems that currently (reogrid v3.0 under .net core 3.1) there is no way to get the screen position of cells boundaries.

By Monitoring CellMouseDown event I can get:

  1. e.CellPosition, this gives me the cell in wich the mouse click occurs. But it seems that there is no way to get the absolute boundaries of a cell, neither relative to the form nor relative to the reogrid control .

  2. e.AbsolutePosition, which does not help, since it reflects the coordinates inside! the cell. Hitting the left part of a cell returns a different position than hitting its right part. And what I need is the cells right boundary. I assume that when combining e.AbsolutePosition with e.RelativePosition (the point clicked inside the cell and relative to the cells 0,0), I could detect the cells left and upper boundary. But this boundary does not yield screen coordinates. It is relative to display cell A1, does not reflect row&column headers, horizontal/vertical scrolling (and probably freezing and more).

By the way I can get the width of the row header using sheet's RowHeaderWidth, but cannot figure out how to get the height of the column header (no sheet property 'ColumnHeaderHeight').

To make it short, how can I reliably detect the windows screen coordinates of a cell?

Best regards, Dani

jingwood commented 3 years ago

Hi Dani! The bounds position of a cell is dynamically calculated in real-time. I will consider adding some APIs to get the positions of the bound.

Does your window appear one time if click inside a cell, or does your window keep display on the side of a cell until you close it?

When you zoom a worksheet, change columns width, or scroll a worksheet, the cell position will change every time. If you are not considering maintenance the position, it will be simpler.

DaniRK commented 3 years ago

Thanks for your reply.

window appears if clicked inside a cell, until user closes it or moves to another cell. And yes, user can change column width, and scroll in both horizontally and vertically. It is actually an auto-complete feature for users writing addresses.

I finally hacked around it, monitoring cell mouse clicks events, scrolling events, and do some complicated housekeeping and calculations; actually maintaining my own mirror of the state of the reogrid control.

Thanks for your efforts and this project Dani