tags:

views:

52

answers:

2

I have one function GetControlRectangle(Rectangle MethodRect) that accepts the rectangle of the control.

Now I write the code like Rectangle rct=dataGridView1.GetCellDisplayRectangle(1,0,false); which finds the location of the cell(1,0) of the datagridview1.

And I pass this rct to the method GetControlRectangle.

Now how to find through the MethodRect(which is the argument in the method)that which function was used to get this rectangle point like GetCellDisplayRectangle() or GetColumnDisplayRectangle(). Because I want to know in the method GetControlRectangle() that this point is for columnheader or cell and it is for cell then for which cell.

In short, I want to know that which function was used through variable which is assigned like Rectangle rct=dataGridView1.GetCellDisplayRectangle(1,0,false); through rct I want to know which function was used to assign this variable.

A: 

If I understood correctly, you need to convert rct into getter/setter pair. In the setter, create a new System.Diagnostics.StackTrace() (just call ToString() method to get a readable representation). It will contain the call stack, in this case, the function that is setting the new value for rct.

Something like this (replace exception with more suitable handling):

Rectangle _rct=null;
Rectangle rct {
  get { return _rct; }
  set {
    throw new Exception(new System.Diagnostics.StackTrace().ToString());
    //_rct=value;
  }
}
Skrim
Can you explain in detail pleaze?
Harikrishna
what does do System.Diagnostics.StackTrace() ?
Harikrishna
+1  A: 

if I understood correctly, he should just modify the GetControlRectangle(Rectangle MethodRect) function so that it looks like GetControlRectangle(Rectangle MethodRect, bool IsHeader) and then have the calling code do the deciding of "which function was called".

Al W