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. event

event

Scheduled Pinned Locked Moved Visual Basic
helpcsharptutorialquestion
8 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.
  • H Offline
    H Offline
    helelark123
    wrote on last edited by
    #1

    Hello, I am working with VB.NET 2005. 1) I have class Chart that inherits from PictureBox 2) I have form that contains PictureBox1 The "connection" between them is as following: PictureBox1.Image = Chart.GetBitmap Now I have problems with events. I would like to mousemove on the Picturebox and get some info and this info is is my Chart object How to do? I tried this but I got error message:"End of statement expected" 'Form1 (Main Form) Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles PictureBox1.MouseMove RaiseEvent Chart.Chart_MouseMove() End Sub ----------------------------------------------- 'Class Chart that inherits from PictureBox Public Sub Chart_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 'Some infos End Sub Phease help

    Shay Noy

    D 1 Reply Last reply
    0
    • H helelark123

      Hello, I am working with VB.NET 2005. 1) I have class Chart that inherits from PictureBox 2) I have form that contains PictureBox1 The "connection" between them is as following: PictureBox1.Image = Chart.GetBitmap Now I have problems with events. I would like to mousemove on the Picturebox and get some info and this info is is my Chart object How to do? I tried this but I got error message:"End of statement expected" 'Form1 (Main Form) Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles PictureBox1.MouseMove RaiseEvent Chart.Chart_MouseMove() End Sub ----------------------------------------------- 'Class Chart that inherits from PictureBox Public Sub Chart_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 'Some infos End Sub Phease help

      Shay Noy

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      [Modified following re reading your post] The first thing to be aware of is your new class Chart can't raise events on the inherited (base class) picturebox If all you are wanting is information returned etc. create a public function in the class chart and call it from inside the mousemove event or wherever on the main form. If you do want to use events relating with your chart class, you will have to create these in your class and then when you declare the class in your form specify the withevents keyword. Then whatever code you are using in the class chart will have to fire these events. Hope that makes sense! Dave

      Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

      modified on Sunday, October 25, 2009 2:53 PM

      H 1 Reply Last reply
      0
      • D DaveAuld

        [Modified following re reading your post] The first thing to be aware of is your new class Chart can't raise events on the inherited (base class) picturebox If all you are wanting is information returned etc. create a public function in the class chart and call it from inside the mousemove event or wherever on the main form. If you do want to use events relating with your chart class, you will have to create these in your class and then when you declare the class in your form specify the withevents keyword. Then whatever code you are using in the class chart will have to fire these events. Hope that makes sense! Dave

        Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

        modified on Sunday, October 25, 2009 2:53 PM

        H Offline
        H Offline
        helelark123
        wrote on last edited by
        #3

        if I understood you right, see an example but it doesn't work: Put Picturebox on your form6 (for example) Public Class Form6 Private WithEvents ChartObj As New ChartClass Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler PictureBox1.MouseMove, AddressOf ChartObj.ChartClass_MouseMove AddHandler PictureBox1.MouseLeave, AddressOf ChartObj.ChartClass_MouseLeave End Sub End Class Public Class ChartClass Inherits PictureBox Public Sub ChartClass_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Cursor = Cursors.Default End Sub Public Sub ChartClass_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Cursor = Cursors.WaitCursor End Sub End Class My question is why the cursor is not changing?

        Shay Noy

        C D 2 Replies Last reply
        0
        • H helelark123

          if I understood you right, see an example but it doesn't work: Put Picturebox on your form6 (for example) Public Class Form6 Private WithEvents ChartObj As New ChartClass Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler PictureBox1.MouseMove, AddressOf ChartObj.ChartClass_MouseMove AddHandler PictureBox1.MouseLeave, AddressOf ChartObj.ChartClass_MouseLeave End Sub End Class Public Class ChartClass Inherits PictureBox Public Sub ChartClass_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Cursor = Cursors.Default End Sub Public Sub ChartClass_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Cursor = Cursors.WaitCursor End Sub End Class My question is why the cursor is not changing?

          Shay Noy

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I believe you'd need to click on the control for the move events to fire on that control. The enter event may work better ? Have you set breakpoints to see when the events are fired ?

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          H 1 Reply Last reply
          0
          • C Christian Graus

            I believe you'd need to click on the control for the move events to fire on that control. The enter event may work better ? Have you set breakpoints to see when the events are fired ?

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            H Offline
            H Offline
            helelark123
            wrote on last edited by
            #5

            Clicking on the control for the move events doesn't fire too. The enter event doens't work too I set breakpoints and the events fired. What is wrong?

            Shay Noy

            C 1 Reply Last reply
            0
            • H helelark123

              Clicking on the control for the move events doesn't fire too. The enter event doens't work too I set breakpoints and the events fired. What is wrong?

              Shay Noy

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              The breakpoint gets hit ? B/c it looks to me like you are saying you have a picturebox, not an instance of your derived class, on your form.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              1 Reply Last reply
              0
              • H helelark123

                if I understood you right, see an example but it doesn't work: Put Picturebox on your form6 (for example) Public Class Form6 Private WithEvents ChartObj As New ChartClass Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler PictureBox1.MouseMove, AddressOf ChartObj.ChartClass_MouseMove AddHandler PictureBox1.MouseLeave, AddressOf ChartObj.ChartClass_MouseLeave End Sub End Class Public Class ChartClass Inherits PictureBox Public Sub ChartClass_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Cursor = Cursors.Default End Sub Public Sub ChartClass_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Cursor = Cursors.WaitCursor End Sub End Class My question is why the cursor is not changing?

                Shay Noy

                D Offline
                D Offline
                DaveAuld
                wrote on last edited by
                #7

                I do not see the relationship between the PictureBox on your form and your class. As Christian States you need to add the chart onto your form as an instance. The code below will show you what i mean; Code For the Form;

                Public Class Form1

                Private WithEvents myChart As New Chart
                
                Public Sub New()
                
                    ' This call is required by the Windows Form Designer.
                    InitializeComponent()
                
                    ' Add any initialization after the InitializeComponent() call.
                    Me.Controls.Add(myChart)
                
                    myChart.Top = 50
                    myChart.Left = 50
                    myChart.BorderStyle = BorderStyle.FixedSingle
                    myChart.BackColor = Color.Aqua
                    myChart.Width = 300
                    myChart.Height = 300
                
                End Sub
                
                Private Sub myChart\_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles myChart.MouseMove
                    Debug.WriteLine("The Chart Mouse Is Moving")
                End Sub
                

                End Class

                Code for your Class;

                Public Class Chart
                Inherits PictureBox

                Private Sub Chart\_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
                    Debug.WriteLine("Mouse Is Moving")
                
                End Sub
                

                End Class

                Now if you run the code and look at the immediate window, you will see 2 debug messages, 1 showingthe mouse move event firing on the form, and 1 for the mouse move event being handled inside your class. Depending on what you are trying to achieve, you can handle either or both of these events as and where you need them.

                Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                H 1 Reply Last reply
                0
                • D DaveAuld

                  I do not see the relationship between the PictureBox on your form and your class. As Christian States you need to add the chart onto your form as an instance. The code below will show you what i mean; Code For the Form;

                  Public Class Form1

                  Private WithEvents myChart As New Chart
                  
                  Public Sub New()
                  
                      ' This call is required by the Windows Form Designer.
                      InitializeComponent()
                  
                      ' Add any initialization after the InitializeComponent() call.
                      Me.Controls.Add(myChart)
                  
                      myChart.Top = 50
                      myChart.Left = 50
                      myChart.BorderStyle = BorderStyle.FixedSingle
                      myChart.BackColor = Color.Aqua
                      myChart.Width = 300
                      myChart.Height = 300
                  
                  End Sub
                  
                  Private Sub myChart\_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles myChart.MouseMove
                      Debug.WriteLine("The Chart Mouse Is Moving")
                  End Sub
                  

                  End Class

                  Code for your Class;

                  Public Class Chart
                  Inherits PictureBox

                  Private Sub Chart\_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
                      Debug.WriteLine("Mouse Is Moving")
                  
                  End Sub
                  

                  End Class

                  Now if you run the code and look at the immediate window, you will see 2 debug messages, 1 showingthe mouse move event firing on the form, and 1 for the mouse move event being handled inside your class. Depending on what you are trying to achieve, you can handle either or both of these events as and where you need them.

                  Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                  H Offline
                  H Offline
                  helelark123
                  wrote on last edited by
                  #8

                  Thank you both Dave and Christian. I understood my mistake

                  Shay Noy

                  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