Click here to Skip to main content
15,918,742 members
Home / Discussions / C#
   

C#

 
GeneralRe: How set the background of an MDI container window? Pin
Dave Kreskowiak30-Oct-11 3:24
mveDave Kreskowiak30-Oct-11 3:24 
GeneralRe: How set the background of an MDI container window? Pin
Dave Kreskowiak29-Oct-11 17:52
mveDave Kreskowiak29-Oct-11 17:52 
GeneralRe: How set the background of an MDI container window? Pin
Alisaunder29-Oct-11 18:02
Alisaunder29-Oct-11 18:02 
GeneralRe: How set the background of an MDI container window? Pin
Dave Kreskowiak30-Oct-11 3:16
mveDave Kreskowiak30-Oct-11 3:16 
GeneralRe: How set the background of an MDI container window? Pin
BobJanova30-Oct-11 23:09
BobJanova30-Oct-11 23:09 
GeneralRe: How set the background of an MDI container window? Pin
Dave Kreskowiak31-Oct-11 1:30
mveDave Kreskowiak31-Oct-11 1:30 
GeneralRe: How set the background of an MDI container window? Pin
BobJanova31-Oct-11 2:11
BobJanova31-Oct-11 2:11 
GeneralRe: How set the background of an MDI container window? Pin
BillWoodruff29-Oct-11 18:02
professionalBillWoodruff29-Oct-11 18:02 
Alisaunder wrote:
And yet neither of you are displaying an alternative that is better?
I think the absence of code here is not the result of any 'negative intention:'

It's just obvious that the best practice here is to enumerate the controls on the Form [1], test each one using the 'Is operator, and, when the MdiClient Control is found, then cast it from Type Control back to its 'native Type, 'MdiClient ... at which point you can have your way with it.
C#
//
// assume you have loaded a valid image from an embedded resource
// into the variable of Type Bitmap named 'mdiBackGround'
//
private MdiClient theMDIClientControl;
//
foreach (Control theControl in this.Controls) [2]
{
    if (theControl is MdiClient)
    {
        theMDIClientControl = theControl as MdiClient;
        break;
    }
}

if (theMDIClientControl != null) theMDIClientControl.BackgroundImage = mdiBackGround;
[1] see my response to Dave K. above[^] confirming why it is absolutely necessary to enumerate the Controls on the Form.

[2] Seems a reasonable assumption the MdiClient Control will always be in the top-level Form Control Collection: hence no need for a recursive search
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright

GeneralRe: How set the background of an MDI container window? Pin
Alisaunder29-Oct-11 18:06
Alisaunder29-Oct-11 18:06 
GeneralRe: How set the background of an MDI container window? Pin
Dave Kreskowiak30-Oct-11 3:21
mveDave Kreskowiak30-Oct-11 3:21 
GeneralRe: How set the background of an MDI container window? Pin
BobJanova30-Oct-11 23:07
BobJanova30-Oct-11 23:07 
GeneralRe: How set the background of an MDI container window? Pin
RichardGrimmer2-Nov-11 7:09
RichardGrimmer2-Nov-11 7:09 
GeneralMy vote of #3 ... Re: How set the background of an MDI container window? Pin
BillWoodruff29-Oct-11 17:37
professionalBillWoodruff29-Oct-11 17:37 
AnswerRe: How set the background of an MDI container window? Pin
phil.o29-Oct-11 23:15
professionalphil.o29-Oct-11 23:15 
GeneralRe: How set the background of an MDI container window? Pin
Dave Kreskowiak30-Oct-11 3:23
mveDave Kreskowiak30-Oct-11 3:23 
AnswerRe: How set the background of an MDI container window? Pin
Ravi Bhavnani30-Oct-11 12:06
professionalRavi Bhavnani30-Oct-11 12:06 
QuestionMdi Form Pin
jojoba2029-Oct-11 1:14
jojoba2029-Oct-11 1:14 
AnswerRe: Mdi Form Pin
tgurlevik29-Oct-11 2:43
tgurlevik29-Oct-11 2:43 
AnswerRe: Mdi Form Pin
Dave Kreskowiak29-Oct-11 3:15
mveDave Kreskowiak29-Oct-11 3:15 
QuestionCasting to Abstract 'parent' rather than casting to Interface ? Pin
BillWoodruff28-Oct-11 22:31
professionalBillWoodruff28-Oct-11 22:31 
AnswerRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
Luc Pattyn29-Oct-11 1:37
sitebuilderLuc Pattyn29-Oct-11 1:37 
GeneralRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
Not Active29-Oct-11 5:17
mentorNot Active29-Oct-11 5:17 
GeneralRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
Luc Pattyn29-Oct-11 5:45
sitebuilderLuc Pattyn29-Oct-11 5:45 
GeneralRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
BillWoodruff29-Oct-11 16:26
professionalBillWoodruff29-Oct-11 16:26 
AnswerRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
Luc Pattyn29-Oct-11 17:40
sitebuilderLuc Pattyn29-Oct-11 17:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.