Well i'm making a draw with external images and then i whant to save the image that is on the picture box but it say that the picturebox is empty
my code:
my code:
VB.NET:
Public Class Form1
Dim button2 As Button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
ListBox1.SelectedIndex = DirectCast(sender, Button).Name.ToString
End Sub
Public Function create_button(ByVal i As Integer, ByVal nome As String)
button2 = New Button
button2.Name = nome
button2.Image = ImageList1.Images(i)
button2.FlatStyle = FlatStyle.Flat
button2.ForeColor = Color.Black
button2.Size = New Size(32, 32)
AddHandler button2.Click, AddressOf Button1_Click
FlowLayoutPanel1.Controls.Add(button2)
create_button = True
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim imagem As Image
Dim nome_da_imagem As String
Dim numero
Dim i As Integer
'For Each itm As Object In My.Computer.FileSystem.GetFiles("c:\img\", FileIO.SearchOption.SearchTopLevelOnly, "*.bmp")
' Me.ListBox1.Items.Add(itm) 'add to list box
' Next
Dim oRead As System.IO.StreamReader
Dim linein
oRead = IO.File.OpenText("Ground.txt")
While oRead.Peek <> -1
linein = oRead.ReadLine()
Me.ListBox1.Items.Add(linein)
End While
oRead.Close()
'percorrer items da lista
For i = 0 To ListBox1.Items.Count - 1
'obter nome deste item
nome_da_imagem = ListBox1.Items.Item(i)
numero = i
'carregar do fixeiro
imagem = Image.FromFile(nome_da_imagem)
'por na lista, o magenta eh transparente
ImageList1.Images.Add(imagem, Color.Magenta)
create_button(i, numero)
'FlowLayoutPanel1.Container.Add(newaa)
Next i
End Sub
Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
Dim graph As System.Drawing.Graphics
Dim imagem As System.Drawing.Image
Dim i As Integer
'classe pa desenhar
graph = PictureBox1.CreateGraphics()
'obter imagem k tá seleccionada
i = ListBox1.SelectedIndex
imagem = ImageList1.Images.Item(i)
'desenhar no sitio ond se clicou
Dim x As Integer
x = Int(Int(e.X) / 32) * 32
Dim y As Integer
y = Int(Int(e.Y) / 32) * 32
graph.DrawImage(imagem, x, y)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End Sub
End Class