Tagged with “.NET” (2)


Collection of snippets I use in my daily programming work

Select Case on an object’s type in VB.NET

Select Case msg.GetType()
    Case GetType(ClassA)
End Select

i18n with Resource Files

Suppose you have the files Strings.resx and Strings.en.resx in you Project, then you can access these Strings in a localized way (depending on the current culture) like this:

Dim _R As Resources.ResourceManager = My.Resources.Strings.ResourceManager
Dim str = _R.GetString("SomeLocalizedResource")


Convert an int-based enum into its integer representation

Public Enum myEnum
  someValue = 42
End Enum

Dim intValue = Convert.ToInt32(myEnum) 

DataRows and DataTables

Converting a Datatable into an Enumerable

1st Option
collection as IEnumerable(Of DataRow) = myTypedTable.Cast(Of DataRow)();
2nd Option
DataRow() collection = myTypedTable.Select()

Make a borderless form movable in .NET

public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public static extern bool ReleaseCapture();

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    if (e.Button == MouseButtons.Left)
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);