Results 1 to 33 of 33

Thread: How to write code for of focus event

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2023
    Posts
    10

    How to write code for of focus event

    I need help with writing a code that each textbox on Gotfocus has backcolor Red and on Lostfocus has backcolor white.

    Instead of writing on each text box Got Foucs and Lost Focus event , I tried writing a class Module (Class1)
    Code:
    -----------------------------------------------------
     Option Explicit
    Private WithEvents cmb As ComboBox
    Private WithEvents txt As TextBox
    Private WithEvents txtcname As TextBox
    Private lbl As Object
    --------------------------------------------------------
    Public Sub setcontrols(Ctl As Object)
        Select Case VBA.UCase(VBA.TypeName(Ctl))
            Case "TEXTBOX"
                Set txt = Ctl
            Case "COMBOBOX"
                Set txt = Ctl
            Case "LABEL"
                Set txt = Ctl
            End Select
    End Sub
    --------------------------------------------------
    Private Sub cmb_GotFocus()
    txt.BackColor = vbBlue
    End Sub
    -----------------------------------------------
    Private Sub cmb_LostFocus()
    txt.BackColor = vbRed
    End Sub
    ------------------------------------------------
    Private Sub txt_GotFocus()
    txt.BackColor = vbRed
    End Sub
    ----------------------------------------------
    Private Sub txt_LostFocus()
    txt.BackColor = &H80000005
    End Sub
    =============================
    My Form Code On Load is :
    Private clsFC As New Class1

    clsFC.setcontrols Tex1
    clsFC.setcontrols Tex2..... so
    (I there a way to get Textbox Name as we are on that textbox instead writing Text1, Text2, Text3 and so on
    Last edited by Shaggy Hiker; Jan 30th, 2023 at 09:29 AM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,943

    Re: How to write code for of focus event

    I edited the post to add [CODE][/CODE] tags. You can do that with the # button.

    This looks like VBA, is that correct?
    My usual boring signature: Nothing

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Personally, I'd probably just do it like you're doing it.

    However, you could make a call in every GotFocus event, and then build a loop using the Controls collection to make the backgrounds white of everything that didn't have the focus. If you didn't pass the control that had the GotFocus event, you'd need to make a couple of API calls to figure out which control actually had the focus, but that's not terribly difficult.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2023
    Posts
    10

    Re: How to write code for of focus event

    Sorry I am new to this Fourms. No sure if you have modified the code. and if so where can I see that

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,126

    Re: How to write code for of focus event

    If you have multiple textboxes, it is often better to use an ARRAY of them...then its easy to find the 'name' (or any other property of that textbox).

    EDIT:
    For example...a form with multiple textboxes (Text1(0), text1(1)....etc and multiple comboboxes (combo1(0), combo1(1), etc..., ALL you need is this to set the BG colors upon focus: (can do this for any control that has a GotFocus and backcolor properties)

    Code:
    Private Sub Text1_GotFocus(Index As Integer)
        Text1(Index).BackColor = vbRed
    End Sub
    
    
    Private Sub Text1_LostFocus(Index As Integer)
        Text1(Index).BackColor = vbWhite
    End Sub
    
    
    Private Sub combo1_GotFocus(Index As Integer)
        Combo1(Index).BackColor = vbBlue
    End Sub
    
    
    Private Sub combo1_LostFocus(Index As Integer)
        Combo1(Index).BackColor = vbRed
    End Sub
    Last edited by SamOscarBrown; Jan 30th, 2023 at 11:53 AM.
    Sam I am (as well as Confused at times).

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2023
    Posts
    10

    Re: How to write code for of focus event

    Thank you for your help , this is great.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,943

    Re: How to write code for of focus event

    Quote Originally Posted by bickmahal10 View Post
    Sorry I am new to this Fourms. No sure if you have modified the code. and if so where can I see that
    Not sure who you are replying to, here. If it is to me, I didn't modify the code any, just wrapped it in the tags so that it shows up formatted...better. Nobody else can edit a post that you make.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2023
    Posts
    10

    Re: How to write code for of focus event

    yes Shaggy Hiker I replied to you. Wasn't really sure what was going on. Thank you for the help

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2023
    Posts
    10

    Re: How to write code for of focus event

    What if I want to without Array

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,126

    Re: How to write code for of focus event

    See post #3....BUT, arrays are most certainly the way you should go (given what little code you have shown).
    Sam I am (as well as Confused at times).

  11. #11
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,383

    Re: How to write code for of focus event

    Quote Originally Posted by SamOscarBrown View Post
    See post #3....BUT, arrays are most certainly the way you should go (given what little code you have shown).
    Not if it's in Office-VBA.
    No Control-Arrays there
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,126

    Re: How to write code for of focus event

    Oh yeah...I had forgotten he is (??) using VBA....hence, this thread should be moved to the Office Development Forum of these fora.
    Sam I am (as well as Confused at times).

  13. #13
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,383

    Re: How to write code for of focus event

    Quote Originally Posted by SamOscarBrown View Post
    Oh yeah...I had forgotten he is (??) using VBA....hence, this thread should be moved to the Office Development Forum of these fora.
    How do you figure that?
    Because his code-snippet has "VBA.UCase"?
    That's valid code in vb6
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  14. #14
    Hyperactive Member
    Join Date
    Jan 2018
    Posts
    264

    Re: How to write code for of focus event

    Just a warning - if you do end up putting event handlers into a separate class in VB, you'll also need to manually clear them when you're done, or else you end up leaking memory.

    So in Class1:
    Code:
    Public Sub clearcontrols()
        Set txt = Nothing
        Set cmb = Nothing
        Set txtcname = Nothing
    End Sub
    and then in the form that uses it:
    Code:
    Private Sub Form_Unload(Cancel As Integer)
        clsFC.clearcontrols
    End Sub

  15. #15
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,126

    Re: How to write code for of focus event

    OK Z, got me....! Anyway, I DID add those three question marks!!!
    Sam I am (as well as Confused at times).

  16. #16
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,095

    Re: How to write code for of focus event

    Quote Originally Posted by ahenry View Post
    Just a warning - if you do end up putting event handlers into a separate class in VB, you'll also need to manually clear them when you're done, or else you end up leaking memory.

    So in Class1:
    Code:
    Public Sub clearcontrols()
        Set txt = Nothing
        Set cmb = Nothing
        Set txtcname = Nothing
    End Sub
    and then in the form that uses it:
    Code:
    Private Sub Form_Unload(Cancel As Integer)
        clsFC.clearcontrols
    End Sub
    Btw, no need for an extra clearcontrols procedure. Just setting clsFC to Nothing in Form_Unload should be enough.

    cheers,
    </wqw>

  17. #17
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,294

    Re: How to write code for of focus event

    I don't get it, where exactly is the memory leak? I thought all objects are released automatically when the program is closed?

  18. #18
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Quote Originally Posted by VanGoghGaming View Post
    I don't get it, where exactly is the memory leak? I thought all objects are released automatically when the program is closed?
    Object "references" release automatically when the object variable falls out of scope (or is set to Nothing). Objects release when their reference count goes to zero.

    And, it's pretty difficult to have a memory leak without getting into API calls, and I don't see any in this thread. We may "accidentally" leave objects instantiated, but that's not exactly a memory leak.

    VB6 is pretty bullet-proof with respect to memory leaks.
    Last edited by Elroy; Feb 1st, 2023 at 06:14 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  19. #19
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,294

    Re: How to write code for of focus event

    Yeah exactly, so what's the point to set the object to Nothing in the Form_Unload event when it will obviously "go out of scope" along with everything else as the program will close imminently?

    To be fair I did happen to leave ActiveX EXE objects hanging in the air (visible in Task Manager) when I failed to destroy all references to them but that's another story since the ActiveX EXE is running in its own process...
    Last edited by VanGoghGaming; Feb 1st, 2023 at 06:15 PM.

  20. #20
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Hi VanGogh,

    Actually, if you use the auto-instantiated variable names that are the same as form class names, the COM/code portion of forms never falls out of scope. There are several ways to handle this. One is to do something like Set Form1 = Nothing in the Form_Unload event. Another, which I see frequently used, is to just never use those auto-instantiating variables.

    This is one case where you do have to be careful if you're depending on that COM/code portion to be uninstantiated (which, in most cases, doesn't matter).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  21. #21
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Also, I did think of one way to have a memory leak without API calls:

    Code:
    Option Explicit
    
    Private Type udt1
        i As Long
        s As String
    End Type
    
    Private Sub Form_Load()
    
        Dim u1 As udt1
        Dim u2 As udt1
        
        
        u1.s = "asdf asdfd asdfd"
        
        
        LSet u1 = u2
        
    End Sub
    But that's pretty unusual, and the LSet statement is a bit unusual in that respect.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  22. #22
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Also, here's proof that the COM/code portion of a form (when using it's name as an auto-instantiating variable) doesn't get uninstantiated.

    A project with nothing but a Form1 and Form2 (starting with Form1).

    Code for Form1:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
    
        Load Form2
        Form2.TestVar = 123
        Form2.Show vbModal
        
        Form2.Show vbModal  ' Just do it again.
    
    End Sub
    Code for Form2:
    Code:
    Option Explicit
    
    Public TestVar As Long
    
    
    Private Sub Form_Activate()
        MsgBox TestVar
    
        Unload Me
    End Sub
    Both times that Form2 is shown modally, the MsgBox reports "123". If the COM/Code portion of Form2 got uninstantiated with Form2 was unloaded, on the second time through, that MsgBox should have reported "0".

    -------------------

    ADDED: To fix/change that behavior, try this instead for the Form2 code:
    Code:
    Option Explicit
    
    Public TestVar As Long
    
    
    Private Sub Form_Activate()
        MsgBox TestVar
    
        Unload Me
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        Set Form2 = Nothing
    End Sub
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  23. #23
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    And, to say one more thing, if I were to use a Class in conjunction with a Form, I'd declare that Class's object variable within the Form. That way, when the COM/code portion of the Form gets uninstantiated, so does the Class's variable.

    But that does go back to the point above, that we've got to understand how/when our Form's COM/code section gets uninstantiated.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  24. #24
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,294

    Lightbulb Re: How to write code for of focus event

    There's nothing unusual about that code, in fact this behavior of the "Unload" statement is even documented in MSDN:

    "Note When a form is unloaded, only the displayed component is unloaded. The code associated with the form module remains in memory."

    The fact that the form's code remains in memory doesn't mean it should be set to "Nothing" though. That memory will be released as soon as the program is terminated. Also there is an added benefit that the code remains in memory because it allows you to create a new form property such as "IsLoaded" which helps you prevent an ill-fated "Unload" statement causing "Form_Load" to be executed again unwittingly:

    Code:
    Private m_bIsLoaded As Boolean
    
    Public Property Get IsLoaded() As Boolean
        IsLoaded = m_bIsLoaded
    End Property
    
    Public Property Let IsLoaded(bIsLoaded As Boolean)
        m_bIsLoaded = bIsLoaded
    End Property
    
    Private Sub Form_Load()
        IsLoaded = True
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        IsLoaded = False
    End Sub
    
    If Form1.IsLoaded Then Unload Form1

  25. #25
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Quote Originally Posted by VanGoghGaming View Post
    There's nothing unusual about that code, in fact this behavior of the "Unload" statement is even documented in MSDN:

    "Note When a form is unloaded, only the displayed component is unloaded. The code associated with the form module remains in memory."

    The fact that the form's code remains in memory doesn't mean it should be set to "Nothing" though. That memory will be released as soon as the program is terminated. Also there is an added benefit that the code remains in memory because it allows you to create a new form property such as "IsLoaded" which helps you prevent an ill-fated "Unload" statement causing "Form_Load" to be executed again unwittingly,
    Ok, I didn't say it was unusual. I was simply pointing out that it's not entirely intuitive to the uninitiated. And also, in relation to some of the things discussed above, if we declare object variables at the module level in a form, they're not automatically uninstantiated just because the form is unloaded. Said a bit differently, we have to appreciate when exactly things fall out of scope, and it's not necessarily just because we've unloaded a form.

    Also, you talk about Form_Load. Form_Load is raised every time the form is loaded, regardless of whether or not the associated form's COM/code portion is already instantiated.

    The only thing that's not raised when a form is re-loaded (if the COM/code portion wasn't uninstantiated) is the Form_Initialize event. Form_Initialize and Form_Terminate directly correspond to the COM/code portion, whereas things like Form_Load, Form_Activate, Form_Unload, etcetera have only to do with the form's UI portion.

    And, on another point, all code in a specific project is loaded the moment we execute that project. That's inclusive of all code in BAS, FRM, & CLS modules. Now, whether or not a set of variables associated with one of those classes is instantiated, that's another issue. But the code is already in memory. We may be able to do some fancy stuff with the linker (with OBJ files during compile-and-link) to change that. But, by default, VB6 never does that.
    Last edited by Elroy; Feb 2nd, 2023 at 09:34 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  26. #26
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,095

    Re: How to write code for of focus event

    Quote Originally Posted by VanGoghGaming View Post
    There's nothing unusual about that code, in fact this behavior of the "Unload" statement is even documented in MSDN:

    "Note When a form is unloaded, only the displayed component is unloaded. The code associated with the form module remains in memory."
    The documentation is wrong. The "code" of the form always "remains in memory" (i.e. the DLL/EXE is rarely unloaded) and this is never source of memory leaks.

    Such poor verbiage has been a source of countless confusion in devs trying to understand the duality of the forms subsystem in VB6.

    It's the instance *data* (so called object in OOP parlance) which remain in memory until Form_Terminate is raised i.e. until last reference to the instance is set to Nothing.

    cheers,
    </wqw>

  27. #27
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,294

    Re: How to write code for of focus event

    The way I'm reading that "Note" from MSDN, it says exactly the same thing you're saying...

  28. #28
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,095

    Re: How to write code for of focus event

    Quote Originally Posted by VanGoghGaming View Post
    The way I'm reading that "Note" from MSDN, it says exactly the same thing you're saying...
    "The code associated with the form module remains in memory" is not the same for me.

    The code associated with the form module for me is the (assembly) binary code for Form_Load and for the other procedures of say Form1. The code is pratically never unloaded.

    Could happen on memory pressure when COM asks all in-proc servers (that is DLLs, not the main EXE) to check if there are no outstanding instances of *any* coclass they are serving and to shutdown but this is very rare occurance in practice.

    Edit: Now I see what you mean. Yes, formally the statement "code remains in memory" is true. The code always remains in memory as it's never unloaded, no need to discuss it :-))

    The interesting part is if the instance *data* remains in memory, not the code handling the form procedures. Code cannot leak, instance data can (and will) and that has some point discussing of what happens on Form_Unload.

    cheers,
    </wqw>

  29. #29
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Quote Originally Posted by wqweto View Post
    Could happen on memory pressure when COM asks all in-proc servers (that is DLLs, not the main EXE) to check if there are no outstanding instances of *any* coclass they are serving and to shutdown but this is very rare occurance in practice.
    I assume you're talking about OS paging and virtual memory. For me, that's at an entirely different level, a level that individual programs never "think" about. And, in a sense, it's still memory, just memory that's been "paged" out to a file maintained by the Windows OS while it's not being used. Technically, I guess it's not memory "chips", but it's also not going back to the EXE file.

    ---------------

    Actually, upon another reading, maybe that's not what you're talking about. Yeah, I do use quite a few ActiveX DLLs in my main project. And I do load-and-unload those explicitly on an as-needed basis. And yeah, that is a case where things are pulled from disk when needed, and not necessarily when the EXE is executed. I explicitly load my AX-DLLs so that I don't have to register them, so I know precisely when they're in memory and when they're not.

    But even in this case, when the AX-DLL is loaded, all of its code is loaded, regardless of whether or not any of its classes are instantiated.

    And, for me, that's why I was careful to say "specific project" in the above...
    all code in a specific project is loaded the moment we execute that project
    Last edited by Elroy; Feb 2nd, 2023 at 09:46 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  30. #30
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,095

    Re: How to write code for of focus event

    There is CoFreeUnusedLibraries API which calls DllCanUnloadNow export on each loaded DLL (if available).

    DllCanUnloadNow function is like DllRegisterServer function (which is called by regsvr32.exe) but the export is called by COM on the currently loaded in-proc servers.

    cheers,
    </wqw>

  31. #31
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Quote Originally Posted by wqweto View Post
    There is CoFreeUnusedLibraries API which calls DllCanUnloadNow export on each loaded DLL (if available).

    DllCanUnloadNow function is like DllRegisterServer function (which is called by regsvr32.exe) but the export is called by COM on the currently loaded in-proc servers.
    Yeah, that's something I've wondered about. However, since I almost never use "registered" ActiveX libraries, I never really pursued it.

    Also, on a related note, I've wondered if/when standard DLLs get loaded/unloaded in VB6 (non-ActiveX, StdCall DLLs). However, that's getting pretty far afield from this thread's OP. I'll start another thread.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  32. #32
    Hyperactive Member
    Join Date
    Jan 2018
    Posts
    264

    Re: How to write code for of focus event

    Yes, I was referring to classes remaining instantiated in memory. And if you get fancy, that could mean having a reference to a control on an unloaded form, which is trouble.

    But I'm sure I've run into situations where not setting a WithEvents reference to Nothing caused an issue that wasn't a problem for normal references. I just can't think of the details now.

  33. #33
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,817

    Re: How to write code for of focus event

    Quote Originally Posted by ahenry View Post
    Yes, I was referring to classes remaining instantiated in memory. And if you get fancy, that could mean having a reference to a control on an unloaded form, which is definite trouble.

    But I'm sure I've run into situations where not setting a WithEvents reference to Nothing caused an issue where a normal reference was properly cleared, I just can't think of the details now.
    Yeah, that can be a problem.

    I do pass controls to little "quickly do something, like maybe set the back color" procedures, but I never save object references to controls outside of the actual form using them ... and I think that's a very good policy.

    Even if I have a class using WithEvents for some control, that class's object is declared inside the form's code. And I'm also very good at making sure any form's COM/code portion is uninstantiated when the form is unloaded (which will uninstantiate that WithEvents class). That's yet another reason to get these COM/code portions of forms uninstantiated (which typically doesn't happen automatically).
    Last edited by Elroy; Feb 2nd, 2023 at 12:26 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

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