lundi 30 mars 2015

Show WinForm below a cell

How can I show I winform that I create in VB.NET just below the active cell?


I have no idea how to solve this. I found the following promising solutions: Excel addin: Cell absolute position


-The accepted solution seems too complicated to work reliably. I got an error on the first row (Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long)


-The second solution looked promising, but it didn't give me the right positions for my windows form.


The following adaptations of the second proposed solution does not create any errors but does not put the windows form in the correct position:



Public Sub GetScreenPositionFromCell(cell As Excel.Range, excel As Excel.Application)

Dim x As Double
Dim y As Double
If Not excel.ActiveWindow Is Nothing Then
x = excel.ActiveWindow.PointsToScreenPixelsX(cell.Left)
y = excel.ActiveWindow.PointsToScreenPixelsY(cell.Top)
End If

Me.Left = x
Me.Top = y

Me.Show()
Me.TopMost = True
End Sub

Aucun commentaire:

Enregistrer un commentaire