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 < "0" Or 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;
}
//###############################################################################################################################


}


 

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);
}
}


 

A Simple Decrypt Function

First Add This Namespaces

using System;
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.IO;
using System.Windows.Forms;

Now The Function:

public void Decrypt(string inputfile,string outputfile,string passPhrase,string saltValue,string hashAlgorithm,int passwordIterations,string initVector,int keySize)
{
// Convert strings defining encryption key characteristics into byte
// arrays. Let us assume that strings only contain ASCII codes.
// If strings include Unicode characters, use Unicode, UTF7, or UTF8
// encoding.
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);

// Convert our ciphertext into a byte array.
byte[] cipherTextBytes = ReadByteArrayFromFile(inputfile);

// First, we must create a password, from which the key will be
// derived. This password will be generated from the specified
// passphrase and salt value. The password will be created using
// the specified hash algorithm. Password creation can be done in
// several iterations.
PasswordDeriveBytes password = new PasswordDeriveBytes(
passPhrase,
saltValueBytes,
hashAlgorithm,
passwordIterations);

// Use the password to generate pseudo-random bytes for the encryption
// key. Specify the size of the key in bytes (instead of bits).
byte[] keyBytes = password.GetBytes(keySize / 8);

// Create uninitialized Rijndael encryption object.
RijndaelManaged symmetricKey = new RijndaelManaged();

// It is reasonable to set encryption mode to Cipher Block Chaining
// (CBC). Use default options for other symmetric key parameters.
symmetricKey.Mode = CipherMode.CBC;

// Generate decryptor from the existing key bytes and initialization
// vector. Key size will be defined based on the number of the key
// bytes.
ICryptoTransform decryptor = symmetricKey.CreateDecryptor(
keyBytes,
initVectorBytes);

// Define memory stream which will be used to hold encrypted data.
MemoryStream memoryStream = new MemoryStream(cipherTextBytes);

// Define cryptographic stream (always use Read mode for encryption).
CryptoStream cryptoStream = new CryptoStream(memoryStream,
decryptor,
CryptoStreamMode.Read);

// Since at this point we don't know what the size of decrypted data
// will be, allocate the buffer long enough to hold ciphertext;
// plaintext is never longer than ciphertext.
byte[] plainTextBytes = new byte[cipherTextBytes.Length];

// Start decrypting.
int decryptedByteCount = cryptoStream.Read(plainTextBytes,
0,
plainTextBytes.Length);

// Close both streams.
memoryStream.Close();
cryptoStream.Close();


File.WriteAllBytes(outputfile,plainTextBytes);

// Convert decrypted data into a string.
// Let us assume that the original plaintext string was UTF8-encoded.
//string plainText = Encoding.UTF8.GetString(plainTextBytes,
//0,
//decryptedByteCount);

// Return decrypted string.
//return plainText;
}
 
%d bloggers like this: