اما بالنسبة الى الكود البرمجي فهذا الكود الي انا قاعد اتعامل فيه اخي الغالي
كود :
Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Drawing.Printing
Public Class add_barcode
Public ToDo As String = "add"
Public id As Integer
Private Sub Butcaret_Click(sender As Object, e As EventArgs) Handles Butcaret.Click
Dim Generator As New MessagingToolkit.Barcode.BarcodeEncoder
Generator.IncludeLabel = True
Generator.CustomLabel = Textcod.Text
Try
PictureBox1.Image = New Bitmap(Generator.Encode(MessagingToolkit.Barcode.BarcodeFormat.Code11, Textcod.Text))
Catch ex As Exception
End Try
End Sub
Sub claertext()
Textcod.Clear()
Textcat.Clear()
Textnewcod.Clear()
Textnewcod.Clear()
Textnpro.Clear()
End Sub
Private Sub Butadd_Click(sender As Object, e As EventArgs) Handles Butadd.Click
If Textcat.Text = String.Empty Or Textcod.Text = String.Empty Or Textnewcod.Text = String.Empty Or Textnpro.Text = String.Empty Then
MsgBox("جميع الحقول مطلوبة يا صديقي العزيز", MsgBoxStyle.Information, "تحذير")
Exit Sub
End If
Try
Dim query As String
If ToDo = "add" Then
query = "insert into parcode (name_pro,dic_pro,newcode,pacrcode_ro,imgparcod) values(@name_pro,@dic_pro,@newcode,@pacrcode_ro,@imgparcod) "
Else
query = "update parcode set name_pro=@name_pro,dic_pro=@dic_pro,newcode=@newcode,pacrcode_ro=@pacrcode_ro,imgparcod=@imgparcod where id= " & id
End If
Dim filesize As UInt32
Dim mstrem As New System.IO.MemoryStream
PictureBox1.Image.Save(mstrem, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arrimage() As Byte = mstrem.GetBuffer
filesize = mstrem.Length
mstrem.Close()
cmd = New MySqlCommand(query, con)
cmd.Parameters.Add("@name_pro", MySqlDbType.VarChar, 200).Value = Textnpro.Text
cmd.Parameters.Add("@dic_pro", MySqlDbType.VarChar, 200).Value = Textcod.Text
cmd.Parameters.Add("@newcode", MySqlDbType.VarChar, 200).Value = Textnewcod.Text
cmd.Parameters.Add("@pacrcode_ro", MySqlDbType.VarChar, 200).Value = Textcat.Text
cmd.Parameters.Add("@imgparcod", MySqlDbType.Blob).Value = arrimage
con.Open()
cmd.ExecuteNonQuery()
claertext()
MsgBox("تم حفظ البيانات بنجاح شكرا لكم", MsgBoxStyle.Information, "الاضافة")
Catch ex As Exception
MsgBox(ex.Message)
Finally
con.Close()
End Try
End Sub
Private Sub add_barcode_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SD As New SaveFileDialog
SD.Filter = "PNG File|*.png"
If SD.ShowDialog() = DialogResult.OK Then
Try
PictureBox1.Image.Save(SD.FileName, Imaging.ImageFormat.Png)
Catch ex As Exception
End Try
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
print_bar.PictureBox1.ImageLocation = PictureBox1.ImageLocation
End Sub
Friend WithEvents prntDoc As New PrintDocument()
Private Print_Image As Image
Declare Auto Function BitBlt Lib "GDI32.DLL" ( _
ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'print picture
Dim prnDialog As New PrintDialog()
'Get a Graphics Object from the form
Dim FormG As Graphics = Me.PictureBox1.CreateGraphics
'Create a bitmap from that graphics
Dim i As New Bitmap(Me.Width, Me.Height, FormG)
'Create a Graphics object in memory from that bitmap
Dim memG As Graphics = Graphics.FromImage(i)
'get the IntPtr's of the graphics
Dim HDC1 As IntPtr = FormG.GetHdc
Dim HDC2 As IntPtr = memG.GetHdc
'get the picture
BitBlt(HDC2, 0, 0, Me.PictureBox1.Width, Me.PictureBox1.Height, HDC1, 0, 0, 13369376)
'Clone the bitmap so we can dispose this one
Me.Print_Image = i.Clone()
'Clean Up
FormG.ReleaseHdc(HDC1)
memG.ReleaseHdc(HDC2)
FormG.Dispose()
memG.Dispose()
i.Dispose()
prnDialog.Document = prntDoc
' Optional Dialog:
Dim r As DialogResult = prnDialog.ShowDialog
If r = DialogResult.OK Then
prntDoc.Print()
End If
End Sub
Private Sub prntDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prntDoc.PrintPage
e.Graphics.DrawImage(Print_Image, 0, 0)
End Sub
End Class