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

AlanRank #669 · 3.6K reputationPosted Sep 23, 2007, 7:16 AM EDT
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?
Matt6 reputationPosted Sep 23, 2007, 1:19 PM EDT
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.
AlanRank #669 · 3.6K reputationPosted Sep 24, 2007, 8:49 AM EDT
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});
Matt6 reputationPosted Sep 26, 2007, 7:12 PM EDT