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. Visual Basic
  4. Just wondering it this code is safe. Thanks for input. MESSAGE CLOSED

Just wondering it this code is safe. Thanks for input. MESSAGE CLOSED

Scheduled Pinned Locked Moved Visual Basic
6 Posts 3 Posters 0 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.
  • M Offline
    M Offline
    mo1492
    wrote on last edited by
    #1

    I've tried this implementation and it works but I am wondering if there are any underlying problems with it; ie Loading Panel at runtime. I am not that experienced in VB. Thanks Class MyClass Inherits UserControl Private WithEvents _MyParentPanel As Panel Private Sub PChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ParentChanged Me._MyParentPanel = CType(sender, Control).Parent end sub Private Sub ParentScrollChange(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles _MyParentPanel.Scroll ' Handle change End Sub End Class

    Richard DeemingR D M 3 Replies Last reply
    0
    • M mo1492

      I've tried this implementation and it works but I am wondering if there are any underlying problems with it; ie Loading Panel at runtime. I am not that experienced in VB. Thanks Class MyClass Inherits UserControl Private WithEvents _MyParentPanel As Panel Private Sub PChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ParentChanged Me._MyParentPanel = CType(sender, Control).Parent end sub Private Sub ParentScrollChange(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles _MyParentPanel.Scroll ' Handle change End Sub End Class

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      What happens if Parent is not a Panel?


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • M mo1492

        I've tried this implementation and it works but I am wondering if there are any underlying problems with it; ie Loading Panel at runtime. I am not that experienced in VB. Thanks Class MyClass Inherits UserControl Private WithEvents _MyParentPanel As Panel Private Sub PChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ParentChanged Me._MyParentPanel = CType(sender, Control).Parent end sub Private Sub ParentScrollChange(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles _MyParentPanel.Scroll ' Handle change End Sub End Class

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

        Yeah, there's lots of problems with it. We'll start with your assumption that the control will over ever be dropped on a Panel control. What if you accidentally drop it on a Form instead? You're code is going to throw an exception and the designer is going to show a problem that prevents rendering it and you'll probably freak out when that happens. A control can have many different control types as a parent. Change the references "Panel" to "Control" so you can support different container controls, including a Form since the Form class derives from Control. It's also not a good idea to rename your event handlers, specifically PChanged, to whatever is shorter. It make the code harder to read and understand without your eyes darting to the end of each line to figure out which event this method handles. Your name is also not descriptive at all. What's a "P" and what changes about it?

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        1 Reply Last reply
        0
        • M mo1492

          I've tried this implementation and it works but I am wondering if there are any underlying problems with it; ie Loading Panel at runtime. I am not that experienced in VB. Thanks Class MyClass Inherits UserControl Private WithEvents _MyParentPanel As Panel Private Sub PChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ParentChanged Me._MyParentPanel = CType(sender, Control).Parent end sub Private Sub ParentScrollChange(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles _MyParentPanel.Scroll ' Handle change End Sub End Class

          M Offline
          M Offline
          mo1492
          wrote on last edited by
          #4

          To All, Sorry for not providing enough information. I was focused on the implementation of whether Me._MyParentPanel = CType(sender,Control).Parent had any underlying issues as far as 'attaching' the control to the Panels Scroll event because of loading _MyParentPanel at runtime. I understand and agree with the issues you raised but: This control is for a specific application and will not be dropped onto the Panel or be used for any other purpose. It is created by a button click from the Panel and is added by the Panel onto the Panel. Thanks

          D 1 Reply Last reply
          0
          • M mo1492

            To All, Sorry for not providing enough information. I was focused on the implementation of whether Me._MyParentPanel = CType(sender,Control).Parent had any underlying issues as far as 'attaching' the control to the Panels Scroll event because of loading _MyParentPanel at runtime. I understand and agree with the issues you raised but: This control is for a specific application and will not be dropped onto the Panel or be used for any other purpose. It is created by a button click from the Panel and is added by the Panel onto the Panel. Thanks

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

            speedbump99 wrote:

            This control is for a specific application and will not be dropped onto the Panel or be used for any other purpose.

            Famous last words. Controls always start out that way, but then next year, "Hey! We've got this control we want to use somewhere else..." Do it right the first time.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            M 1 Reply Last reply
            0
            • D Dave Kreskowiak

              speedbump99 wrote:

              This control is for a specific application and will not be dropped onto the Panel or be used for any other purpose.

              Famous last words. Controls always start out that way, but then next year, "Hey! We've got this control we want to use somewhere else..." Do it right the first time.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              M Offline
              M Offline
              mo1492
              wrote on last edited by
              #6

              Thanks Dave, This app is for my personal use only and I am 'infinitely' sure that this control will never, ever, ever be used anywhere else. But I do appreciate your input. Best regards.

              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