Hi,
I am trying to override a private method and to make things worse, the call is buried in another private method (several actually). Specifically, I have a custom DataGrid class (inheriting DataGrid) and I want to somehow get to the PaintColumnHeaderText(Graphics g, Rectangle boundingRect) method. My goal is to change the bounding rectangle's position to vertically align the headers.
any help is appreciated! ^_^
-Matt
MattPosted Sep 26, 2007, 11:12 PM
AlanPosted Sep 24, 2007, 12:49 PM
Well, here's the code to call that particular method using reflection. I've assumed that you're calling it from your custom DataGrid class and that you're passing arguments of 'g 'and 'boundingRect' for the Graphcs and new Rectangle objects, respectively:
using System.Reflection;
.............
Type t = typeof(DataGrid);
BindingFlags bf = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod;
MethodInfo mi = t.GetMethod("PaintColumnHeaderText", bf);
int result = (int)mi.Invoke(this, new object[]{g, boundingRect});
MattPosted Sep 23, 2007, 5:19 PM
If I could find a way to edit the location without it moving on me that'd work too. The problem is that I don't think that there is a variable that I can change. If I can move the bounding rectangle than I am happy.
AlanPosted Sep 23, 2007, 11:16 AM
Although it's possible to call a private virtual method using reflection, to the best of my knowledge it's not possible to override it in a derived class.
Would being able to simply call it suffice for what you're trying to do?