How do i validate settings using the project manager generated My.Settings in VB.Net?

56 Views Asked by At

The code below does not work, the error says the method ValidateSettings does not have a signature compatable with delgate 'Delgate Sub SettingChangingEventHandler(sender as Object, e as SettingChangingEventArgs)'

This error shows up when hovering over [...] AddressOf ValidateSettings

    Private Sub ValidateSettings(sender As Object, e As SettingChangingEventArgs)


    End Sub

    Private Sub frm_Settings_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        AddHandler My.Settings.SettingChanging, AddressOf ValidateSettings
        PropertyGrid_Settings.SelectedObject = My.Settings
        CenterToParent()
    End Sub

Im using this tutorial

1

There are 1 best solutions below

0
Bartekchrup On

The solution was to add Imports System.Configuration to the class, as pointed out by a comment on the original post.

Imports System.Configuration
Public Class frm_Settings

    Private Sub ValidateSettings(sender As Object, e As SettingChangingEventArgs)
        'validation and notifying user
        MsgBox(e.NewValue)
    End Sub

    Private Sub frm_Settings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler My.Settings.SettingChanging, AddressOf ValidateSettings
        PropertyGrid_Settings.SelectedObject = My.Settings

        CenterToParent()
    End Sub