Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Unwanted Event firing

Unwanted Event firing

Scheduled Pinned Locked Moved Windows Forms
csharpdesignquestion
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    francoisdotnet
    wrote on last edited by
    #1

    Hi I have a composite (complex) CustomControl in VB.NET. In the *.Designer.vb file a control is set to a Settings value: Me.nudtags.Value = Global.Project1.My.MySettings.Default.pastags I suspect this fires the ValueChanged event (even though the Designer.vb file calls Me.SuspendLayout?) Private Sub nudtags_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudtags.ValueChanged DoMethod(nudtags.Value) End Sub The "DoMethod" can not run in design-time, but it fires and runs as soon as I add the control to a form (in the same project). There must be a way to prevent this event from firing in design time and/or after the CustomControl is loaded in runtime? :confused: PS: I tried Me.DesignMode but with no luck.

    D 1 Reply Last reply
    0
    • F francoisdotnet

      Hi I have a composite (complex) CustomControl in VB.NET. In the *.Designer.vb file a control is set to a Settings value: Me.nudtags.Value = Global.Project1.My.MySettings.Default.pastags I suspect this fires the ValueChanged event (even though the Designer.vb file calls Me.SuspendLayout?) Private Sub nudtags_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudtags.ValueChanged DoMethod(nudtags.Value) End Sub The "DoMethod" can not run in design-time, but it fires and runs as soon as I add the control to a form (in the same project). There must be a way to prevent this event from firing in design time and/or after the CustomControl is loaded in runtime? :confused: PS: I tried Me.DesignMode but with no luck.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      There is no way to stop an event from firing. you just have to get creative in the method you handle it at different times. The ValueChanged event fires because, well, the value changed. The Value has nothing to do with SuspendLayout. Normally, the value would be used as design time, as well as runtime, to update the visuals of the control in the designer. If you wanted to not run the DoMethod, I'd do something like this:

      Private Sub nudtags_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudtags.ValueChanged
      If Not DesignMode Then
      DoMethod(nudtags.Value)
      End If
      End Sub

      I've heard of DesignMode not being reliable, though I've never had aproblem with it. You might want to read this[^] for some clarifications.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        There is no way to stop an event from firing. you just have to get creative in the method you handle it at different times. The ValueChanged event fires because, well, the value changed. The Value has nothing to do with SuspendLayout. Normally, the value would be used as design time, as well as runtime, to update the visuals of the control in the designer. If you wanted to not run the DoMethod, I'd do something like this:

        Private Sub nudtags_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudtags.ValueChanged
        If Not DesignMode Then
        DoMethod(nudtags.Value)
        End If
        End Sub

        I've heard of DesignMode not being reliable, though I've never had aproblem with it. You might want to read this[^] for some clarifications.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        F Offline
        F Offline
        francoisdotnet
        wrote on last edited by
        #3

        I tried exactly what you had there before posting the question. That DesignMode for some reason returns False. Thanks for the reply. I think that article will be a help... For now I have worked around it with my own designmode boolean I set to false during runtime :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups