A Function to Concat String Array Values by Specified Delimiter

Let ‘s Say I have Following Array:

string[] st = new string[5];
st[0] = "Animation";
st[1] = "Action";
st[2] = "Romance";
st[3] = "Drame";
st[4] = "Comedy";

Now I want to Merge all of it with ‘,’ Delimiter Like Below:

Output :   Animation,Action,Romance,Drame,Comedy

Here is the Function For the Above

public string GetAllStringsFromArrary(string[] strArray,string strDelimeter)
{
string strFinal = string.Empty;

for (int i = 0; i < strArray.Length ; i++)
{
strFinal += strArray[i];

if (i != strArray.Length - 1)
{
strFinal += strDelimeter;
}
}
return strFinal;


}

We will Call it Like This:

string str = GetAllStringsFromArrary( st,",");
 

A Function to find strings Between a Given Word/string

For example :
let’s say you have following Text:

Title                    Author              Product*         
~~~~~ ~~~~~~ ~~~~~~~~
"Aurora's Eggs" Douglas Niles Story (Dragons 2)

The Dragons Douglas Niles Novel

The Kinslayer Wars Douglas Niles Novel

The Qualinesti Paul B. Thompson Novel
& Tonya C. Cook

Vinas Solamnus J. Robert King Novel

The Dargonesti Paul B. Thompson Novel
& Tonya C. Cook

"Storytellers" Nick O'Donohoe Story (Dragons 2)

"The Best" Margaret Weis Story (Dragons 1)

"Quarry" Adam Lesh Story (Dragons 2)

"Easy Pickings" Douglas Niles Story (Dragons 1)

The Legend of Huma Richard A. Knaak Novel

And I want to find Everthing that is in between ” character.

The Answer should be like Following

Aurora's Eggs

Storytellers

The Best

Quarry

Easy Pickings

For this use the following Function:

public static List FindStringBetween(string strData,string strFindWhat)
{
List lstFound = new List();
int startIndex, EndIndex;
startIndex = strData.IndexOf(strFindWhat);

EndIndex = strData.IndexOf(strFindWhat, startIndex + strFindWhat.Length);

if (EndIndex > 0)
{
lstFound.Add(strData.Substring(startIndex+strFindWhat.Length ,EndIndex - startIndex-strFindWhat.Length ));
}

while (EndIndex > 0)
{
startIndex = strData.IndexOf(strFindWhat, EndIndex + 1);
if (startIndex == -1) {
return lstFound; }
EndIndex = strData.IndexOf(strFindWhat, startIndex + 1);
if (EndIndex > 0)
{
lstFound.Add(strData.Substring(startIndex + strFindWhat.Length, EndIndex - startIndex - strFindWhat.Length));
}
}

return lstFound;
}

Please ignore the last line.

It will give you the complete list of the strings found.

 

Dashed Label [Design Mode Only]

Sometimes you have so many controls on your design form that can make you confused.  So i have developed a Dashed Label Control which provide each control a boundry in Design Mode only. For better Understanding see the Screen Shots Below:

Design Mode

At Run Time

I hope your getting what i am saying.

Now to the Code.

1. Add a custom Control to your project. Name is DashedLabel (or anything you like.)
2. Now on its Paint Event Write the following Code.

private void DashedLabel_Paint(object sender, PaintEventArgs e)
{
if (this.DesignMode)
{
using (Pen pen = new Pen(Color.Gray))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
}
}
}

That’s it.

Complete Project : Dashed Label

 

3d – Pie Chart [Transparent]

3d- Pie chart Control for .net Framework

This one is not Made By me.
Reference: http://www.codeproject.com/KB/graphics/julijanpiechart.aspx

Dll:  You can Download The Control Dll from above website.

Now for the Coding :

Simply add the dll to your project through : ToolBox -> Choose items > Your Dll
You will see a  Pie chart Control in your Tool box of the Visual Studio

Drag and drop it to a form.

Write the following code on Form’s Load event.

private void Form1_Load(object sender, EventArgs e)
{
pcc1.Values = new decimal[] { 10, 15, 5, 35 };
int alpha = 80;
pcc1.Colors = new Color[] { Color.FromArgb(alpha, Color.Red),
Color.FromArgb(alpha, Color.Green),
Color.FromArgb(alpha, Color.Yellow),
Color.FromArgb(alpha, Color.Blue) };

pcc1.SliceRelativeDisplacements = new float[] { 0.1F, 0.2F, 0.2F, 0.2F };

pcc1.Texts = new string[] { "red",
"green",
"blue",
"yellow" };

pcc1.ToolTips = new string[] { "Peter",
"Paul",
"Mary",
"Brian" };

pcc1.Font = new Font("Arial", 10F);
pcc1.ForeColor = SystemColors.WindowText;
pcc1.LeftMargin = 10F;
pcc1.RightMargin = 10F;
pcc1.TopMargin = 10F;
pcc1.BottomMargin = 10F;
pcc1.SliceRelativeHeight = 0.25F;
pcc1.InitialAngle = -90F;

}

This is just a Demo of how the Control works
pcc1 is the Pie chart Control’s Name

Complete Project: 3d -Pie Chart

 

Numeric Only TextBox

It’s Very Easy to make a Numeric only TextBox ..
Just right the Following Code on The Textbox’s KeyPress Event..

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar > 31 && (e.KeyChar < '0' || e.KeyChar > '9'))
{
e.Handled = true;
}
}

Above Code Wont Let you enter anything other than 0 to 9 Numerics

To Limit the Number of Character in Texbox use the MaxLength Property  of Texbox

Example:

TextBox1.MaxLength = 10;

Vb.net


Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar > "31" And (e.KeyChar "9") Then
e.Handled = True
End If
End Sub

Example:

TextBox1.MaxLength = 10

 

A Simple Log Writer And Log Searching Class


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

class clsLog
{

private StringBuilder strLog;
private string strFileName = string.Empty;

//Initialize Logging
//###############################################################################################################################
public void StartLogging(string strLogFileName)
{
strLog = new StringBuilder();
strLog.Append("Logging Started At : [" + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "]" + Environment.NewLine + Environment.NewLine);
strFileName = strLogFileName;
}
//###############################################################################################################################


//Write Log Entry
//###############################################################################################################################
public void WriteLogEntry(string strEntry)
{
strLog.Append("[" + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "] " + strEntry + Environment.NewLine);
}
//###############################################################################################################################


//New Line
//###############################################################################################################################
public void NewLine()
{
strLog.Append(Environment.NewLine);
}
//###############################################################################################################################


//Stop Logging
//###############################################################################################################################
public void StopLogging()
{
strLog.Append(Environment.NewLine + "Logging Stopped At : [" + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "]" + Environment.NewLine);
if (System.IO.File.Exists(strFileName))
{
using (StreamWriter sw = File.AppendText(strFileName))
{
sw.Write(strLog.ToString());
sw.Close();
}
}
else
{
System.IO.File.WriteAllText(strFileName,strLog.ToString());
}
}
//###############################################################################################################################

//Search Log
//###############################################################################################################################
public string SearchLog(string strLogFileName, DateTime dtFrom, DateTime dtTo)
{
if (!File.Exists(strLogFileName)) { return null; }

string strReturnString = string.Empty;
using (StreamReader sr = new StreamReader(strLogFileName)) //strFileName
{
String line;
while ((line = sr.ReadLine()) != null)
{
DateTime strDateTime;
if (line.Length > 22)
{
DateTime.TryParse(line.Substring(0, 25).Replace('[', ' ').Replace(']', ' ').Trim(), out strDateTime);
if (strDateTime >= dtFrom && strDateTime <= dtTo)
{
strReturnString += line + Environment.NewLine;
}
}
}
}

return strReturnString;
}
//###############################################################################################################################


}


 

Getting Local IP Address


public static string GetLocalIP()
{
string _IP = null;

System.Net.IPHostEntry _IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());

foreach (System.Net.IPAddress _IPAddress in _IPHostEntry.AddressList)
{
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
_IP = _IPAddress.ToString();
}
}
return _IP;
}

 

Class To Change Wallpaper in Xp,Vista,Windows 7 from C#.Net

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using Microsoft.Win32;
using System.Drawing;


public sealed class clsWallpaper
{

const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

public enum Style : int
{
Tiled,
Centered,
Stretched
}

public static void Set(Uri uri, Style style)
{
System.IO.Stream s = new System.Net.WebClient().OpenRead(uri.ToString());

System.Drawing.Image img = System.Drawing.Image.FromStream(s);
string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp");
img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp);

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control PanelDesktop", true);
if (style == Style.Stretched)
{
key.SetValue(@"WallpaperStyle", 2.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}

if (style == Style.Centered)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}

if (style == Style.Tiled)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 1.ToString());
}

SystemParametersInfo(SPI_SETDESKWALLPAPER,
0,
tempPath,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}

}

 

A Class To Hide Show Task Bar (Works with XP)

using System;
using System.Runtime.InteropServices;


///
/// This class will show or hide windows taskbar for full screen mode.
///

internal class HandleTaskBar
{
private const int SWP_HIDEWINDOW = 0x0080;
private const int SWP_SHOWWINDOW = 0x0040;

///
/// Default Constructor.
///

public HandleTaskBar()
{
}

[DllImport("User32.dll", EntryPoint="FindWindow")]
private static extern int FindWindow(string lpClassName, string lpWindowName);

[DllImport("User32.dll")]
private static extern int SetWindowPos(int hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);

///
/// Show the TaskBar.
///

public static void showTaskBar()
{
int hWnd = FindWindow("Shell_TrayWnd", "");
SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW);
}

///
/// Hide the TaskBar.
///

public static void hideTaskBar()
{
int hWnd = FindWindow("Shell_TrayWnd", "");
SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);
}
}