The Sandbox Thread

19 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Chili Clipboard: An extended clipboard

Back to Forum: The Sandbox
  • littleguru

    A little application that monitors the clipboard. It shows the clipboard history in a popup window and allows to put any entry back into the clipboard.

    It contains a class that monitors the system clipboard: ClipboardMonitor. The class creates internally a NativeWindow that registers as clipboard viewer and processes the messages send by the system (if the content of the clipboard changed).

    The app also tries to show a way to create a popup window (by processing a few windows messages) and to start an application in the system tray without showing the main window.


    I have seen that the topic of starting an application displaying a notify icon in the system tray area is an often discussed topic in news groups... although the solution is quite simple.

    Once the NotifyIcon control is placed on the form, you only need to instanciate the form. Once instanciated the NotifyIcon control shows the icon in the system tray. It is not required to show the form!
    The application is then started without providing a form. That means that it can only be closed by calling Application.Exit() and not by closing the main form (there is no main form provided).

    MainForm form = new MainForm();
    Application.Run();

    The sample shows also how to inherit from ListBox and create your own custom drawn listbox items. Each listbox item is custom drawn and has a button (visible on the right side of the item when selected). After clicking the button a context menu pops up. It contains actions that can be done on the listbox item.

    As last nice feature the app has a class (AutoStarter) that registers or unregisters the application to start with the system. That is done by setting the appropriate keys in the registry.


    I hope you enjoy my work.

    Version 1.0.1:
    - Showing now the icon of the application (if available) that put the item into the clipboard. As suggested by Ion.

    Version 1.0.2:
    - Fixed minor issues with putting an item back into clipboard.
    - Added clear all link to main menu.
    - Added limit of max. items in history.

    Version 1.0.3:
    - Fixed minor bugs.
    - Enhanced UI.

  • Ion Todirel

    Instead of using fixed icons (in ClipboardItemListBox ()) whould't be better to use Icon.ExtractAssociatedIcon (if it make sense)?

  • littleguru

    New version 1.0.2 is up.

  • littleguru

    Version 1.0.3 is up.

  • Sven Groot

    Very nice! I love the UI, very Vista-ish. Smiley

    Two things I noticed:
    1. You're overriding the WndProc to detect when the form loses focus? Any particular reason why you're not using the Deactivated event?
    2. You're setting the font manually to Segoe UI, 9pt. Instead of doing that, I recommend setting it to SystemFonts.IconTitleFont (do this in the constructor after calling InitializeComponents, or do it in the Load event; the latter is required if you don't want to do it in DesignMode (which is what I do). This has the advantage of using Segoe UI on Vista, Tahoma on XP, and Sans Serif elsewhere, and it also obeys the user's font size settings.

    I have a class that I use as the base class for most of my forms that does this for me:

    /// <summary>
    /// Base class for windows forms that should follow the global font scheme settings.
    /// </summary>
    /// <remarks>
    /// This class makes sure the form uses Tahoma on XP and Segoe UI on Vista. Please make sure your
    /// form's <see cref="System.Windows.Forms.ContainerControl.AutoScaleMode" /> property is set to
    /// Font, and make special provisions if your form uses graphics or anything like that.
    /// </remarks>
    public class AutoFontForm : Form
    {
       /// <summary>
       /// Creates a new instance of the <see cref="AutoFontForm" /> class.
       /// </summary>
       public AutoFontForm()
       {
          this.Load += new EventHandler(AutoFontForm_Load);
       }

       void AutoFontForm_Load(object sender, EventArgs e)
       {
          if( !DesignMode )
          {
             Font = System.Drawing.SystemFonts.IconTitleFont;
             Microsoft.Win32.SystemEvents.UserPreferenceChanged += new Microsoft.Win32.UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
          }
       }

       void SystemEvents_UserPreferenceChanged(object sender, Microsoft.Win32.UserPreferenceChangedEventArgs e)
       {
          if( e.Category == Microsoft.Win32.UserPreferenceCategory.Window )
             Font = System.Drawing.SystemFonts.IconTitleFont;
       }
    }


    There's some issues with graphics since automatic scaling will also resize your pictureboxes if you have any, and you definitely need to test with all three fonts and different sizes (since MS Sans Serif, Tahoma and Segoe UI have wildly different font metrics), but other than that it works great.
  • littleguru

    Hi Sven. Thanks for your feedback.

    1) I override, since Deactivate is also fired if a messagebox shows up. That happens when clicking the "clear history" link. In that case the popup window disappears, which is not what i wanted... By overriding the window proc this doesn't happen Smiley

    2) I'll fix that Smiley

  • Sven Groot

    littleguru wrote:
    1) I override, since Deactivate is also fired if a messagebox shows up. That happens when clicking the "clear history" link. In that case the popup window disappears, which is not what i wanted... By overriding the window proc this doesn't happen

    That makes sense. I find it's usually a good idea to document this kind of thing in your code with comments, if I don't I come back to it after six months and think "why the hell did I do that"? Also, it's better to use a named constant for the window message you're looking for rather than using a magic number in your code. Right now I have to search through the header files to find out which one it is.

    Sorry if it sounds like I'm lecturing you, the Teaching Assistant in me tends to come out sometimes. Tongue Out

    Other than that, as I've said, very nice app. Smiley

  • littleguru

    I know, there are some places of improvement (documentation + using constants - and a lot other stuff to btw.)... but I haven't had the time and passion to do them Tongue Out

  • phreaks

    Way cool.
    Great job.

  • anthq11

    thats awesome!

    nice job

  • Oggelito

    Excellent work with the interface.
    A clipboard manager is a must have, and this is the best I've seen so far.

  • blowdart

    Sweet.

    But it kills RDPCLIP, no more cutting in a remote desktop window and pasting in the host machine

  • littleguru

    blowdart wrote:
    Sweet.

    But it kills RDPCLIP, no more cutting in a remote desktop window and pasting in the host machine


    Strange. I register only the app in the notification queue and unregister it on exit.

  • harumscarum

        Finally downloaded this and I am really liking it. Just a couple questions:

    1) Why Chili?
    2) When I click on the icon in the taskbar with the app open shouldn't it close it instead of reopening?

  • littleguru

    harumscarum wrote:
        Finally downloaded this and I am really liking it. Just a couple questions:

    1) Why Chili?
    2) When I click on the icon in the taskbar with the app open shouldn't it close it instead of reopening?


    Thanks for the feedback.

    1) Because I needed a root namespace and came up with Chili. I know it's not very genial, but anyways... www.chilisoftware.net is now my "company" Wink

    2) This is the same as with the other popups in Vista (try with the volume, energy or network popup). If you click the icon they will also not get hidden!

  • N3mr0d

    Hello!

    Nice work, very useful. I was wondering if you thought if it would be possible to create a drag&drop on purpose to move data from and to other apps?


  • littleguru

    N3mr0d wrote:
    Hello!

    Nice work, very useful. I was wondering if you thought if it would be possible to create a drag&drop on purpose to move data from and to other apps?


    Cool that you like it Smiley

    You mean from the clipboard history window to an app?

  • N3mr0d

    Yes, text, bitmaps or other things... I assume that it should possible to do it with text, but with more complex objects? And why not in the two ways? from you clipboard manager to apps, and from apps to the clipboard?

    I thought of that functionnality when I saw the demo of "surface" and this  wondrous screen from perceptive pixel.

    If I had more time, and more confidence in my skills in .net I would try to code it... Holliday soon Big Smile.

    I'll keep in touch if I am able to do it Tongue Out

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.