Click here to Skip to main content
15,886,664 members
Articles / Productivity Apps and Services / Microsoft Office

RefEdit Emulation for .NET

Rate me:
Please Sign up or sign in to vote.
4.75/5 (14 votes)
27 Oct 2012CPOL6 min read 91.9K   3.8K   29  
A simple implementation of a ref edit control for .NET
Imports Microsoft.Office.Interop
Imports System.Runtime.InteropServices

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim excelApp As Excel.Application = Nothing

        ' Create an Excel App
        Try
            excelApp = Marshal.GetActiveObject("Excel.Application")
        Catch ex As COMException
            ' An exception is thrown if there is not an open excel instance.                    
        Finally
            If excelApp Is Nothing Then
                excelApp = New Microsoft.Office.Interop.Excel.Application
                excelApp.Workbooks.Add()
            End If
            excelApp.Visible = True

            Me.Excel2007RefEdit1.ExcelConnector = excelApp
            Me.Excel2007RefEdit2.ExcelConnector = excelApp
            Me.Excel2007RefEdit3.ExcelConnector = excelApp
        End Try

        Me.Excel2007RefEdit1.Focus()

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Button1.Focus()
    End Sub

    'Private Sub Excel2007RefEdit1_AfterResize(ByVal sender As Object, ByVal e As LeafCreations.EventArgs.AfterResizeEventArgs) Handles Excel2007RefEdit1.AfterResize
    '    MsgBox(String.Format(": IsMinimized = {0}", e.DisplayState.IsParentMinimized))
    'End Sub

    'Private Sub Excel2007RefEdit1_BeforeResize(ByVal sender As Object, ByVal e As LeafCreations.EventArgs.BeforeResizeEventArgs) Handles Excel2007RefEdit1.BeforeResize
    '    MsgBox(String.Format("BeforeResize: IsMinimized = {0}", e.DisplayState.IsParentMinimized))
    'End Sub

    Private Sub Excel2007RefEdit1_OnSelectionChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Excel2007RefEdit1.Changed
        Me.TextBox1.Text = Me.Excel2007RefEdit1.Address
    End Sub

    Private Sub chkShowSheetName_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkShowSheetName.CheckedChanged
        Me.Excel2007RefEdit1.IncludeSheetName = Me.chkShowSheetName.Checked
    End Sub

    Private Sub chkShowRowAbsolute_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkShowRowAbsolute.CheckedChanged
        Me.Excel2007RefEdit1.ShowRowAbsoluteIndicator = Me.chkShowRowAbsolute.Checked
    End Sub

    Private Sub chkShowColumnAbsolute_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkShowColumnAbsolute.CheckedChanged
        Me.Excel2007RefEdit1.ShowColumnAbsoluteIndicator = Me.chkShowColumnAbsolute.Checked
    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
United States United States
I am a .NET/Office/SQL programmer. Although by day I work for as a software developer for a big distribution company, by night I enjoy creating things. My major nocturnal project is Office Ribbon Editor (http://www.leafcreations.org).

I have dabbled in such languages as java, c, c++, php, cf, objective C and even cobol. At this moment, I am sticking with the .NET languages.

Comments and Discussions