none
ChangeUICues reflection RRS feed

  • Question

  • Hallo, everybody

     

    i'm trying to reflect the ChangeUICues checkbox's method, but faced some problems.

    here's the code.

    Type t = checkBox1.GetType();

    MethodInfo m = t.GetMethod("ChangeUICues", BindingFlags.NonPublic | BindingFlags.Instance);

    UICues u = UICues.ShowFocus| UICues.Changed | UICues.ChangeFocus | UICues.ChangeKeyboard|UICues.None | UICues.ShowKeyboard | UICues.Shown;

    UICuesEventArgs a = new UICuesEventArgs(u);

     object[] ob = new object[1];

     ob[0]= a;

     m.Invoke(checkBox1, ob);

     

    and so i get a nullReferenceException on ob in m.Invoke(checkBox1, ob).

     what i'm doing wrong?(

    • Moved by Aspen VJ Monday, November 29, 2010 2:54 AM (From:Windows Forms General)
    Friday, November 26, 2010 12:13 PM

Answers

  • Are you sure you actually got a MethodInfo object returned by t.GetMethod?

    ChangeUICues is an Event not a Method and, even if you can get hold of it, you can't invoke it directly.  You might be better off trying to use the [Control.]OnChangeUICues Method, which is the thing that raises the event (to as many delegates as may be registered to receive the event).  If you're extending the CheckBox class, simply override OnChangeUICues. 

    This is all pretty "nasty" stuff to be mucking about with.  Take a step back for a moment and tell us what you're trying to achieve with all this; there may be a better way.



    Regards, Phill W.
    • Marked as answer by Terion Monday, November 29, 2010 11:33 AM
    Friday, November 26, 2010 12:28 PM
  • Hi Terion

    Your problem is getting an exception of 'nullReference'.

    1.There is no a method called 'ChangeUICues' .It is an event.

    2.You use GetMethod("ChangeUICues"....). That CLR will never find it. You can use GetEvent().

    3.So it will retun a null object at second line.

    You use the null object to execute that causes this exception.


    Please mark the right answers which satisfy your requirements.That will be helpfull for all community members. Thanks, Cookie
    • Marked as answer by Terion Monday, November 29, 2010 11:33 AM
    Monday, November 29, 2010 5:42 AM

All replies

  • Are you sure you actually got a MethodInfo object returned by t.GetMethod?

    ChangeUICues is an Event not a Method and, even if you can get hold of it, you can't invoke it directly.  You might be better off trying to use the [Control.]OnChangeUICues Method, which is the thing that raises the event (to as many delegates as may be registered to receive the event).  If you're extending the CheckBox class, simply override OnChangeUICues. 

    This is all pretty "nasty" stuff to be mucking about with.  Take a step back for a moment and tell us what you're trying to achieve with all this; there may be a better way.



    Regards, Phill W.
    • Marked as answer by Terion Monday, November 29, 2010 11:33 AM
    Friday, November 26, 2010 12:28 PM
  • Hi Terion

    Your problem is getting an exception of 'nullReference'.

    1.There is no a method called 'ChangeUICues' .It is an event.

    2.You use GetMethod("ChangeUICues"....). That CLR will never find it. You can use GetEvent().

    3.So it will retun a null object at second line.

    You use the null object to execute that causes this exception.


    Please mark the right answers which satisfy your requirements.That will be helpfull for all community members. Thanks, Cookie
    • Marked as answer by Terion Monday, November 29, 2010 11:33 AM
    Monday, November 29, 2010 5:42 AM
  • Are you sure you actually got a MethodInfo object returned by t.GetMethod?

    ChangeUICues is an Event not a Method and, even if you can get hold of it, you can't invoke it directly.  You might be better off trying to use the [Control.]OnChangeUICues Method, which is the thing that raises the event (to as many delegates as may be registered to receive the event).  If you're extending the CheckBox class, simply override OnChangeUICues. 

    This is all pretty "nasty" stuff to be mucking about with.  Take a step back for a moment and tell us what you're trying to achieve with all this; there may be a better way.



    Regards, Phill W.

    thank you,guys. you're right, tha't's an event(

    the problem is:

    when you press tab and go through controls, when you reach a checkbox - you'll see the dotted rectangle as a result of OnChangeUICues rising.

    but i must realise tabbing by another way - by pressing ENTER in any of my controls on the form.

    i use this code for it

    private

     

    void checkBox1_KeyPress(object sender, KeyPressEventArgs e)

    {

    if (e.KeyChar == 13)

    {

    this.SelectNextControl((Control)sender, true, true, true, true);}}

    but in such situation there's no OnChangeUICues rising and no rectangle as a result, so user won't ever now that he has reached a checkbox

     

    i want to show that rectangle by any way.

     

    Monday, November 29, 2010 11:44 AM
  • hey there?(

    Friday, December 3, 2010 9:46 AM