Skip to content

Instantly share code, notes, and snippets.

@Demonic722
Created August 1, 2012 23:36
Show Gist options
  • Save Demonic722/3231579 to your computer and use it in GitHub Desktop.
Save Demonic722/3231579 to your computer and use it in GitHub Desktop.
Something related to a counter and opening files...
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OpenFileCounter
{
public partial class Form1 : Form
{
int counter = 0;
OpenFileDialog ofd = new OpenFileDialog();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if ((ofd.ShowDialog() == DialogResult.OK) && (ofd.OpenFile() != null))
textBox1.Text = Path.GetFileName(ofd.FileName);
//for each file opened, add 1 to the counter
foreach (string file in ofd.FileNames)
{
counter++;
label1.Text = counter.ToString();
}
}
}
}
Imports System.IO
Public Class Form1
Dim counter As Integer = 0
Dim ofd As New OpenFileDialog()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ofd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
TextBox1.Text = Path.GetFileName(ofd.FileName)
End If
For Each file As String In ofd.FileNames
counter += 1
Label1.Text = counter.ToString()
Next
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment