In VB6 I used Image controls to give visible feedback when the mouse moves over a 'sensitive' area in a picture: set the borderstyle to fixedsingle and set it back to none when it's outside.
I am looking for a simple equivalent in VB2005. VB6 Image controls are transparent, but anything I can find in VB2005 in the form of (user-) controls is opaque (right ) and requires a lot of hassle with the underlying image.
So the functionality I am looking for is to let the user know where on a picture he can click, for further info and whatever. Without ruining the picture (a bitmap in a picturebox on a panel). Should be easy, but can't find any help in the help. Help!

VB6 Image control in VB2005 used as feedback device in a picture
ghw123
In have a lot of these areas and I want to draw them in at design time. There I also make a link to the the object that should do things like show some info when the user clicks, bring up a context menu etc.
C.Parent=Picturebox1 does work (even at design time with a public property Pparent -- until you move the damn thing. Then it is reset to the panel or form underneath.)
Also, at run time the feedback controls 'stay behind' noticeably when scrolling the picturebox. And the painting goes rather slowly.
I haven't even thought about the headache to keep track of these controls when the picture is scaled.
SnowJim
Hi - I've been playing with this a bit but not getting very far, sadly.
I hadn't noticed the delay in drawing the controls as I had only been using a simple image in the picture box, but I've since tried it with a much larger image and it is very noticeable. In fact there is a most disconcerting effect when you move the mouse over the control until it redraws fully. Turning double buffering on sorted that out, and it may have had some effect on the redraw but it is hard to tell. I fear this is something you may have to live with if you continue with the control idea.
I haven't played much with zooming images but I used the code from Bob Powells site at
http://www.bobpowell.net/zoompicbox.htm
and added the feedback control to his zoompicbox. Simply scaling the control bounds by the zoom factor works perfectly so it may be worth having a look to see how his method differs from yours.
If you dispense with the controls I think the only hard part would be writing the code to detect which area you were over when clicking. All the functionality you want to add could be written in a class and each area could be allocated an instance of that class.
Terrence Chan
Thank you. That is something I could not have found out on my own (in spite of the 4000+ pages of VB books). Pparent is over and done with..
When I scroll the picturebox(container), the picture scrolls quick enough, but the feedbackcontrols remain in the same position on the screen, with the 'old' underlying section of the picture. They get repainted a little (0.1 sec) later with the 'new' underlying section. In between they are noticeably present.
But you are right, that's not the intention: they should scroll and scale with the picture in the picturebox. With four transforms (translate to center, apply scrollbars, scale, translate back) and then drawimage the picture metafile scrolls and scales OK.
I tried the Setbounds method, but that uses pixels, not graphics it seems: they don't move . Do I have to manually have to transform the control bounds or is there a better way
Re dispensing with the controls at runtime: If I have to, I will do so. In fact I had something like that in VB6. But I intend to add more functionality to them, so then I must do a lot of passing and event firing, isn't it hence my reluctance to give up on the control idea. But ..
Cheiman
A transparent control isn't really transparent. It simply shows the background of its parent.
If you set the parent property of the feedback control to be your picturebox then you should find it still works. It does for me.
Simply add the line
C.Parent = PictureBox1
using your own picturebox name, to the form load event.An alternative way to do what you want would be to simply monitor the mouse position in the mouse move event and draw directly on the picturebox when it is within bounds which you can define in a series of rectangles. Something like the following:
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Dim R As New Rectangle(50, 50, 50, 50)
Dim R1 As New Rectangle(55, 55, 40, 40)
Dim P As New Pen(Color.Black)
p.Width = 10
If e.X > R.X And e.X < R.X + R.Width And e.Y > R.Y And e.Y < R.Y + R.Height Then
Dim G As Graphics = PictureBox1.CreateGraphics
G.DrawRectangle(P, R1)
G.Dispose()
Else
PictureBox1.Invalidate(R)
End If
P.Dispose()
End Sub
Duane Douglas
Dietz
Rather than using the standard PictureBox try adding a new class to your project as follows:
Imports System.ComponentModel
Imports System.ComponentModel.Design
<Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", GetType(IDesigner))> Public Class PictureBoxContainer
Inherits PictureBox
End Class
Build the project and this will then appear in the toolbox and you can use it instead of the PictureBox control.
You will then find that whatever you drop onto this new picturebox becomes a child of the box and you don't need the Pparent property on the feedback control which gives so much frustration.
Re: scrolling the PictureBox - I presume you mean that you are scrolling the panel on which the picturebox sits. Not sure what you mean by " feedback controls 'stay behind' noticeably". Aren't they invisible - how would you know.
Re: scaling the picture - don't you just need to scale all the bounds of the feedback controls by the same factor that you are scaling the picture.
Another thought if you have performance problems with the controls. What about just using them at design time so that you can position them visually but dispense with them when the application runs, copying their bounds to a series of rectangles and monitoring the mouse position with respect to the rectangles as suggested above.
Samaro
I've read a lot in these forums about the difficulty of making things transparent but personally I have never had a problem on my machine.
Have a look at the following which I think gives the effect you are after.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim C As New FeedbackControl
Me.Controls.Add(C)
C.SetBounds(50, 50, 50, 50)
End Sub
End Class
Public Class FeedbackControl
Inherits Control
Dim ShowBorder As Boolean
Dim P As New Pen(Color.Black)
Public Sub New()
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = Color.Transparent
P.Width = 10
AddHandler Me.MouseEnter, AddressOf ShowHighlight
AddHandler Me.MouseLeave, AddressOf RemoveHighlight
End Sub
Private Sub ShowHighlight(ByVal sender As Object, ByVal e As System.EventArgs)
ShowBorder = True
Invalidate()
End Sub
Private Sub RemoveHighlight(ByVal sender As Object, ByVal e As System.EventArgs)
ShowBorder = False
Invalidate()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
If ShowBorder Then
Dim R As New Rectangle(0, 0, Me.Width, Me.Height)
e.Graphics.DrawRectangle(P, R)
End If
End Sub
End Class