Posts RSS Comments RSS 136 Posts and 267 Comments till now

How to Create a Cool Firefox’s Bookmark Toolbar

I was lurking on Slashdot reading article about software bug that became a feature. Someone mentioned a bug in the Firefox’s bookmarking name. Then another person suggested a Firefox Extension to make your bookmark Toolbar looks Cool.

OK, so here are the steps:

  1. 1. Download this Firefox Extension HERE
  2. 2. Blank out the name of your bookmarks in the Bookmark Toolbar
  3. 3. If the websites in your toolbar doesn’t have icon, visit that particular website, get its logo URL, and then visit this PAGE to convert the logo into icon.

As a teaser, here is how my Bookmark Toolbar looks like:

cool-bookmark-toolbar.png

Source: Slashdot

 

Create Drag-and-Drog File Path Locator

There are days when we actually need to get the full path location of a file. A quick example would be when you are adding entries into your Book Collector application. After downloads all information about the particular book you are adding, you are then adding the path of the e-Book into the ‘eBook Textbox’ entry. To fill up the entry, you can either browse for the file, or quickly copy and paste the full path location of the file. Usually the latter option is the fastest. Normally, you will do it in the following sequence:

  1. Open ‘Explorer
  2. Navigate the the folder, copy the folder name from address bar
  3. Return back to Book Collector, paste the folder name at the textbox
  4. Return again to Explorer, select the file, press F2/single-click, then copy the filename.
  5. Finally return to Book Collector to paste the filename.

This will become tedious and tiring once you have tens or hundreds entries to key in. So I came up with this solution. The logic of the application will be:

  1. Create a small, transparent floating box which is movable with mouse drag
  2. You can drag and drop a file to this floating box
  3. The full path of that file is copied to the Clipboard
  4. You can go back to Book Collector (or any other use) and paste the full path using Ctrl+V / right-click+paste

Lets tackle the requirement one by one. To create a small, transparent and floating box you need to set the following property:

  • AllowDrop: Change it into True to allow us drag-and-drop object to this Windows Form
  • BackColor: Change it into something cool (which is other than gray)
  • ControlBox: You only need the box. Set it into False
  • FormBorderStyle: Change it to anything but Sizeable.
  • Locked: Set it into True.
  • MaximizeBox: Set it into False
  • MinimizeBox: Set it into False
  • Opacity: This property regulate how transparent is your Windows Form.0% is completely invisible. 100% is not transparent at all. Set the value into around 50%
  • ShowIcon: Set it into False
  • ShowInTaskbar: Set it into False
  • TopMost: Set it into True

Finally modify the constructor to automatically set the size

 

public Form1()
{
   InitializeComponent();

   this.SuspendLayout();

   this.Size = new Size(35, 35);

   this.ResumeLayout();

}

To allow the window to be moved by dragging, you need to declare class-wide variable and create Event handlers

 

private bool isMouseDown = false; // to record whether window on dragging mode
private int oldX; //x-axis position when dragging start
private int oldY; //y-axis position when dragging start

// handle MouseDown Event
private void mouseDown(object sender, MouseEventArgs e)
{

   oldX = e.X;
   oldY = e.Y;
   isMouseDown = true;

}

// handle MouseMove Event
private void mouseMove(object sender, MouseEventArgs e)
{
   if (isMouseDown)
       this.Location = new Point(e.X+this.Location.X-oldX, e.Y+this.Location.Y-oldY);
}

// handle MouseUp Event
private void mouseUp(object sender, MouseEventArgs e)
{
   if (isMouseDown)
       isMouseDown = false;

}

// handle Keypress Event
// To close the program when user press ‘q’
private void Keypressed(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == ‘q’)
       this.Close();
}

The next step is to take care when a user Drop an object into the form

 

private void FmDragOver(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop) || e.Data.GetDataPresent(DataFormats.StringFormat))
    {
       if ((e.AllowedEffect & DragDropEffects.Move) != 0)
       e.Effect = DragDropEffects.Move;
       if (((e.AllowedEffect & DragDropEffects.Copy) != 0) && ((e.KeyState & 0×08) != 0))
       e.Effect = DragDropEffects.Copy;
    }
}

private void FmDragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
   {
      string[] astr = (string[])e.Data.GetData(DataFormats.FileDrop);
      Clipboard.SetText(astr[0]);
   }
}

Download the project here:

This solution has helped me save many minutes spend browsing, copy-pasting file’s full path. I hope it help you too.

Reference:
MSDN

Close
E-mail It
Socialized through Gregarious 42