|
-
Jul 11th, 2008, 05:04 AM
#1
Thread Starter
Member
[2.0] Resizing Controls
Hello,
In the _Resize events of a control I have some code that changes the size of some child controls. These changes should, obviously, occur when the parent control is resized, but there are also other situations where this resize should occur. In some other functions I thus should call the same resize routine.
What is the cleanest way to handle this? Currently, I'm simply calling the _Resize function like this;
Code:
MyControl_Resize(new Object(), new EventArgs());
This seems bad though, even when it seems to work 100%. It's just not how events are supposed to be used. I see two other options I can do;
- Create a general doResize() function which I call in MyControl_Resize and in any other functions where the resize should occur
- Somehow, if this is even possible, raise the MyControl_Resize event in the 'proper' way instead of calling it like I showed above.
Even though it already works now, I'd like to know if it could and perhaps should be done better.
Thanks.
-
Jul 11th, 2008, 06:28 AM
#2
Re: [2.0] Resizing Controls
I applaud your thinking. I've had numerous people argue with me that calling event handlers directly is OK. It's just not the right thing to do, as you say. Your first suggestion is the way to go. The second suggestion would work for the Click event of some controls, like a Button, that are born to be clicked and have a PerformClick method. Otherwise go with your first option.
-
Jul 11th, 2008, 03:07 PM
#3
Thread Starter
Member
Re: [2.0] Resizing Controls
Sounds good, but what about overheat? When the user resizes the form, the _Resize event gets called a dozen of times in some situations. It's just one function, but won't it slow down too much?
Otherwise I'll do what you suggest. Thanks!
-
Jul 11th, 2008, 07:19 PM
#4
Re: [2.0] Resizing Controls
Give it a try and see. If you notice a lag then post the code and we'll see if we can optimise it but I doubt there'll be a problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|