iron_guitarist1987
Member
Hello. I am having a problem with a program I made. Its an application for placing points on an image. It has a picture box inside a panel so the image can be scrolled. The problem is that depending where the point is placed, the point drawn is shifted. Please help me out. Here is the code:
thank you.
VB.NET:
Public Class Landmarks
Dim ima, ext As String
Dim picsize(2) As Integer
Dim x, y As Integer
Dim Img As Image
Private Sub PicBox_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PicBox.Click
Dim bmp As New System.Drawing.Bitmap(Img)
Dim graph As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)
Dim coordinate As String
x = e.X
y = (-1) * (e.Y) + PicBox.Height - 5
coordinate = CStr(x) & " " & CStr(y)
ListBox1.Items.Add(coordinate) 'adds x to listbox 1
graph.FillEllipse(Brushes.Blue, e.X, e.Y - 2, 5, 5) 'adds a filled circle in the picturebox
graph.DrawEllipse(Pens.Blue, e.X - 3, e.Y - 5, 11, 11) 'adds a ring around the filled circle
Img = bmp.Clone
PicBox.Image = Img
End Sub
Private Sub OpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFile.Click
ima = " "
ext = " "
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
ima = OpenFileDialog1.FileName
PicBox.Enabled = True
picsize(0) = Image.FromFile(ima).Height 'Stores the height of the picture
picsize(1) = Image.FromFile(ima).Width ' stores the width of the picture
PicBox.Height = picsize(0) 'sets the height of the picturebox = height of the picture
PicBox.Width = picsize(1) 'sets the width of the picturebox = width of the picture
PicBox.Image = Image.FromFile(ima) 'puts the picture into the picturebox
Img = Image.FromFile(ima)
Else
MsgBox("The extension is not supported.")
End If
End Sub
Private Sub PicBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PicBox.MouseMove
x = e.X
y = (-1) * (e.Y) + PicBox.Height - 5
coor.Text = CStr(x) & " " & CStr(y)
End Sub
End Class
thank you.