Hola tengo un problema algo grande, estoy con el proyecto de crear un programa que cree una carpeta o que se seleccione una carpeta personalizada para guardar Screenshots
Algo asi
Al abrir el programa se crea automaticamente la ruta "C:\Users\Tavito\Desktop\Screenshots"
Imports System.IO 'Todo el codigo esta resumido por partes
Public Class Form1
Private Folder As String 'Crea la ruta de la carpeta "Screenshots"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Folder = Path.
Combine(Environment.
GetFolderPath(Environment.
SpecialFolder.
Desktop),
"Screenshots") If Not Directory.
Exists(Folder) Then 'Si no existe dicho directorio Directory.
CreateDirectory(Folder) 'Entonces lo crear End If
LabelFolder.
Text = Folder 'Y en el "LabelFolder" muestra la ruta que se creo End Sub
Pero, si yo quiero seleccionar otra carpeta
Private Sub CheckFolder_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckFolder.CheckedChanged
If CheckFolder.Checked = True Then
FolderBrowserDialog1.ShowDialog()
LabelFolder.Text = FolderBrowserDialog1.SelectedPath() 'Aqui va la ruta de la carpeta que se selecciono
Else
LabelFolder.
Text = Folder 'Si por algun motivo quiero usar nuevamente la carpeta "Screenshots". Pero la elimine por accidente CheckFolder.Checked = False
Folder = Path.
Combine(Environment.
GetFolderPath(Environment.
SpecialFolder.
Desktop),
"Screenshots") If Not Directory.
Exists(Folder) Then Directory.
CreateDirectory(Folder) End If
End If
End Sub
El proceso de crear la carpeta no me da
ningun problema, el problema esta aqui al tomar la captura de pantalla
Resumire el codigo por partes
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Imaging
Public Class Form1
Private Folder As String 'Crea la ruta de la carpeta Private Nombre As String = "Image " 'Aqui asigna el nombre a todas las imagenes
Private Template As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Aqui almacena los formatos de las imagenes
ComboBox1.DataSource = New ImageFormat() {ImageFormat.Bmp, ImageFormat.Gif, ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Tiff}
End Sub
Dim bmp As Bitmap
Dim graphics As Graphics
Private Sub ButtonScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonScreen.Click
Dim SearchPattern As String = String.Concat(Nombre, "??.", ComboBox1.SelectedItem)
Dim Files As String() = Directory.
GetFiles(Folder, SearchPattern
) Dim Numb As Integer = 0
Numb
= Integer.
Parse(Files(Files.
Length - 1).
Substring(Template.
Length,
2)) + 1 End If
Dim Bmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
Using Grap As Graphics = graphics.FromImage(Bmp)
Grap.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
Dim Format As ImageFormat = DirectCast(ComboBox1.SelectedItem, ImageFormat)
Bmp.Save(String.Concat(Template, Numb.ToString("00"), ".", Format), Format)
End Using
End Sub
El problema esta aqui
Dim Files As String() = Directory.
GetFiles(Folder, SearchPattern
)
De que Folder, no vale lo que yo selecciono en el "BrowserDialog1.SelectedPath"
Solo funciona si dejo la ruta que yo mismo proporciono al abrir el programa
Folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Screenshots")
Ahora si la duda como hago para que
Dim Files As String() = Directory.
GetFiles(Folder, SearchPattern
)
Almacene la ruta seleccionada en el "LabelFolder" y guarde las imagenes en la carpeta seleccionada