Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, 13 November 2007

System.Windows.Form.MessageBox control is not extensible

Windows.Form.MessageBox control is not extensible since it is provided by the operating system. It is a static a class with private constructor. However, we could do something to customise this class by digging deep into Win32 API i.e., a 'hook' could be built to listen to the window events related to creating and activating the MessageBox, etc.

References:
http://msdn.microsoft.com/msdnmag/issues/02/11/CuttingEdge/default.aspx#S9
http://www.thescripts.com/forum/thread446492.html

Monday, 5 November 2007

How do I convert a string to a byte array and vica-versa in VB.NET and C#?

Convert String to Byte[]

' VB.NET to convert a string to a byte array
Public Shared Function StrToByteArray(str As String) As Byte()

Dim encoding As New System.Text.ASCIIEncoding()
Return encoding.GetBytes(str)
End Function 'StrToByteArray

// C# to convert a string to a byte array.

public static byte[] StrToByteArray(string str){
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}

Convert Byte[] to String

' VB.NET to convert a byte array to a string:
Dim dBytes As Byte() = ...Dim str As StringDim
enc As New System.Text.ASCIIEncoding()
str = enc.GetString(dBytes)

// C# to convert a byte array to a string.

byte [] dBytes = ...string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(dBytes);

Ref.: http://www.chilkatsoft.com/faq/DotNetStrToBytes.html