JavaScript Pad function

Created 02 December 2004 00:00

This function allows you to pad strings e.g. to pad a date part with 0's, you'd call

yourString = yourString.pad('0', 1);

// chr      Character to pad the string with
// num      The length of the string after padding
// prepend  (Optional) True to add to beginning, false for end - defaults to true.
String.prototype.pad = function(chr, num, prepend) {
  var front = true;
  var str = this;
  if (arguments.length > 2) front = prepend;
  for (var i=str.length; i<=num; i++) {
    str = ((front) ? (chr + str) : (str + chr));
  return str;

Right-clicking Treeview Nodes in Windows Forms

Created 09 December 2004 00:00

Right-clicking on a node in a treeview does not change the SelectedNode property, therefore it is impossible to get a handle on the current node within, for example, a context menu when using this method.

Instead, use a mouse event in conjunction with the treeview's "GetNodeAt" method to get a handle on the node:

private void treeView_MouseUp(object sender, MouseEventArgs e)
  if (e.Button == MouseButtons.Right) 
    TreeNode node = treeView.GetNodeAt(e.X, e.Y);
    if (node != null)