Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Archive for the ‘C#’ Category

WindowCMD Utility

Posted by Circuit Negma on February 24, 2019


Technorati Tags: ,

2019-02-23 20_34_54-Clipboard


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SHDocVw;
using System.IO;

namespace WindowsCMD
{
public partial class Form1 : Form
{
public Form1()
{
// Initialize form components
InitializeComponent();

// Set the toolstripstatus label to current time of localhost machine
toolStripStatusLabel1.Text = System.DateTime.Now.ToString();

// Use a timer that will update Time and Date inside toolstripstatus label
timer1.Enabled = true; // enable timer
timer1.Interval = 1000; // set timer to fire every 1000ms = 1s

}

private void toolStripStatusLabel1_Click(object sender, EventArgs e)
{
// disable welcome message if someone click on Clock in toolstripstatus label
MessageBox.Show(“Hello! :)”, “WindowsCMD”);
}

private void button1_Click(object sender, EventArgs e)
{
// SHDocVw (Microsoft Internet Controls) – allow the app to access windows explorer
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

// Create a list with opened “Explorer” windows
ArrayList windows = new ArrayList();

string filename;
string directoryPath;
Uri basePathUri;

foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

if (filename.Equals(“explorer”))
{
if(ie.LocationURL.Count() == 0)
{

}
else
{
basePathUri = new Uri(ie.LocationURL.ToString());
directoryPath = basePathUri.ToString();
windows.Add(directoryPath.Substring(8));
}
}
else
{
MessageBox.Show(“error”);
}
}

listBox1.DataSource = windows;

}

private void button2_Click(object sender, EventArgs e)
{
string strCmdText;

if(listBox1.Items.Count == 0)
{
strCmdText = @”\”;
}
else
{
strCmdText = listBox1.SelectedItem.ToString();
}

strCmdText = “/K cd ” + strCmdText;
System.Diagnostics.Process.Start(“CMD.exe”, strCmdText);
}

private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = System.DateTime.Now.ToString();
}
}
}

Posted in C#, Tools | Leave a Comment »

IP Address Finder V1.0

Posted by Circuit Negma on May 13, 2012


Created By: Hussein Nosair

Sources:

1. http://csharp.net-informations.com/communications/csharp-ip-address.htm

2. http://www.daniweb.com/software-development/csharp/code/217169/find-ip-address

IP Address Finder V1.0

Download Link:

Name:
IPAddress1.rar

Path:
/

Size:
5.4KB (5550 bytes)

Modified:
2012-05-13 09:57:54

Uploaded:
2012-05-13 09:57:54

md5:
b4dcf8affc90bfe3897cc705f0986b5a

Shared:
Publicly Shared

URL:
http://www.adrive.com/public/ZCwq4A/IPAddress1.rar

Downloads:
0

Expires:
2012-05-27

Code:

   1:  using System;
   2:  //using System.Collections.Generic;
   3:  //using System.ComponentModel;
   4:  //using System.Data;
   5:  //using System.Drawing;
   6:  //using System.Linq;
   7:  //using System.Text;
   8:  using System.Windows.Forms;
   9:  using System.Net;
  10:  using System.Text.RegularExpressions;
  11:   
  12:   
  13:  namespace IPAddress1
  14:  {
  15:      public partial class Form1 : Form
  16:      {
  17:          public Form1()
  18:          {
  19:              InitializeComponent();
  20:              this.textBox1.Focus();
  21:   
  22:              //====================================
  23:              // Keys Detection Methods
  24:              //====================================
  25:              // Method 1
  26:              this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(CheckEnterKey);
  27:   
  28:              // Method 2
  29:              //this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKey);
  30:          }
  31:   
  32:          private void button1_Click(object sender, EventArgs e)
  33:          {
  34:              int tmpCount = 0;
  35:              IPHostEntry remoteHostName;
  36:              IPAddress[] ips;
  37:   
  38:              try
  39:              {
  40:                  remoteHostName = Dns.GetHostEntry(textBox1.Text);
  41:                  ips = remoteHostName.AddressList;
  42:   
  43:                  textBox2.AppendText("Host Name: " + textBox1.Text);
  44:                  textBox2.AppendText(Environment.NewLine);
  45:   
  46:                  System.Console.WriteLine(ips.Rank);
  47:                  
  48:                  foreach (IPAddress ipaddress in ips)
  49:                  {
  50:                      textBox2.AppendText("IP Address[" + tmpCount++ + "]: " + ipaddress.ToString());
  51:                      textBox2.AppendText(Environment.NewLine);
  52:                      System.Console.WriteLine("IP Address[" + tmpCount++ + "]: " + ipaddress.ToString());
  53:   
  54:                      System.Console.WriteLine("Hash Code: " + ipaddress.GetHashCode());
  55:                  }
  56:   
  57:              }
  58:              catch (System.Net.Sockets.SocketException ex)
  59:              {
  60:                  textBox2.Clear();
  61:                  textBox2.AppendText(ex.SocketErrorCode.ToString());
  62:                  Console.WriteLine(ex.SocketErrorCode.ToString());
  63:              }
  64:          }
  65:   
  66:          // Method 1
  67:          //-----------------------------------------------------------------------------
  68:          private void CheckEnterKey(object sender, System.Windows.Forms.KeyEventArgs e)
  69:          {
  70:              if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
  71:              {
  72:                  button1_Click(sender, e);
  73:              }
  74:          }
  75:   
  76:          // Method 2
  77:          //-----------------------------------------------------------------------------
  78:          /*private void CheckEnterKey(object sender, System.Windows.Forms.KeyEventArgs e)
  79:          {
  80:              if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
  81:              {
  82:                  button1_Click(sender, e);
  83:              }
  84:          }*/
  85:   
  86:          // Write to a file Method
  87:          //----------------------------------------------------------------------------
  88:          /*private void button1_Click(object sender, EventArgs e)
  89:          {
  90:              //
  91:              // This is the button labeled "Save" in the program.
  92:              //
  93:              File.WriteAllText("C:\\demo.txt", textBox1.Text);
  94:          }*/
  95:      }
  96:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Posted in C#, Tools | Leave a Comment »

File Rename Rev 2

Posted by Circuit Negma on May 11, 2012


Created By: Hussein Nosair

File Rename Rev 2

Auto-calculate the padding zeros based on the number of files to be renamed in the target Directory/Folder.

   1: using System;

   2: using System.Collections.Generic;

   3: using System.ComponentModel;

   4: using System.Data;

   5: using System.Drawing;

   6: using System.Linq;

   7: using System.Text;

   8: using System.Windows.Forms;

   9: using System.IO;

  10:  

  11: namespace getFiles2

  12: {

  13:     public partial class Form1 : Form

  14:     {

  15:         private string[] dirFiles;

  16:         private int count;

  17:         //private string fileExt;

  18:  

  19:         public Form1()

  20:         {

  21:             InitializeComponent();

  22:         }

  23:  

  24:         private void button1_Click(object sender, EventArgs e)

  25:         {

  26:             int tmpCount = 1;

  27:             //int max;

  28:  

  29:             //folderBrowserDialog1.RootFolder = Environment.SpecialFolder.System;

  30:  

  31:             // Set the help text description for the FolderBrowserDialog.

  32:             this.folderBrowserDialog1.Description =

  33:                "Select the directory pf Files that you want to rename.";

  34:  

  35:             if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)

  36:             {

  37:                 textBox1.ResetText();                               // Clear out all text in the textbox1

  38:                 dirFiles = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*" ,SearchOption.AllDirectories);

  39:                 count = dirFiles.Length;

  40:                 Array.Sort(dirFiles);

  41:                 textBox1.AppendText("Folder Location: " + folderBrowserDialog1.SelectedPath + Environment.NewLine);

  42:                 textBox1.AppendText("Total Files: " + count + Environment.NewLine);

  43:                 textBox1.AppendText(Environment.NewLine);

  44:  

  45:                 //max = Array.

  46:                 //System.Console.WriteLine(Array.IndexOf(dirFiles, "0020"));

  47:                 //System.Console.WriteLine(Array.IndexOf(dirFiles, "0020"));

  48:  

  49:                 foreach (string file in dirFiles)

  50:                 {

  51:                     textBox1.AppendText(tmpCount + "." + Environment.NewLine);

  52:                     textBox1.AppendText("FilePath = " + file + Environment.NewLine);

  53:                     textBox1.AppendText("FileName = " + Path.GetFileNameWithoutExtension(file) + Environment.NewLine);

  54:                     textBox1.AppendText("FileExt = " + Path.GetExtension(file).ToUpper() + Environment.NewLine);

  55:                     textBox1.AppendText(Environment.NewLine);

  56:                     //System.Console.WriteLine(Path.GetDirectoryName(file));

  57:                     //System.Console.WriteLine(Path.GetFileNameWithoutExtension(file));

  58:                     //System.Console.WriteLine(count.ToString().Count());

  59:                     tmpCount++;

  60:                 }

  61:             }

  62:         }

  63:  

  64:         private void button2_Click(object sender, EventArgs e)

  65:         {

  66:             int tmpCount = 0;

  67:             int iPadingZeros;

  68:             string fldrPath;

  69:             string fileName;

  70:             string fileExt;

  71:             string newFileName;

  72:  

  73:             if (dirFiles == null)

  74:             {

  75:                 //System.Console.WriteLine("error: File Directory is undefined.");

  76:                 textBox1.AppendText("Error: Files directory is undefined." + Environment.NewLine);

  77:                 this.Invalidate();

  78:                 this.SuspendLayout();

  79:                 progressBar1.ForeColor = Color.Red;

  80:                 this.Invalidate();

  81:                 this.Refresh();

  82:                 this.ResumeLayout();

  83:                 

  84:                 progressBar1.Step = progressBar1.Maximum;

  85:                 progressBar1.Value = progressBar1.Maximum;

  86:                 return;

  87:             }

  88:  

  89:             progressBar1.Minimum = 0;

  90:             progressBar1.Maximum = dirFiles.Length;

  91:             progressBar1.Step = 1;

  92:             progressBar1.ForeColor = Color.Green;

  93:             button2.Enabled = false;

  94:             iPadingZeros = count.ToString().Length;

  95:  

  96:             foreach (string file in dirFiles)

  97:             {

  98:                 fldrPath = Path.GetDirectoryName(file);

  99:                 //System.Console.WriteLine("File Location:" + fldrPath + Environment.NewLine);

 100:                 fileName = Path.GetFileNameWithoutExtension(file);

 101:                 //System.Console.WriteLine("File Name: " + fileName + Environment.NewLine);

 102:                 fileExt = Path.GetExtension(file);

 103:                 //System.Console.WriteLine("File Ext.: " + fileExt + Environment.NewLine);

 104:                 //System.Console.WriteLine("{0,22:D4} {0,22:X4}", tmpCount);

 105:                 newFileName = fldrPath + "\\" + tmpCount.ToString("D" + iPadingZeros.ToString()) + fileExt;

 106:                 //newFileName = fldrPath + @"\" + tmpCount.ToString("D4") + fileExt;    // Same result as in above statement.

 107:                 //System.Console.WriteLine(newFileName);

 108:                 System.IO.File.Move(file, newFileName);

 109:                 progressBar1.Value = tmpCount + 1;

 110:                 tmpCount++;

 111:             }

 112:  

 113:             button2.Enabled = true;

 114:             //

 115:             // Clear all elements in the array.

 116:             //

 117:             Array.Clear(dirFiles, 0, dirFiles.Length);

 118:             dirFiles = null;

 119:             textBox1.ResetText();

 120:             textBox1.AppendText("Message -> All Clear!" + Environment.NewLine);

 121:         }

 122:     }

 123: }

Posted in C#, Tools | Leave a Comment »

File Rename ver. 1

Posted by Circuit Negma on May 4, 2012


Created by: Hussein Nosair

getFiles1

I needed something quick and tailored to my files. I have created this tool. the File Rename tool scan the directory and sub directories first for all files, sort them and then rename the files to “XXXX.ext”. The “XXXX” starts from 0000 to 9999.

For now, this is it. However, I will progressly update the tool and add more features.

 1: using System;

 2: using System.Collections.Generic;

 3: using System.ComponentModel;

 4: using System.Data;

 5: using System.Drawing;

 6: using System.Linq;

 7: using System.Text;

 8: using System.Windows.Forms;

 9: using System.IO;

 10:

 11: namespace getFiles1

 12: {

 13:     public partial class Form1 : Form

 14:     {

 15:         private string[] dirFiles;

 16:         private int count;

 17:         //private string fileExt;

 18:

 19:         public Form1()

 20:         {

 21:             InitializeComponent();

 22:         }

 23:

 24:         private void button1_Click(object sender, EventArgs e)

 25:         {

 26:             int tmpCount = 1;

 27:             //folderBrowserDialog1.RootFolder = Environment.SpecialFolder.System;

 28:

 29:             // Set the help text description for the FolderBrowserDialog.

 30:             this.folderBrowserDialog1.Description =

 31:                "Select the directory pf Files that you want to rename.";

 32:

 33:             if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)

 34:             {

 35:                 textBox1.ResetText();                               // Clear out all text in the textbox1

 36:                 dirFiles = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*" ,SearchOption.AllDirectories);

 37:                 count = dirFiles.Length;

 38:                 Array.Sort(dirFiles);

 39:                 textBox1.AppendText("Folder Location: " + folderBrowserDialog1.SelectedPath + Environment.NewLine);

 40:                 textBox1.AppendText("Total Files: " + count + Environment.NewLine);

 41:                 textBox1.AppendText(Environment.NewLine);

 42:

 43:                 foreach (string file in dirFiles)

 44:                 {

 45:                     textBox1.AppendText(tmpCount + "." + Environment.NewLine);

 46:                     textBox1.AppendText("FilePath = " + file + Environment.NewLine);

 47:                     textBox1.AppendText("FileName = " + Path.GetFileNameWithoutExtension(file) + Environment.NewLine);

 48:                     textBox1.AppendText("FileExt = " + Path.GetExtension(file).ToUpper() + Environment.NewLine);

 49:                     textBox1.AppendText(Environment.NewLine);

 50:                     //System.Console.WriteLine(Path.GetDirectoryName(file));

 51:                     //System.Console.WriteLine(Path.GetFileNameWithoutExtension(file));

 52:                     //System.Console.WriteLine(count.ToString().Count());

 53:                     tmpCount++;

 54:                 }

 55:             }

 56:         }

 57:

 58:         private void button2_Click(object sender, EventArgs e)

 59:         {

 60:             int tmpCount = 0;

 61:             string fldrPath;

 62:             string fileName;

 63:             string fileExt;

 64:             string newFileName;

 65:

 66:             if (dirFiles == null)

 67:             {

 68:                 //System.Console.WriteLine("error: File Directory is undefined.");

 69:                 textBox1.AppendText("Error: Files directory is undefined." + Environment.NewLine);

 70:                 progressBar1.ForeColor = Color.Red;

 71:                 progressBar1.Step = progressBar1.Maximum;

 72:                 progressBar1.Value = progressBar1.Maximum;

 73:                 return;

 74:             }

 75:

 76:             progressBar1.Minimum = 0;

 77:             progressBar1.Maximum = dirFiles.Length;

 78:             progressBar1.Step = 1;

 79:             progressBar1.ForeColor = Color.Green;

 80:             button2.Enabled = false;

 81:

 82:             foreach (string file in dirFiles)

 83:             {

 84:                 fldrPath = Path.GetDirectoryName(file);

 85:                 //System.Console.WriteLine("File Location:" + fldrPath + Environment.NewLine);

 86:                 fileName = Path.GetFileNameWithoutExtension(file);

 87:                 //System.Console.WriteLine("File Name: " + fileName + Environment.NewLine);

 88:                 fileExt = Path.GetExtension(file);

 89:                 //System.Console.WriteLine("File Ext.: " + fileExt + Environment.NewLine);

 90:                 //System.Console.WriteLine("{0,22:D4} {0,22:X4}", tmpCount);

 91:                 newFileName = fldrPath + "\\" + tmpCount.ToString("D4") + fileExt;

 92:                 //newFileName = fldrPath + @"\" + tmpCount.ToString("D4") + fileExt; // Same result as in above statement.

 93:                 //System.Console.WriteLine(newFileName);

 94:                 System.IO.File.Move(file, newFileName);

 95:                 progressBar1.Value = tmpCount + 1;

 96:                 tmpCount++;

 97:             }

 98:

 99:             button2.Enabled = true;

 100:             //

 101:             // Clear all elements in the array.

 102:             //

 103:             Array.Clear(dirFiles, 0, dirFiles.Length);

 104:             dirFiles = null;

 105:             textBox1.ResetText();

 106:             textBox1.AppendText("Message -> All Clear!" + Environment.NewLine);

 107:

 108:

 109:         }

 110:     }

 111: }

 

Download Link:

Name:

getFiles1.rar

Path:

/

Size:

5.9KB (6051 bytes)

Modified:

2012-05-04 12:36:57

Uploaded:

2012-05-04 12:36:57

md5:

6ebb2ef67a92142b6c268072158c984a

Shared:

Publicly Shared

URL:

http://www.adrive.com/public/WQpj9D/getFiles1.rar

Downloads:

0

Expires:

2012-05-18

Posted in C#, Tools | Leave a Comment »