correction
Imports System
Imports System.Drawing.Imaging
Public Class Form1
#Region "declaration"
Private WithEvents mytoolstripbar As New ToolStrip
Private WithEvents planimage As New ToolStripButton
Private WithEvents barimage As New ToolStripButton
Private WithEvents saveimage As New ToolStripButton
Private WithEvents Eraseall As New ToolStripButton
Private xp, yp As Integer
Private flagplan As Boolean
Private counter As Integer
Private Structure barcodeimage
Public imagebarcode As Bitmap
Public idimage As Integer
End Structure
Private Structure barcodedata
Public locationbarcode As Point
Public barcodeid As Integer
End Structure
Private listbarcodeimage As New List(Of barcodeimage)
Private lastmouselocation As New Point
Private listlocationbarcode As New List(Of barcodedata)
#End Region
#Region "design"
Private Sub DesignToolstripBar()
mytoolstripbar.BackColor = Color.Cornsilk
Me.Controls.Add(mytoolstripbar)
With planimage
.Font = New Font("arial", 12, FontStyle.Bold)
.BackColor = Color.PowderBlue
.Text = "Plan image"
.ToolTipText = "loading plan image"
End With
mytoolstripbar.Items.Add(planimage)
mytoolstripbar.Items.Add(New ToolStripSeparator)
With barimage
.Font = New Font("arial", 12, FontStyle.Bold)
.BackColor = Color.PowderBlue
.Text = "Les barcodes"
.ToolTipText = "loading barcode image"
.Enabled = False
End With
mytoolstripbar.Items.Add(barimage)
mytoolstripbar.Items.Add(New ToolStripSeparator)
With saveimage
.Font = New Font("arial", 12, FontStyle.Bold)
.BackColor = Color.PowderBlue
.Text = "Save image"
.ToolTipText = "save image"
.Enabled = False
End With
mytoolstripbar.Items.Add(saveimage)
mytoolstripbar.Items.Add(New ToolStripSeparator)
With Eraseall
.Font = New Font("arial", 12, FontStyle.Bold)
.BackColor = Color.PowderBlue
.Text = "Nouveau"
.ToolTipText = "Nouveau"
.Enabled = False
End With
mytoolstripbar.Items.Add(Eraseall)
End Sub
#End Region
#Region "events"
Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim thebarcodedata As New barcodedata
If e.Cancel = True Then Exit Sub
If flagplan Then
Panelframe.Visible = True
Panelframe.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName)
Panelframe.Width = Panelframe.BackgroundImage.Width
Panelframe.Height = Panelframe.BackgroundImage.Height
Panelframe.Location = New Point(0, mytoolstripbar.Bottom + 2)
Panelframe.BackgroundImageLayout = ImageLayout.None
planimage.Enabled = False
barimage.Enabled = True
Eraseall.Enabled = True
Exit Sub
End If
Dim mypic As New PictureBox
Dim thebarcodeimage As New barcodeimage
With mypic
.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName)
.Location = New Point(xp, yp)
.BorderStyle = BorderStyle.Fixed3D
.Width = .BackgroundImage.Width
.Height = .BackgroundImage.Height
.Tag = counter
.BringToFront()
AddHandler mypic.MouseMove, AddressOf mypicmousemove
AddHandler mypic.MouseDown, AddressOf mypicMouseDown
AddHandler mypic.MouseUp, AddressOf mypicMouseup
End With
thebarcodeimage.idimage = counter
thebarcodeimage.imagebarcode = DirectCast(mypic.BackgroundImage, Bitmap)
thebarcodedata.barcodeid = counter
thebarcodedata.locationbarcode = mypic.Location
listbarcodeimage.Add(thebarcodeimage)
listlocationbarcode.Add(thebarcodedata)
counter += 1
Panelframe.Controls.Add(mypic)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
xp = 1
yp = 1
counter = 0
DesignToolstripBar()
End Sub
Private Sub mypicmousemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim pt As New Point
pt = e.Location
If e.Button = Windows.Forms.MouseButtons.Left Then
pt.X = (pt.X + DirectCast(sender, PictureBox).Left) - lastmouselocation.X
pt.Y = (pt.Y + DirectCast(sender, PictureBox).Top) - lastmouselocation.Y
If pt.X < 0 Then
pt.X = 0
End If
If pt.Y < 0 Then
pt.Y = 0
End If
If pt.X > Me.Width - DirectCast(sender, PictureBox).Width Then
pt.X = Me.Width - DirectCast(sender, PictureBox).Width
End If
If pt.Y > Me.Height - DirectCast(sender, PictureBox).Height Then
pt.Y = Me.Height - DirectCast(sender, PictureBox).Height
End If
DirectCast(sender, PictureBox).Location = pt
DirectCast(sender, PictureBox).BringToFront()
End If
End Sub
Private Sub mypicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
lastmouselocation = e.Location
End Sub
Private Sub mypicMouseup(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim relativepoint As New Point
Dim thebarcodedata As New barcodedata
Dim idbarcode, iter, iterimage As Integer
relativepoint.X = DirectCast(sender, PictureBox).Left
relativepoint.Y = DirectCast(sender, PictureBox).Top
For iterimage = 0 To listbarcodeimage.Count - 1
If DirectCast(sender, PictureBox).Tag.ToString = listbarcodeimage(iterimage).idimage.ToString Then
idbarcode = listbarcodeimage(iterimage).idimage
If e.Button = Windows.Forms.MouseButtons.Left Then
For iter = 0 To listlocationbarcode.Count - 1
If listlocationbarcode(iter).barcodeid = idbarcode Then
thebarcodedata.barcodeid = idbarcode
thebarcodedata.locationbarcode = relativepoint
listlocationbarcode.Remove(listlocationbarcode(iter))
listlocationbarcode.Insert(iter, thebarcodedata)
Exit Sub
End If
Next
Else
listbarcodeimage.RemoveAt(iterimage)
For iter = 0 To listlocationbarcode.Count - 1
If listlocationbarcode(iter).barcodeid = idbarcode Then
listlocationbarcode.RemoveAt(iter)
Panelframe.Controls.Remove(DirectCast(sender, PictureBox))
Exit Sub
End If
Next
End If
End If
Next
End Sub
Private Sub planimage_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles planimage.MouseDown
flagplan = True
OpenFileDialog1.ShowDialog()
'DirectCast(sender, ToolStripButton).Enabled = False
End Sub
Private Sub barimage_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles barimage.MouseDown
flagplan = False
OpenFileDialog1.ShowDialog()
saveimage.Enabled = True
Eraseall.Enabled = True
End Sub
Private Sub saveimage_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles saveimage.MouseDown
SaveFileDialog1.ShowDialog()
End Sub
Private Sub SaveFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
JoinImage()
MessageBox.Show("New image was created")
End Sub
Private Sub Eraseall_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Eraseall.MouseDown
listbarcodeimage.Clear()
listlocationbarcode.Clear()
Panelframe.Controls.Clear()
Panelframe.Visible = False
barimage.Enabled = False
planimage.Enabled = True
saveimage.Enabled = False
End Sub
#End Region
Private Sub JoinImage()
Try
Dim imageplan As Bitmap = DirectCast(Panelframe.BackgroundImage, Bitmap)
Dim size1, size2, sizefinal As New Size
size1 = imageplan.Size
' size2 = imageplan2.Size
sizefinal.Height = size1.Height
sizefinal.Width = size1.Width
Dim imgFinal As New Bitmap(sizefinal.Width, sizefinal.Height)
Dim gfx As Graphics = Graphics.FromImage(imgFinal)
gfx.Clear(Color.White)
gfx.DrawImage(imageplan, 0, 0, New Rectangle(0, 0, size1.Width, size1.Height), GraphicsUnit.Pixel)
' gfx.DrawImage(imageplan2, New Point(20, size1.Height \ 2))
For iter = 0 To listbarcodeimage.Count - 1
gfx.DrawImage(listbarcodeimage(iter).imagebarcode, New Point(listlocationbarcode(iter).locationbarcode.X, listlocationbarcode(iter).locationbarcode.Y))
Next
imgFinal.Save(SaveFileDialog1.FileName, ImageFormat.Jpeg)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
Panelframe.Visible = False
' Add any initialization after the InitializeComponent() call.
End Sub
End Class