image map in vb.net?-VBForums
Results 1 to 10 of 10

Thread: image map in vb.net?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    69

    image map in vb.net?

    Hello, I have a small app I'm working on in VB.NET. On a form I have an image of Ohm's Law Wheel, which I attached. I want the user to be able to click any one of these formulas and then that calculation can be performed. So, is there a way to do an imagemap type control like in html? Or do I need to split this image up and do it that way? Any help would appreciated...

    http://www.vbforums.com/attachment.p...1&d=1283193100
    Attached Images Attached Images  

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: image map in vb.net?

    The short answer is yes. However, it depends how complex you want this. You could pretty easily take some basic coordinate data and hit test against it on a click. The complexity comes in if you are wanting colors to change when a person highlights over the formula etc... In that case you would have to draw that whole image yourself.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    69

    Re: image map in vb.net?

    Ok, changing the colors is not really necessary... I will have labels and textbox controls near by that will react to the click so it will definitely be apparent when a different formula has been clicked. But how do I do coordinates? Can you point me in the right direction?

    Ok, I figured out how to display coordinates of the mouse pointer while it's over the image, that wasn't so bad.. but I guess now I have to hover over each area of the wheel and write down the coordinates of the shape containing each formula... would I then have to do like a case select type logic to say if the click was within these coordinates, do this, etc?
    Last edited by CanaanP; Aug 30th, 2010 at 02:36 PM.

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: image map in vb.net?

    Take a look at this sample project...
    Attached Files Attached Files

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    69

    Re: image map in vb.net?

    Wow, there's a lot in there that is above my head. But it does appear to be exactly what I want. One thing though, is it possible for this to be done invisibly? I don't want the blue lines to show at all. But I will try to digest all of this and see what I can learn from it. Thanks.

  6. #6
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: image map in vb.net?

    Yeah, just comment or remove the code out. You will see it in the Paint event handler of the PictureBox.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    69

    Re: image map in vb.net?

    I am having trouble figuring out how to define the next polygon... I thought that if I copied your subs that mention polygonf and pointf and just use something else like polygon1 and point1 I should be ok, but I'm doing something wrong... can you give me a hint on how to establish a new polygon? I already have the coordinates I want to use, I just don't know how to write the code. Thanks

  8. #8
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: image map in vb.net?

    The only part you would have to change is this part:


    vb.net Code:
    1. '//...code
    2.  
    3.     '//constructors
    4.     Public Sub New()
    5.  
    6.         Dim pts As New List(Of PointF)()
    7.  
    8.         pts.Add(New PointF(70, 160))
    9.         pts.Add(New PointF(215, 244))
    10.         pts.Add(New PointF(242, 217))
    11.         pts.Add(New PointF(159, 71))
    12.         pts.Add(New PointF(70, 160))
    13.  
    14.         Me.formulas.Add(New Formula(New PolygonF(pts.ToArray()), "P=RI^2"))
    15.  
    16.         Me.InitializeComponent()
    17.  
    18.         Me.PictureBox1.Image = My.Resources.OhmsLawWheel
    19.  
    20.     End Sub
    21.  
    22.     '//...code

    This is where I create an object to store the coordinate data. So if you have the coordinate data for the next polygon you would make it look like this:

    vb.net Code:
    1. '//...code
    2.  
    3.     '//constructors
    4.     Public Sub New()
    5.  
    6.         Dim pts As New List(Of PointF)()
    7.  
    8.         pts.Add(New PointF(70, 160))
    9.         pts.Add(New PointF(215, 244))
    10.         pts.Add(New PointF(242, 217))
    11.         pts.Add(New PointF(159, 71))
    12.         pts.Add(New PointF(70, 160))
    13.  
    14.         Me.formulas.Add(New Formula(New PolygonF(pts.ToArray()), "P=RI^2"))
    15.  
    16.         '//create next polygon
    17.         pts = New List(Of PointF)()
    18.         pts.Add(New PointF(X, Y))
    19.         pts.Add(New PointF(X2, Y2))
    20.         '//etc...
    21.         pts.Add(New PointF(X, Y))
    22.         Me.formulas.Add(New Formula(New PolygonF(pts.ToArray()), _
    23.                                                  "Formula XYZ"))
    24.  
    25.         Me.InitializeComponent()
    26.  
    27.         Me.PictureBox1.Image = My.Resources.OhmsLawWheel
    28.  
    29.     End Sub
    30.  
    31.     '//...code

    The project I posted is a very rough draft but you can adapt its concepts to suit your needs.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    69

    Re: image map in vb.net?

    Got it, thank you very much... this is awesome.

  10. #10
    Member kamakaki's Avatar
    Join Date
    Jul 2011
    Location
    Greece
    Posts
    56

    Re: image map in vb.net?

    Nice code.

    If someone can help for this.

    I have this two List of points

    Code:
    ublic Sub New()
    
            Dim pts As New List(Of PointF)()
    
            pts.Add(New PointF(70, 160))
            pts.Add(New PointF(215, 244))
            pts.Add(New PointF(242, 217))
            pts.Add(New PointF(159, 71))
            pts.Add(New PointF(70, 160))
    
            Me.formulas.Add(New Formula(New PolygonF(pts.ToArray()), "P=RI^2"))
    
            pts = New List(Of PointF)()
            pts.Add(New PointF(278, 42))
            pts.Add(New PointF(278, 203))
            pts.Add(New PointF(243, 218))
            pts.Add(New PointF(160, 72))
    
            Me.formulas.Add(New Formula(New PolygonF(pts.ToArray()), "E^2/R"))
    
            Me.InitializeComponent()
    
            Me.PictureBox1.Image = My.Resources.OhmsLawWheel
    How to change this code (or what ever)
    Code:
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    
            For Each f In Me.formulas
                Using p As New Pen(Color.Blue, 4)
                    e.Graphics.DrawPolygon(p, f.Polygon.Points)
                End Using
            Next
    
        End Sub
    How to show blue line in only one list of points, where the mouse is clicking or mouse is over???
    what - how -where - when - who ...(like all newbies )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.