|
||
|
Clipboard Ring SampleDemonstrates how to build a pinnable Visual Studio style clipboard ring using clipboard notifications and vbAccelerator controls This sample uses the cClipboardViewer class to hook into clipboard change notifications, and then displays them in a pinnable ListBar in a similar manner to the Clipboard Ring functionality provided in Visual Studio. To Run This SampleYou need a number of vbAccelerator controls to run this sample (although I recommend downloading them anyway because they're kinda cool):
Once you have these, you're ready to begin. Run the demonstration. Each time you copy something to the clipboard (from any application on the system), if it contains Text it will be added to the Clipboard Ring bar within the Tools tab. The sample limits the number of items to a maximum of 100 entries, after which it starts deleting the earliest ones; however you can change this limit to anything you want. To add an entry from the clipboard ring bar then either drag it onto the document or double-click/press return in the toolbox itself. Brief DescriptionIf you look at the main MDI form in the control, you'll see that it contains two controls: a Tab Control and a ToolBox ListBar control within the tab control. The tab control is docked left with the Pinnable property set to True and Pinned set to False - this makes the tab display as a vertical bar which slides out its contents when the mouse moves over it. Since there is only going to be one item in the tab (the ToolBox) the ShowTabs property is set to False. This means that if the control is pinned by the user, it will not display tabs at the bottom. The toolbox control is added as a child of the Tab Control at runtime. In this sample, the user isn't allowed to close the toolbox so the CanClose property of the tab is set to false: Dim tabX As cTab ' Set Image List: tabTools.ImageList = ilsIcons ' Don't show tabs when pinned: tabTools.ShowTabs = False ' Add the tab to hold the toolbox: Set tabX = tabTools.Tabs.Add( _ "TOOLS", , _ "Tools", _ ilsIcons.ListImages("TOOLBOX").Index - 1) ' Make the tab contain the toolbox: tabX.Panel = tbxClipboard ' Don't allow the user to close it: tabX.CanClose = False That's all you need to set up the tab control. The ToolBox control is initialised with a single bar and initially just one item (the "Pointer" item which represents no selection): ' Set Image List: tbxClipboard.ImageList = ilsIcons ' Add the Clipboard Ring Bar: Dim tbr As cToolBoxBar Set tbr = tbxClipboard.Bars.Add("CLIPBOARD", , "Clipboard Ring") ' Add the Pointer to the bar: Dim itmX As cToolItem Set itmX = tbr.Items.Add( _ "C" & m_lId, , _ "Pointer", _ ilsIcons.ListImages("POINTER").Index - 1) ' Don't let the user drag this item: itmX.CanDrag = False Finally, the sample checks for clipboard change notifications, and whenever it receives one through the ClipboardChanged event adds it to the toolbox: Private WithEvents m_cClipView As cClipboardViewer .. Private Sub MDIForm_Load() ... Set m_cClipView = New cClipboardViewer m_cClipView.InitClipboardChangeNotification _ Me.hwnd End Sub Private Sub m_cClipView_ClipboardChanged() ' If the clipboard contains text: If (Clipboard.GetFormat(vbCFText)) Then ' Generate a new key: m_lId = m_lId + 1 ' Add the item with this key: Dim itmX As cToolItem Set itmX = tbxClipboard.Bars(1).Items.Add( _ "C" & m_lId, , _ Clipboard.GetText, _ ilsIcons.ListImages("TEXT").Index - 1) ' Limit to 100 entries; if more, then remove the ' earliest one: If (tbxClipboard.Bars(1).Items.Count > 101) Then ' limit to 100 entries: tbxClipboard.Bars(1).Items.Remove "C" & m_lId - 100 End If ' Select the new item (optional): itmX.Selected = True End If End Sub Enhancing ItThis sample is simple enough, but hopefully it demonstrates how easy it is to add powerful tool box functionality to your application. Here are some ideas about further enhancements:
|
|
|