ArcObjects Library Reference  

WatermarkFunctionUIForm

About the Create a custom raster function Sample

[C#]

WatermarkFunctionUIForm.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Catalog;
using ESRI.ArcGIS.CatalogUI;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;

namespace CustomFunctionUI
{
    public partial class WatermarkFunctionUIForm : Form
    {
        #region Private Members
        private object myInputRaster;
        private string myWaterMarkImagePath;
        private double myBlendPercentage;
        private bool myDirtyFlag;
        #endregion

        #region WatermarkFunctionUIForm Properties
        /// <summary>
        /// Constructor
        /// </summary>
        public WatermarkFunctionUIForm()
        {
            InitializeComponent();
            myInputRaster = null;
            myWaterMarkImagePath = "";
            myBlendPercentage = 0.0;
        }

        /// <summary>
        /// Get or set the watermark image path
        /// </summary>
        public string WatermarkImagePath
        {
            get
            {
                myWaterMarkImagePath = watermarkImageTxtbox.Text;
                return myWaterMarkImagePath;
            }
            set
            {
                myWaterMarkImagePath = value;
                watermarkImageTxtbox.Text = value;
            }
        }

        /// <summary>
        /// Flag to specify if the form has changed
        /// </summary>
        public bool IsFormDirty
        {
            get
            {
                return myDirtyFlag;
            }
            set
            {
                myDirtyFlag = value;
            }
        }

        /// <summary>
        /// Get or set the input raster
        /// </summary>
        public object InputRaster
        {
            get
            {
                return myInputRaster;
            }
            set
            {
                myInputRaster = value;
                inputRasterTxtbox.Text = GetInputRasterName(myInputRaster);
            }
        }

        /// <summary>
        /// Get or set the blending percentage
        /// </summary>
        public double BlendPercentage
        {
            get
            {
                if (blendPercentTxtbox.Text == "")
                    blendPercentTxtbox.Text = "50.00";
                myBlendPercentage = Convert.ToDouble(blendPercentTxtbox.Text);
                return myBlendPercentage;
            }
            set
            {
                myBlendPercentage = value;
                blendPercentTxtbox.Text = Convert.ToString(value);
            }
        }
        #endregion

        #region WatermarkFunctionUIForm Members
        /// <summary>
        /// This function takes a raster object and returns the formatted name of  
        /// the object for display in the UI.
        /// </summary>
        /// <param name="inputRaster">Object whose name is to be found</param>
        /// <returns>Name of the object</returns>
        private string GetInputRasterName(object inputRaster)
        {
            if ((inputRaster is IRasterDataset))
            {
                IRasterDataset rasterDataset = (IRasterDataset)inputRaster;
                return rasterDataset.CompleteName;
            }

            if (inputRaster is IName)
            {
                if (inputRaster is IDatasetName)
                {
                    IDatasetName inputDSName = (IDatasetName)inputRaster;
                    return inputDSName.Name;
                }

                if (inputRaster is IFunctionRasterDatasetName)
                {
                    IFunctionRasterDatasetName inputFRDName = (IFunctionRasterDatasetName)inputRaster;
                    return inputFRDName.BrowseName;
                }

                if (inputRaster is IMosaicDatasetName)
                {
                    IMosaicDatasetName inputMDName = (IMosaicDatasetName)inputRaster;
                    return "MD";
                }

                IName inputName = (IName)inputRaster;
                return inputName.NameString;
            }
            else if (inputRaster is IRasterFunctionTemplate)
            {
                IRasterFunctionTemplate rasterFunctionTemplate =
                    (IRasterFunctionTemplate)inputRaster;
                return rasterFunctionTemplate.Function.Name;
            }
            else if (inputRaster is IRasterFunctionVariable)
            {
                IRasterFunctionVariable rasterFunctionVariable =
                    (IRasterFunctionVariable)inputRaster;
                return rasterFunctionVariable.Name;
            }

            return "";
        }

        /// <summary>
        /// Updates the UI textboxes using the properties that have been set.
        /// </summary>
        public void UpdateUI()
        {
            if (myInputRaster != null)
                inputRasterTxtbox.Text = GetInputRasterName(myInputRaster);
            blendPercentTxtbox.Text = Convert.ToString(myBlendPercentage);
            watermarkImageTxtbox.Text = myWaterMarkImagePath;
        }

        private void inputRasterBtn_Click(object sender, EventArgs e)
        {
            IEnumGxObject ipSelectedObjects = null;
            ShowRasterDatasetBrowser((int)(Handle.ToInt32()), out ipSelectedObjects);

            IGxObject selectedObject =  ipSelectedObjects.Next();
            if (selectedObject is IGxDataset)
            {
                IGxDataset ipGxDS = (IGxDataset)selectedObject;
                IDataset ipDataset;
                ipDataset = ipGxDS.Dataset;
                myInputRaster = ipDataset.FullName;
                inputRasterTxtbox.Text = GetInputRasterName(myInputRaster);
                myDirtyFlag = true;
            }
        }

        public void ShowRasterDatasetBrowser(int handle, out IEnumGxObject ipSelectedObjects)
        {
            IGxObjectFilterCollection ipFilterCollection = new GxDialogClass();

            IGxObjectFilter ipFilter1 = new GxFilterRasterDatasetsClass();
            ipFilterCollection.AddFilter(ipFilter1, true);
            IGxDialog ipGxDialog = (IGxDialog)(ipFilterCollection);

            ipGxDialog.RememberLocation = true;
            ipGxDialog.Title = "Open";

            ipGxDialog.AllowMultiSelect = false;
            ipGxDialog.RememberLocation = true;

            ipGxDialog.DoModalOpen((int)(Handle.ToInt32()), out ipSelectedObjects);
            return;
        }

        private void watermarkImageBtn_Click(object sender, EventArgs e)
        {
            watermarkImageDlg.ShowDialog();
            if (watermarkImageDlg.FileName != "")
            {
                watermarkImageTxtbox.Text = watermarkImageDlg.FileName;
                myDirtyFlag = true;
            }
        }

        private void blendPercentTxtbox_ModifiedChanged(object sender, EventArgs e)
        {
            if (blendPercentTxtbox.Text != "")
            {
                myBlendPercentage = Convert.ToDouble(blendPercentTxtbox.Text);
                myDirtyFlag = true;
            }
        }
        #endregion

    }
}

[Visual Basic .NET]

WatermarkFunctionUIForm.vb

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports ESRI.ArcGIS.Catalog
Imports ESRI.ArcGIS.CatalogUI
Imports ESRI.ArcGIS.DataSourcesRaster
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.esriSystem

Namespace CustomFunction

    Partial Public Class WatermarkFunctionUIForm
        Inherits Form
#Region "Private Members"
        Private myInputRaster As Object
        Private myWaterMarkImagePath As String
        Private myBlendPercentage As Double
        Private myDirtyFlag As Boolean
#End Region

#Region "WatermarkFunctionUIForm Properties"
        ''' <summary>
        ''' Constructor
        ''' </summary>
        Public Sub New()
            InitializeComponent()
            myInputRaster = Nothing
            myWaterMarkImagePath = ""
            myBlendPercentage = 0.0
        End Sub

        ''' <summary>
        ''' Get or set the watermark image path
        ''' </summary>
        Public Property WatermarkImagePath() As String
            Get
                myWaterMarkImagePath = watermarkImageTxtbox.Text
                Return myWaterMarkImagePath
            End Get
            Set(ByVal value As String)
                myWaterMarkImagePath = value
                watermarkImageTxtbox.Text = value
            End Set
        End Property

        ''' <summary>
        ''' Flag to specify if the form has changed
        ''' </summary>
        Public Property IsFormDirty() As Boolean
            Get
                Return myDirtyFlag
            End Get
            Set(ByVal value As Boolean)
                myDirtyFlag = value
            End Set
        End Property

        ''' <summary>
        ''' Get or set the input raster
        ''' </summary>
        Public Property InputRaster() As Object
            Get
                Return myInputRaster
            End Get
            Set(ByVal value As Object)
                myInputRaster = value
                inputRasterTxtbox.Text = GetInputRasterName(myInputRaster)
            End Set
        End Property

        ''' <summary>
        ''' Get or set the blending percentage
        ''' </summary>
        Public Property BlendPercentage() As Double
            Get
                If blendPercentTxtbox.Text = "" Then
                    blendPercentTxtbox.Text = "50.00"
                End If
                myBlendPercentage = Convert.ToDouble(blendPercentTxtbox.Text)
                Return myBlendPercentage
            End Get
            Set(ByVal value As Double)
                myBlendPercentage = value
                blendPercentTxtbox.Text = Convert.ToString(value)
            End Set
        End Property
#End Region

#Region "WatermarkFunctionUIForm Members"
        ''' <summary>
        ''' This function takes a raster object and returns the formatted name of  
        ''' the object for display in the UI.
        ''' </summary>
        ''' <param name="inputRaster">Object whose name is to be found</param>
        ''' <returns>Name of the object</returns>
        Private Function GetInputRasterName(ByVal inputRaster As Object) As String
            If (TypeOf inputRaster Is IRasterDataset) Then
                Dim rasterDataset As IRasterDataset = DirectCast(inputRaster, IRasterDataset)
                Return rasterDataset.CompleteName
            End If

            If TypeOf inputRaster Is IName Then
                If TypeOf inputRaster Is IDatasetName Then
                    Dim inputDSName As IDatasetName = DirectCast(inputRaster, IDatasetName)
                    Return inputDSName.Name
                End If

                If TypeOf inputRaster Is IFunctionRasterDatasetName Then
                    Dim inputFRDName As IFunctionRasterDatasetName = DirectCast(inputRaster, IFunctionRasterDatasetName)
                    Return inputFRDName.BrowseName
                End If

                If TypeOf inputRaster Is IMosaicDatasetName Then
                    Dim inputMDName As IMosaicDatasetName = DirectCast(inputRaster, IMosaicDatasetName)
                    Return "MD"
                End If

                Dim inputName As IName = DirectCast(inputRaster, IName)
                Return inputName.NameString
            ElseIf TypeOf inputRaster Is IRasterFunctionTemplate Then
                Dim rasterFunctionTemplate As IRasterFunctionTemplate = DirectCast(inputRaster, IRasterFunctionTemplate)
                Return rasterFunctionTemplate.[Function].Name
            ElseIf TypeOf inputRaster Is IRasterFunctionVariable Then
                Dim rasterFunctionVariable As IRasterFunctionVariable = DirectCast(inputRaster, IRasterFunctionVariable)
                Return rasterFunctionVariable.Name
            End If

            Return ""
        End Function

        ''' <summary>
        ''' Updates the UI textboxes using the properties that have been set.
        ''' </summary>
        Public Sub UpdateUI()
            If myInputRaster IsNot Nothing Then
                inputRasterTxtbox.Text = GetInputRasterName(myInputRaster)
            End If
            blendPercentTxtbox.Text = Convert.ToString(myBlendPercentage)
            watermarkImageTxtbox.Text = myWaterMarkImagePath
        End Sub

        Private Sub inputRasterBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim ipSelectedObjects As IEnumGxObject = Nothing
            ShowRasterDatasetBrowser(CInt(Handle.ToInt32()), ipSelectedObjects)

            Dim selectedObject As IGxObject = ipSelectedObjects.[Next]()
            If TypeOf selectedObject Is IGxDataset Then
                Dim ipGxDS As IGxDataset = DirectCast(selectedObject, IGxDataset)
                Dim ipDataset As IDataset
                ipDataset = ipGxDS.Dataset
                myInputRaster = ipDataset.FullName
                inputRasterTxtbox.Text = GetInputRasterName(myInputRaster)
                myDirtyFlag = True
            End If
        End Sub

        Public Sub ShowRasterDatasetBrowser(ByVal handle__1 As Integer, ByRef ipSelectedObjects As IEnumGxObject)
            Dim ipFilterCollection As IGxObjectFilterCollection = New GxDialogClass()

            Dim ipFilter1 As IGxObjectFilter = New GxFilterRasterDatasetsClass()
            ipFilterCollection.AddFilter(ipFilter1, True)
            Dim ipGxDialog As IGxDialog = DirectCast(ipFilterCollection, IGxDialog)

            ipGxDialog.RememberLocation = True
            ipGxDialog.Title = "Open"

            ipGxDialog.AllowMultiSelect = False
            ipGxDialog.RememberLocation = True

            ipGxDialog.DoModalOpen(CInt(Handle.ToInt32()), ipSelectedObjects)
            Return
        End Sub

        Private Sub watermarkImageBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
            watermarkImageDlg.ShowDialog()
            If watermarkImageDlg.FileName <> "" Then
                watermarkImageTxtbox.Text = watermarkImageDlg.FileName
                myDirtyFlag = True
            End If
        End Sub

        Private Sub blendPercentTxtbox_ModifiedChanged(ByVal sender As Object, ByVal e As EventArgs)
            If blendPercentTxtbox.Text <> "" Then
                myBlendPercentage = Convert.ToDouble(blendPercentTxtbox.Text)
                myDirtyFlag = True
            End If
        End Sub
#End Region

    End Class

End Namespace