3
Reply

Error in a SetValue. Can someone tell me where the error is?

Gustavo

Gustavo

Jun 9 2010 9:51 PM
3.7k

Hello:

I am trying to set a property in a Form from a Class that I called. There is an error.  Can someone tell me where the error is in the line marked as //ERROR.

 

 

        private void TabPageEnter(object sender, EventArgs e)

        {

            Form TheForm = Form.ActiveForm.ActiveMdiChild;

            TheTabPageName = ((TabPage)sender).Name.Substring(7);

            switch (TheTabPageName)

            {

                case "Record":

                    MessageBox.Show("TabPageEnter: TheForm:" + TheForm.Name.ToString());      //   = FormGeneral    // GOOD

                    MessageBox.Show("TabPageEnter: TheTabPageEnter=" + TheTabPageName);       //   = tabPageRecord  // GOOD

 

                    //FormGeneral.buttonRecordPrint.Visible = true;     // What I want to do.

 

                    ((Form)sender).GetType().GetField("buttonRecordPrint.Visible").SetValue(((Form)sender), true);  // Error

                    //Error = {"Unable to cast object of type 'System.Windows.Forms.TabPage' to type 'System.Windows.Forms.Form'."}

 

                    break;

                default:

                    break;

            }

        }


Answers (3)