Hotspots in .Net
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 43

Thread: Hotspots in .Net

  1. #1
    Join Date
    Apr 2007
    Posts
    68

    Hotspots in .Net

    Hi All

    I am creating a Windows based application, my main screen is based on a picture, instead of using buttons, I would like to create hotspots on the picture for navigation, is this possible in the .net Windows application, this is not for the web.

    Cheers

    Djbel

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,946

    Re: Hotspots in .Net

    You can load an image directly onto a form, or onto a picturebox control. Then, you can capture mouse clicks, and compare the location to 'spots' that you activate, and fire in the 'click event' and produce the action.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2007
    Posts
    68

    Re: Hotspots in .Net

    Hi dglienna

    Thanks for the reply. unfortuantly I am not exactly clear on what you mean. Do you mean have a set of cordinates for each area, then take the position of a mouse click and check if it is within a set of coordinates, if it is then fire a click event? If this is the case just got a couple of questions, how do I set up a coordinate location for an area on a picture and secondly how would I do this for complex shapes such as circles, ect?

    Cheers

    Djbell

  4. #4
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Hotspots in .Net

    It is going be a bit more complicated if you are using irregular shaped hotspots.

    Using the mouseup event will give you coordinates clicked in the picbox. You will need a way to determine which region the clicked coordinates are in.

    Rectangular and circular regions should be relatively easy. I would create a class for your regions containing the following vars: region_type (enum), parameter1, parameter2
    region_type specifies whether the region is circular or rectangular. If circular, parameter1 is midpoint of circle and parameter2 is radius. If rectangular, parameter1 is upper left corner and parameter2 is lower right.

    You will need a routine that accepts your coordinates, checks through your regions and calls the appropriate function (this could happen in the region class if you do it that way).

    ps: have you looked at WPF ? I think this can be done on a WPF form.
    Last edited by HairyMonkeyMan; December 22nd, 2008 at 05:40 AM.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,946

    Re: Hotspots in .Net

    Not with a class of shapes, if they are all the same size (within circle or square dim's)

    Gets more complex with different sized shape, though
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    IF you control the picture, there is a simple trick...Use the LSB of each color. This allows for 7 hotspots in an impage without ANY calculations.

    Stegography in action!!!!
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,946

    Re: Hotspots in .Net

    Which 7 are those?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    Quote Originally Posted by dglienna View Post
    Which 7 are those?
    Use a 24/32 bit format. Make sure the "real" picture has only EVEN color values (LSB or R,G,B are 0.)

    Now modify the picture to the the LSB to 001,010,011,100,101,110,111 (R,G,B) for seven different areas.

    Now when you geta click, look at a the pixel. Grab the LSB of R,G,B; combine. If 000 then not a hotspot, otherwise it is one of the 7...
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  9. #9
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,946

    Re: Hotspots in .Net

    That sounds great. I'm trying to imagine it in my head, but a picture would be worth, well, 1000 words? (plus a after I spread some holiday cheer)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    Here...

    This blue picture is primarily made op of one color, with EVEN R,G,B values...

    Some of the pixels had had 1 lsb added to one or more of the colors.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  11. #11
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Hotspots in .Net

    TheCPUWizard, the solution is of course interesting. But how maintainable is it? Altering the background image on pixel level, at least for me, is a tedious task . Also, scalability is a factor to consider.

    Since you're using .NET, I suggest using one of the windows forms skinning techniques out there, or even create a HTML page, with regions, and place a web browser control on your form.
    Personally, I would go with skinning.

  12. #12
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    Maintaining the pictures is not a problem..IF you have a decemt layer based graphic editor. The primary advantage is that all of the information is contained in the image itself.

    --- If you need more hotspots, use 2 LSB, this give you 63 distinct ones on a single image.

    --- Alternatively, supply TWO images, one which you display and ony (often just 8 bit resultion) where each color in the second represents a different hotspot.

    I use this technique heavily becuase I am NOT a graphic designer, and outsource all my work [shameless plug: My eldest daughter graduated last year from university with a degree in graphic arts..].

    Most other techniques involve a tighter coupling beteween the visual information and the coding....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  13. #13
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,946

    Re: Hotspots in .Net

    Quote Originally Posted by TheCPUWizard View Post
    Now modify the picture to the the LSB to 001,010,011,100,101,110,111 (R,G,B) for seven different areas.

    Now when you geta click, look at a the pixel. Grab the LSB of R,G,B; combine. If 000 then not a hotspot, otherwise it is one of the 7...
    So, that means you change all pixels within the 'hotspot' so that you know when you're in the 'hotspot'

    That would be hard to resize, I'd imagine...

    The two-image idea sounds a lot better. You could resize only the visible image, and scale the mouse-clicks
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  14. #14
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Hotspots in .Net

    Quote Originally Posted by dglienna View Post
    So, that means you change all pixels within the 'hotspot' so that you know when you're in the 'hotspot'
    Exactly. Not that this will NOT work with "lossy" compressed formats like jpeg).

    That would be hard to resize, I'd imagine...

    The two-image idea sounds a lot better. You could resize only the visible image, and scale the mouse-clicks
    Resizing (regardless of methodology) does introduce some difficulty. In most cases a little "fuzzyness" in the determination may be acceptable, but in others it can be a problem.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  15. #15
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Hotspots in .Net

    I took the chance to try something..

    here is a quick project just to test if this can work ..

    I created a second Jpg in greyscale with each region in a different color .. there is still a little 'Noise' between regions as i did not do it 100%, but just a quick test..

    I used steps of 10 for each region, so region 1 is 0, region 2 is 10, etc ... (255 = background)

    I used two pictureboxes, one to show the Sized /Stretched image, and a hidden one to hold full size image..

    I then translated the cursor position to actual on the image and get the Regions color on that spot.. no problems with image stretch color distortion with this method..

    Hope it works for you..


    Gremmy...

    --EDIT--
    Fixed Zip on later post
    Last edited by GremlinSA; January 15th, 2009 at 01:50 AM. Reason: Newfile uploaded...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Page 1 of 3 123 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center