Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Putting point where click

Status
Not open for further replies.

DeeDee

Programmer
Jul 13, 2000
34
US
I want to put an X or a point on a picturebox where the user clicks. I tried using a shape (circle), and it works, but it doesn't leave it at the position you clicked last if you click somewhere else. I need it to show every point that is clicked. Here's what I have:

Shape1.Left = CStr(x)
Shape1.Top = CStr(y)
Form1.Shape1.Visible = True

Thanks for any help in advance!!

 

To use a shape object in the fashion that you want you will have to create a control array. Change the index of the one that you have to zero (0). Then at run time you will have to load and display as needed.

OR

You could use the circle and line methods

[tt]
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Picture1.Circle (X, Y), 200, 0

End Sub

'OR

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Picture1.Line (X - 100, Y - 100)-(X + 100, Y + 100)
Picture1.Line (X + 100, Y - 100)-(X - 100, Y + 100)

End Sub

[/tt]

Good luck
 
I have a small problem. I lied, I have an Imagebox instead of a picturebox because I couldn't get the whole picture to show in the pb unless it took up the whole screen. So, is there a way to show the whole thing in a picturebox so I can use the line property? Or, if I have to keep the imagebox, is there another way to put a point where the user clicked? Sorry!!
 

Yes, add a MDI form to your project and make your form that you display your image in a MDIChild. Then

[tt]
Option Explicit

Private Sub Form_Load()

Picture1.Top = 30
Picture1.Left = 30
Picture1.AutoSize = True
Picture1.Picture = LoadPicture("C:\z\usa.jpg")
DoEvents

Me.Width = Picture1.Width + 90
Me.Height = Picture1.Height + 90

End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

'Picture1.Circle (X, Y), 200, 0
Picture1.Line (X - 100, Y - 100)-(X + 100, Y + 100)
Picture1.Line (X + 100, Y - 100)-(X - 100, Y + 100)

End Sub

[/tt]

The MDI parent will (if necessary) create scrollbars (true) if the child form is larger than the display area of the MDIParent. This will allow you to use the picture box on a form that displays a picture larger than the display area of the form, or for that matter larger than the display area of the screen itself.

Good Luck

 

Ok yeah, you will also have to set the autoredraw of the picture box = true to keep the x's or o's from being wiped away because of scrolling.

 
Is there any way to do it to where I can have the picture in an area with a set size instead of having to scroll? I need the picture to be a certain size on the form.
 

Ok back to the imagebox (not picture box)

[tt]
Option Explicit

Dim ControlCount As Integer

Private Sub Form_Load()

Image1.Picture = LoadPicture("C:\z\usa.jpg")

End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

ControlCount = ControlCount + 1
Load Shape1(ControlCount)
Shape1(ControlCount).Left = X '(X - (Shape1(ControlCount).Width / 2))
Shape1(ControlCount).Top = Y '(Y - (Shape1(ControlCount).Height / 2))
Shape1(ControlCount).Visible = True
Shape1(ControlCount).ZOrder 0

End Sub
[/tt]

As per my previous post by using a control array you can accomplish what you want with what you have.

I hope this helps, Good Luck
 
That works perfect. Thank you soooo much!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top