dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] Custom controls - general perfomance question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    544

    Resolved [RESOLVED] Custom controls - general perfomance question

    Hi,

    I have multiple custom controls in my project.... I'm wondering, in terms of performance, is It better to override all Paint etc. methods in control Itself rather than assign events for control on Form (UI thread) ? Or does It not matter ? I'm asking because I noticed slight difference between UI thread perfomance when having custom controls or have same code for control in Form events...

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,617

    Re: Custom controls - general perfomance question

    The OnPaint method should be overridden and all standard drawing for the control done there. The Paint event handler should only be for drawing specific to that instance.
    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
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    544

    Re: Custom controls - general perfomance question

    What about everything else - I also have keypress,keydown etc. overrides ?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,617

    Re: Custom controls - general perfomance question

    The same goes there. The OnSomeEvent method is for standard functionality that is common to every instance and the SomeEvent event handler is for functionality specific to that instance. The method will always be executed but the event handler will only be executed if there is one, so I would expect that an event handler would be slightly slower. Is that what you're seeing? The DRY principle also requires that you only write the common code in one place, not repeatedly in multiple event handlers.
    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    544

    Re: Custom controls - general perfomance question

    Is that what you're seeing? The DRY principle also requires that you only write the common code in one place, not repeatedly in multiple event handlers.
    Yes, that is why I asked. Specially Paint methods slows down UI, I'll just change my custom controls methods a bit....Otherwise I'm allways trying to follow principle "never write same code twice".

    Thanks JM

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width