Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IUIService Interface

Enables interaction with the user interface of the development environment object that is hosting the designer.

Namespace:  System.Windows.Forms.Design
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
[GuidAttribute("06A9C74B-5E32-4561-BE73-381B37869F4F")]
public interface IUIService

The IUIService type exposes the following members.

  NameDescription
Public propertyStylesGets the collection of styles that are specific to the host's environment.
Top
  NameDescription
Public methodCanShowComponentEditorIndicates whether the component can display a ComponentEditorForm.
Public methodGetDialogOwnerWindowGets the window that should be used as the owner when showing dialog boxes.
Public methodSetUIDirtySets a flag indicating the UI has changed.
Public methodShowComponentEditorAttempts to display a ComponentEditorForm for a component.
Public methodShowDialogAttempts to display the specified form in a dialog box.
Public methodShowError(Exception)Displays the specified exception and information about the exception in a message box.
Public methodShowError(String)Displays the specified error message in a message box.
Public methodShowError(Exception, String)Displays the specified exception and information about the exception in a message box.
Public methodShowMessage(String)Displays the specified message in a message box.
Public methodShowMessage(String, String)Displays the specified message in a message box with the specified caption.
Public methodShowMessage(String, String, MessageBoxButtons)Displays the specified message in a message box with the specified caption and buttons to place on the dialog box.
Public methodShowToolWindowDisplays the specified tool window.
Top

IUIService can display error messages, show dialog boxes, and get ambient properties of the host, such as the font for dialog boxes and color schemes, through the Styles dictionary property.

The following code example creates a designer that provides designer verb menu commands that call methods of the IUIService. To use the example, compile the sample code to an assembly, and add a reference to the assembly in a Windows Forms application. If you are using Visual Studio, the IUIServiceExampleControl is automatically added to the Toolbox. Add an instance of the IUIServiceExampleControl to a Form. To access the designer verb commands that invoke IUIService methods, either right-click on the control's surface or click on the control's smart tag glyph and select an item from the smart tag panel.

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

// This designer provides a set of designer verb shortcut menu commands 
// that call methods of the IUIService. 
public class IUIServiceTestDesigner : System.Windows.Forms.Design.ControlDesigner
{
    public IUIServiceTestDesigner()
    {
    }

    // Provides a set of designer verb menu commands that call  
    // IUIService methods. 
    public override System.ComponentModel.Design.DesignerVerbCollection Verbs
    {
        get
        {
            return new DesignerVerbCollection( new DesignerVerb[] 
            {
                new DesignerVerb( 
                    "Show a test message box using the IUIService", 
                     new EventHandler(this.showTestMessage)),
                new DesignerVerb( 
                    "Show a test error message using the IUIService", 
                     new EventHandler(this.showErrorMessage)),
                new DesignerVerb( 
                    "Show an example Form using the IUIService", 
                     new EventHandler(this.showDialog)),
                new DesignerVerb( 
                     "Show the Task List tool window using the IUIService", 
                     new EventHandler(this.showToolWindow)) 
            });
        }
    }

    // Displays a message box with message text, caption text  
    // and buttons of a particular MessageBoxButtons style. 
    private void showTestMessage(object sender, EventArgs e)
    {
        IUIService UIservice = (IUIService)this.GetService( 
            typeof( System.Windows.Forms.Design.IUIService ) );
        if( UIservice != null )            
            UIservice.ShowMessage("Test message", "Test caption", 
                System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore);
    }

    // Displays an error message box that displays the message 
    // contained in a specified exception. 
    private void showErrorMessage(object sender, EventArgs e)
    {       
        IUIService UIservice = (IUIService)this.GetService( 
            typeof( System.Windows.Forms.Design.IUIService ) );
        if( UIservice != null )            
            UIservice.ShowError( new Exception(
                "This is a message in a test exception, " + 
                "displayed by the IUIService", 
                 new ArgumentException("Test inner exception")));
    }

    // Displays an example Windows Form using the  
    // IUIService.ShowDialog method. 
    private void showDialog(object sender, EventArgs e)
    {
        IUIService UIservice = (IUIService)this.GetService( 
            typeof( System.Windows.Forms.Design.IUIService ) );
        if( UIservice != null )            
            UIservice.ShowDialog(new ExampleForm());
    }

    // Displays a standard tool window using the  
    // IUIService.ShowToolWindow method. 
    private void showToolWindow(object sender, EventArgs e)
    {
        IUIService UIservice = (IUIService)this.GetService( 
            typeof( System.Windows.Forms.Design.IUIService ) );
        if( UIservice != null )            
            UIservice.ShowToolWindow(StandardToolWindows.TaskList);
    }
}

// Provides an example Form class used by the  
// IUIServiceTestDesigner.showDialog method. 
internal class ExampleForm : System.Windows.Forms.Form
{
    public ExampleForm()
    {
        this.Text = "Example Form";
        System.Windows.Forms.Button okButton = new System.Windows.Forms.Button();
        okButton.Location = new Point(this.Width-70, this.Height-70);
        okButton.Size = new Size(50, 20);
        okButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
        okButton.DialogResult = DialogResult.OK;
        okButton.Text = "OK";
        this.Controls.Add( okButton );
    }
}

// This control is associated with the IUIServiceTestDesigner,  
// and can be sited in design mode to use the sample.
[DesignerAttribute(typeof(IUIServiceTestDesigner), typeof(IDesigner))]
public class IUIServiceExampleControl : UserControl
{
    public IUIServiceExampleControl()
    {
        this.BackColor = Color.Beige;
        this.Width = 255;
        this.Height = 60;
    }

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        if( this.DesignMode )
        {
            e.Graphics.DrawString(
                "Right-click this control to display a list of the", 
                 new Font("Arial", 9), Brushes.Black, 5, 6);
            e.Graphics.DrawString(
                "designer verb menu commands provided", 
                 new Font("Arial", 9), Brushes.Black, 5, 20);
            e.Graphics.DrawString( 
                "by the IUIServiceTestDesigner.", 
                 new Font("Arial", 9), Brushes.Black, 5, 34);
        }
    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.