Click here to Skip to main content
15,891,704 members
Articles / Desktop Programming / Windows Forms

MS Office-like TaskPane Control

Rate me:
Please Sign up or sign in to vote.
4.85/5 (25 votes)
24 Apr 2007CPOL10 min read 128.9K   8.4K   262  
A .NET TaskPane control, with full design-time support.
Imports System.IO

Public Class DocumentForm

    Private m_DocumentPath As String = ""
    Private m_CurrentStart As Integer = 0

    Public Property DocumentPath() As String
        Get
            Return m_DocumentPath
        End Get
        Set(ByVal value As String)
            m_DocumentPath = value

            If m_DocumentPath IsNot Nothing AndAlso File.Exists(m_DocumentPath) Then
                Try
                    rtbDocument.LoadFile(m_DocumentPath)
                Catch ex As Exception
                    rtbDocument.LoadFile(m_DocumentPath, RichTextBoxStreamType.PlainText)
                End Try

                Me.Text = Path.GetFileName(m_DocumentPath)
            Else
                MessageBox.Show("Cannot load document: " & Environment.NewLine & Environment.NewLine _
                                & m_DocumentPath, "Error Loading Document")
            End If
        End Set
    End Property

    Public Sub ClearSelection()
        rtbDocument.SelectedText = ""
    End Sub

    Public Sub FindText(ByVal argText As String)
        If argText.Length = 0 Then Return

        rtbDocument.Find(argText, m_CurrentStart, RichTextBoxFinds.None)
    End Sub

    Private Sub rtbDocument_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbDocument.SelectionChanged
        m_CurrentStart = rtbDocument.SelectionStart

        If rtbDocument.SelectionLength > 0 Then
            m_CurrentStart += 1 ' make sure it finds the NEXT match, not the current one
        End If
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Microsoft
United States United States
I did some stuff.. I live in Seattle.. now I work for Live Search at Microsoft Smile | :)

Comments and Discussions