combit List & Label 24 - .NET Online Web Help
Extend Designer by Custom Function
Programming Introduction > Examples > General > Extend Designer by Custom Function

The following example shows how a function can be added that allows querying a registry key within a report. The result of the function could be used in appearance conditions for objects for example. Of course the properties of the DesignerFunction class can also be set directly in the properties window of the development environment.

using (ListLabel LL = new ListLabel())
{
    // Define/Assign data source
    LL.DataSource = CreateDataSet();

                
    // Initialize function
    DesignerFunction RegQuery = new DesignerFunction();
    RegQuery.FunctionName = "RegQuery";
    RegQuery.GroupName = "Registry";
    RegQuery.MinimalParameters = 1;
    RegQuery.MaximumParameters = 1;
    RegQuery.ResultType = LlParamType.String;
    RegQuery.EvaluateFunction += new EvaluateFunctionHandler(RegQuery_EvaluateFunction);

    // Add function
    LL.DesignerFunctions.Add(RegQuery);

    // Call the designer
    LL.Design();
}

// ...

void RegQuery_EvaluateFunction(object sender, EvaluateFunctionEventArgs e)
{
    // Get registry key
    RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\combit\");
    e.ResultValue = key.GetValue(e.Parameter1.ToString()).ToString();
}
Using LL As New ListLabel()
    ' Define/Assign data source
    LL.DataSource = CreateDataSet()

    ' Initialize function
    Dim RegQuery As New DesignerFunction()
    RegQuery.FunctionName = "RegQuery"
    RegQuery.GroupName = "Registry"
    RegQuery.MinimalParameters = 1
    RegQuery.MaximumParameters = 1
    RegQuery.ResultType = LlParamType.[String]
    RegQuery.EvaluateFunction += New EvaluateFunctionHandler(RegQuery_EvaluateFunction)

    ' Add function
    LL.DesignerFunctions.Add(RegQuery)

    ' Call the designer
    LL.Design()
End Using

' ...

Sub RegQuery_EvaluateFunction(sender As Object, e As EvaluateFunctionEventArgs) Handles RegQuery.EvaluateFunction
    ' Get registry key
     Dim key As RegistryKey
     RegistryKey = Registry.CurrentUser.OpenSubKey("Software\combit\")
     e.ResultValue = key.GetValue(e.Parameter1.ToString()).ToString()
 End Sub