packages/Windows API Code Pack 1.1/source/Samples/Shell/TabbedThumbnailDemo/CS/Winforms/Form1.cs
/// <summary>
/// Open a user-specified text file in a new tab (using a RichTextBox)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Open a user-specified text file in a new tab (using a RichTextBox)
Open a user - specified text file in a new tab ( using a RichTextBox )
private void button3_Click(object sender, EventArgs e)
        {
            CommonOpenFileDialog cfd = new CommonOpenFileDialog();
            CommonFileDialogStandardFilters.TextFiles.ShowExtensions = true;
            CommonFileDialogFilter rtfFilter = new CommonFileDialogFilter("RTF Files", ".rtf");
            rtfFilter.ShowExtensions = true;
            cfd.Filters.Add(CommonFileDialogStandardFilters.TextFiles);
            cfd.Filters.Add(rtfFilter);
            if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                TabPage newTab = new TabPage(Path.GetFileName(cfd.FileName));
                tabControl1.TabPages.Add(newTab);
                RichTextBox rtbText = new RichTextBox();
                rtbText.KeyDown += new KeyEventHandler(rtbText_KeyDown);
                rtbText.MouseMove += new MouseEventHandler(rtbText_MouseMove);
                rtbText.KeyUp += new KeyEventHandler(rtbText_KeyUp);
                rtbText.Dock = DockStyle.Fill;
                if (Path.GetExtension(cfd.FileName).ToLower() == ".txt")
                    rtbText.LoadFile(cfd.FileName, RichTextBoxStreamType.PlainText);
                else if (Path.GetExtension(cfd.FileName).ToLower() == ".rtf")
                    rtbText.LoadFile(cfd.FileName, RichTextBoxStreamType.RichText);
                newTab.Controls.Add(rtbText);
                TabbedThumbnail preview = new TabbedThumbnail(this.Handle, newTab.Handle);
                preview.TabbedThumbnailActivated += preview_TabbedThumbnailActivated;
                preview.TabbedThumbnailClosed += preview_TabbedThumbnailClosed;
                preview.TabbedThumbnailMaximized += preview_TabbedThumbnailMaximized;
                preview.TabbedThumbnailMinimized += preview_TabbedThumbnailMinimized;
                preview.ClippingRectangle = GetClippingRectangle(rtbText);
                TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(preview);
                TaskbarManager.Instance.ThumbnailToolBars.AddButtons(newTab.Handle, thumbButtonCut, thumbButtonCopy, thumbButtonPaste, thumbButtonSelectAll);
                tabControl1.SelectedTab = newTab;
                TaskbarManager.Instance.TabbedThumbnail.SetActiveTab(tabControl1.SelectedTab);
                button2.Enabled = true;
                button4.Enabled = true;
            }
        }
private void button3_Click ( object sender , EventArgs e ) { CommonOpenFileDialog cfd = new CommonOpenFileDialog ( ) ; CommonFileDialogStandardFilters . TextFiles . ShowExtensions = true ; CommonFileDialogFilter rtfFilter = new CommonFileDialogFilter ( " " , " " ) ; rtfFilter . ShowExtensions = true ; cfd . Filters . Add ( CommonFileDialogStandardFilters . TextFiles ) ; cfd . Filters . Add ( rtfFilter ) ; if ( cfd . ShowDialog ( ) == CommonFileDialogResult . Ok ) { TabPage newTab = new TabPage ( Path . GetFileName ( cfd . FileName ) ) ; tabControl1 . TabPages . Add ( newTab ) ; RichTextBox rtbText = new RichTextBox ( ) ; rtbText . KeyDown += new KeyEventHandler ( rtbText_KeyDown ) ; rtbText . MouseMove += new MouseEventHandler ( rtbText_MouseMove ) ; rtbText . KeyUp += new KeyEventHandler ( rtbText_KeyUp ) ; rtbText . Dock = DockStyle . Fill ; if ( Path . GetExtension ( cfd . FileName ) . ToLower ( ) == " " ) rtbText . LoadFile ( cfd . FileName , RichTextBoxStreamType . PlainText ) ; else if ( Path . GetExtension ( cfd . FileName ) . ToLower ( ) == " " ) rtbText . LoadFile ( cfd . FileName , RichTextBoxStreamType . RichText ) ; newTab . Controls . Add ( rtbText ) ; TabbedThumbnail preview = new TabbedThumbnail ( this . Handle , newTab . Handle ) ; preview . TabbedThumbnailActivated += preview_TabbedThumbnailActivated ; preview . TabbedThumbnailClosed += preview_TabbedThumbnailClosed ; preview . TabbedThumbnailMaximized += preview_TabbedThumbnailMaximized ; preview . TabbedThumbnailMinimized += preview_TabbedThumbnailMinimized ; preview . ClippingRectangle = GetClippingRectangle ( rtbText ) ; TaskbarManager . Instance . TabbedThumbnail . AddThumbnailPreview ( preview ) ; TaskbarManager . Instance . ThumbnailToolBars . AddButtons ( newTab . Handle , thumbButtonCut , thumbButtonCopy , thumbButtonPaste , thumbButtonSelectAll ) ; tabControl1 . SelectedTab = newTab ; TaskbarManager . Instance . TabbedThumbnail . SetActiveTab ( tabControl1 . SelectedTab ) ; button2 . Enabled = true ; button4 . Enabled = true ; } }
Open a user-specified text file in a new tab (using a RichTextBox)
Open a user - specified text file in a new tab ( using a RichTextBox )
// Open text file // Based on the extension, load the file appropriately in the RichTextBox // Update the tab // Add a new preview // Event handlers for this preview // Add thumbnail toolbar buttons // Select the tab in the application UI as well as taskbar tabbed thumbnail list
sender
object
None
e
EventArgs
None