Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello!!
I am developing live project first time, i change default color of mdi parent form using bellow code..
C#
#region parentmdicolor

           MdiClient mdiclt;
           foreach (Control cltr in this.Controls)
           {
               try
               {

                   mdiclt = (MdiClient)cltr;
                   mdiclt.BackColor = this.BackColor;

               }
               catch (InvalidCastException ex)
               {
                   MessageBox.Show(" Something is happening :-(", ex.Message);
               }

           }
           #endregion


but after that whenever am dragging and dropping some controls like menustripe , linklabel my progarm directly execute catch and after clicking ok my color is appear on mdi form. so why it is happening what is the solution???
Error msg is "Unable to cast object of type system.windows.form.linklable to system.windows.form.mdiparent"
THANKS In Advance..
Posted
Updated 9-Mar-13 5:30am
v3

Try this:
C#
MdiClient mdiclt;
foreach (Control cltr in this.Controls)
{
    try
    {

        mdiclt = cltr as MdiClient;
        if (mdiclt != null)
        {
            mdiclt.BackColor = this.BackColor;
        }
    }
    catch (InvalidCastException ex)
    {
        MessageBox.Show(" Something is happening :-(", ex.Message);
    }

}
 
Share this answer
 
Comments
OriginalGriff 10-Mar-13 4:57am    
That's not very helpful! :laugh:
What does it do? What doesn't it do?
.
Remember that we can't see your screen, access your HDD, or read your mind!
Please see my previous answer: Is mdi form's background color changeable?[^].

Honestly, don't do it, stay out of trouble.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900