detect event starter, what info sender and e will return?

OSVBNET 1,391 Reputation points
2022-07-28T23:48:50.783+00:00

Hello

MyForm_Load Event::
Dim boolVal As Boolean = Registry.CurrentUser.OpenSubKey(my app settings address).GetValue(ValueName, DefaultData)
SwitchButton1.Value = boolVal

and:

Private Sub SwitchButton1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles SwitchButton1.ValueChanged
Registry.CurrentUser.CreateSubKey(my app settings address).SetValue(ValueName, ValueData, ValueKind)

SwitchButton1_ValueChanged will be called in 2 ways:
on formload .Value
or by clicking on it
both will return DevComponents.DotNetBar.Controls.SwitchButton for sender
anyway to distinguish them to call CreateSubKey only when clicking on it, not on form load?

(beside setting another boolean on form_load complete event and checking it)
Thanks :)

Developer technologies | VB
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2022-07-29T02:30:50.573+00:00

    Hi @OSVBNET ,
    Try adding events dynamically.

        Private Sub MyForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
            SwitchButton1.Value = boolVal  
            AddHandler SwitchButton1.ValueChanged, AddressOf SwitchButton1_ValueChanged  
        End Sub  
      
        Private Sub SwitchButton1_ValueChanged(sender As System.Object, e As System.EventArgs)  
            Registry.CurrentUser.CreateSubKey(My app settings address).SetValue(ValueName, ValueData, ValueKind)  
        End Sub  
    

    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.