C#
Hexadecimal string to Bytes array
0
/// <summary>
/// Hexa decimal to Byte array
/// </summary>
/// <param name="HexString">Hexa decimal string</param>
/// <returns>byte array</returns>
public static byte[] HexToBytes(String hexString)
{
byte[] byteArray = null;
int byteCount = 0;
if (hexString != null && hexString.Length > 0)
{
// make sure we have an even number of characters
if (hexString.Length % 2 != 0)
hexString = "0" + hexString;
byteCount = hexString.Length / 2;
byteArray = new byte[byteCount];
string sTemp;
for (int i = 0; i < byteCount; i++)
{
sTemp = hexString.Substring(i * 2, 2);
byteArray[i] = Convert.ToByte(sTemp, 16);
}
}
return byteArray;
}
Bytes array to Hexadecimal string
0
/// <summary>
/// Byte array to Hexa decimal string
/// </summary>
/// <param name="bytes">byte array</param>
/// <returns>hexa decimal string</returns>
public static string BytesToHex(byte[] bytes)
{
string hex = BitConverter.ToString(bytes);
return hex.Replace("-", "");
}
/// <summary>
/// Byte array to Hexa decimal string
/// </summary>
/// <param name="bytes">byte array</param>
/// <param name="includeHyphen">bool include hyphen</param>
/// <returns>hexa decimal string</returns>
public static string BytesToHex(byte[] bytes, bool includeHyphen)
{
string hex = BitConverter.ToString(bytes);
return hex;
}
Auto Complete ComboBox – C# Windows Forms
3
Introduction
This is a simple code snippet which is used to make an Auto Complete ComboBox.
Using the code
Usage: Call the function AutoComplete from within the ComboBox’s KeyPress event handler.
AutoComplete(ComboBox cb, System.Windows.Forms.KeyPressEventArgs e, bool blnLimitToList)
Code
/// <summary>
/// AutoComplete
/// </summary>
/// <param name="cb">ComboBox</param>
/// <param name="e">KeyPressEventArgs</param>
DataGrid Paging using DataReader – C# Windows Forms
0
Introduction
This is an example of Windows Forms DataGrid paging using c#. I have used Microsoft SQL Server 2000 database.
Using the code
Create a table:
create table tblEmp
(
E_ID int primary key ,
E_Name varchar(60) ,
E_Salary money ,
E_DOJ datetime
)
go
Public variables:
/// <summary>
DataGrid Paging – C# Windows Forms
0
Introduction
This is an example of Windows Forms DataGrid paging using c#. I have used Microsoft SQL Server 2000 database.
Using the code
Create a table:
create table tblEmp
(
E_ID int primary key ,
E_Name varchar(60) ,
E_Salary money ,
E_DOJ datetime
)
go
In this example, the loadPage() method fetches only the required page data from More >
String.Format Method
0-
http://msdn.microsoft.com/en-us/library/system.string.format.aspx
-
http://msdn.microsoft.com/en-us/library/fht0f5be(VS.80).aspx
-
http://msdn.microsoft.com/en-us/library/26etazsy(VS.80).aspx
Integer
Add zeroes before number
1: String.Format("{0:00000}", 15); // "00015"
More >