Results 1 to 4 of 4

Thread: [2.0] Resizing Controls

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    48

    [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    48

    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!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width