|
I'm so glad your opinion isn't all that matters then.
|
|
|
|
|
I'm not the only one telling you the practice sucks...
|
|
|
|
|
And yet neither of you are displaying an alternative that is better?
|
|
|
|
|
I'm not in the spoon feeding business, I did provide the two keywords that exist for dealing elegantly with such situations. So if you want to learn something, look them up and read the reference material.
|
|
|
|
|
So sorry you don't feel like trying to answer the ops question with something less cryptic. Seems forums just aren't as helpful as they used to be. Since you feel you are such an expert that you you don't need to provide examples my opinion, for what it's worth is that you are no help at all and shouldn't even be posting.
|
|
|
|
|
Yeah, right. A couple of Code Project MVP's aren't very helpful at all. The pile of 5-voted responses to questions just doesn't offer up any evidence at all of us being helpful.
I'm not in the spoon-feed business either. There are just WAY too many very basic concept questions being asked that are very easily answered simply by typing the question into Google.
I'd rather have someone learn how to do research themselves than just keep asking question after question about very basic topics.
|
|
|
|
|
Actually Most everyone I know searches for the answers before hitting a forum with a question. Personally in my opinion it's more professional to offer assistance with a basic code example in the hopes the op learns something in the process. All anyone is learning from your responses is not to ask you for help.
|
|
|
|
|
Actually Most everyone I know searches for the answers before hitting a forum with a question.
I don't agree with you : if you see the questions these days it is obvious that more and more people consider this forum as a 'code self-service'. Plenty of questions wouldn't have been told if the OP took time to search for it on CP or on Google first.
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
Yeah, and most everyone I know Googles for answers before asking questions too.
But, yet, here we are, still looking at piles and piles of questions on very basic concepts.
The world doesn't follow in your footsteps either.
|
|
|
|
|
Apparently you haven't been reading the posts.
You also apparently won't be happy until you see actual code:
private void MdiClientExample()
{
foreach (Control c in this.Controls)
{
if (c is MdiClient)
{
MdiClient mc = (MdiClient)c;
...
}
}
}
Are you happy now?
Oh, and by the way, I don't consider this production quality code either. It's just cleaner than the example Microsoft gave.
And if you're going to critisize us, you might want to start by creating your own code samples instead of lifting and posting others as your own work.
|
|
|
|
|
Funny, I have a feeling you weren't taught with original code either. This is another example of someone thinking the op should be equally as skilled as the person responding. If you don't feel like spoon feeding you shouldn't be offering assistance all you do is add to the confusion.
|
|
|
|
|
Alisaunder wrote: Funny, I have a feeling you weren't taught with original code either.
You're right. I'm self-taught over the span over 30+ years. When I was learning most of my stuff, there was no internet, so I was pretty much on my own, reading as much as I could.
Alisaunder wrote: This is another example of someone thinking the op should be equally as skilled
as the person responding.
With coding skills, not at all. But the research skills and the ability to teach yourself something new? Oh, yeah. Those are basic skills you learn in school and apply to the coding job every day. If you want someone to spoon-feed you stuff all the time, you're not going to last very long. And there are a TON of people who come here looking for the spoon.
I give enough information to the OP so they can Google the problem themselves. In my humble opinion, new coders today have it much easier than I did learning this stuff.
|
|
|
|
|
Someone (I think it was here on CP) told me that as is as fast as is, so it's better to do
foreach(Control c in Controls) {
MdiClient mdi = c as MdiClient;
if(mdi != null) { ... }
}
... because you avoid the cost of the second cast.
|
|
|
|
|
There is only one cast being made on each iteration of the loop until the correct control is found. So it really doesn't matter which you use since the only speed difference (and it's a very minor one) would be the expense of the second cast on the inside of the if statement.
|
|
|
|
|
Yes, it is pretty minor. I have started writing my code in that way since then, though.
|
|
|
|
|
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.
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
|
|
|
|
|
And in some rare cases it may not be in the top-level Form. Also adding Try and catch is error controlling which I don't care who you are is still considered good practice, otherwise you end up with crashing code that nobody can debug. Once you have a complete project you can remove The error handling code to streamline the application. But to say it's not good practice to include it is in my opinion really stupid and asking for trouble.
|
|
|
|
|
Alisaunder wrote: Also adding Try and catch is error controlling which I don't care who you are
is still considered good practice
Only if used appropriately. If this little block is coded up correctly, you won't have a need for a try/catch block at all.
If I had to use a try/catch block, it wouldn't be in the manner than you copied from MSDN. It would have been outside the foreach or even in the caller and not this method and still used the if statement to test the control type.
|
|
|
|
|
No, you're wrong. Correct exception handling is good practice, yes. Using exceptions where there is a well documented non-exception path is not, because exceptions are expensive and slow. You should use exceptions for exceptional cases, not as part of normal flow control.
|
|
|
|
|
Alisaunder wrote: Also adding Try and catch is error controlling which I don't care who you are
is still considered good practice
You clown....and empty catch block is NOT a valid error handling technique...as others have pointed out to you, it's not what exceptions are there for...it's just LAZY to catch and ignore an exception, since you can check before hand if it's not a valid item...
Alisaunder wrote: otherwise you end up with crashing code that nobody can debug
Cobblers....you have heard of a debugger yes?
Alisaunder wrote: Once you have a complete project you can remove The error handling code to
streamline the application
Seriously? Remove error handling once it's complete? Oh dear god....
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Hi, I don't think you deserve to be cast into the outer darkness of the dreaded one-vote here, because you were, I think, sincerely trying to respond to the OP's question.
And, whether the code you provided leads to gnashing of teeth, or not, it does work.
But, may I suggest, in the future, you provide a link to the MS docs, or other sources, code examples are taken from.
best, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
I don't see where you problem is : if you cannot see the background of your MDI parent, it is because there is another object above it (its child) which is masking the main form.
So, you can change the background color of the main form as you want, your change will be applied but you will not see it as there is still the same child object above it.
Why don't you change the background color of the MdiClient control, so ?
And, please, reserve the use of 'pre' tag for actual code.
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
You normally can't see the background of an MdiParent form. It's being covered byt eh MdiClient control which is Dock = Full over the entire form.
|
|
|
|
|
Does this[^] article help?
/ravi
|
|
|
|
|
In a container form I have menu and buttons to open their forms.
Here I am facing a problem when I open any form these buttons and lables come over newly opened form.
Please guide me how I can manage this issue? I want to open a new form and keep these container form's controls in back ground of it.
|
|
|
|