Export (0) Print
Expand All

IUIService Interface

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

For a list of all members of this type, see IUIService Members.

[Visual Basic]
<Guid("06A9C74B-5E32-4561-BE73-381B37869F4F")>
Public Interface IUIService
[C#]
[Guid("06A9C74B-5E32-4561-BE73-381B37869F4F")]
public interface IUIService
[C++]
[Guid("06A9C74B-5E32-4561-BE73-381B37869F4F")]
public __gc __interface IUIService
[JScript]
public
   Guid("06A9C74B-5E32-4561-BE73-381B37869F4F")
interface IUIService

Remarks

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

Example

[Visual Basic, C#, C++] 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, add the component in the assembly to the Toolbox, and add an instance of the IUIServiceExampleControl to a System.Form. To access the designer verb commands that invoke IUIService methods, either right-click on the component's surface or select a command link in the description pane of the Properties Window while the component is selected.

[Visual Basic] 
Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

' This designer provides a set of designer verb shortcut menu commands
' that call methods of the IUIService.
Public Class IUIServiceTestDesigner
   Inherits System.Windows.Forms.Design.ControlDesigner
   
   Public Sub New()
    End Sub

    ' Provides a set of designer verb menu commands that call 
    ' IUIService methods.
    Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
        Get
            Return New DesignerVerbCollection(New DesignerVerb() { _
                New DesignerVerb("Show a test message box using the IUIService", _
                New EventHandler(AddressOf Me.showTestMessage)), _
                New DesignerVerb("Show a test error message using the IUIService", _
                New EventHandler(AddressOf Me.showErrorMessage)), _
                New DesignerVerb("Show an example Form using the IUIService", _
                New EventHandler(AddressOf Me.showDialog)), _
                New DesignerVerb("Show the Task List tool window using the IUIService", _
                New EventHandler(AddressOf Me.showToolWindow))})
        End Get
    End Property

    ' Displays a message box with message text, caption text 
    ' and buttons of a particular MessageBoxButtons style.
    Private Sub showTestMessage(ByVal sender As Object, ByVal e As EventArgs)
        Dim UIservice As IUIService = CType(Me.GetService( _
            GetType(System.Windows.Forms.Design.IUIService)), IUIService)
        If Not (UIservice Is Nothing) Then
            UIservice.ShowMessage("Test message", "Test caption", _
                System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore)
        End If
    End Sub

    ' Displays an error message box that displays the message
    ' contained within a specified exception.
    Private Sub showErrorMessage(ByVal sender As Object, ByVal e As EventArgs)
        Dim UIservice As IUIService = CType(Me.GetService( _
            GetType(System.Windows.Forms.Design.IUIService)), IUIService)
        If Not (UIservice Is Nothing) Then
            UIservice.ShowError(New Exception( _
                "This is a message in a test exception, displayed by the IUIService", _
                New ArgumentException("Test inner exception")))
        End If
    End Sub

    ' Displays an example Windows Form using the 
    ' IUIService.ShowDialog method.
    Private Sub showDialog(ByVal sender As Object, ByVal e As EventArgs)
        Dim UIservice As IUIService = CType(Me.GetService( _
            GetType(System.Windows.Forms.Design.IUIService)), IUIService)
        If Not (UIservice Is Nothing) Then
            UIservice.ShowDialog(New ExampleForm())
        End If
    End Sub

    ' Displays a standard tool window using the 
    ' IUIService.ShowToolWindow method.
    Private Sub showToolWindow(ByVal sender As Object, ByVal e As EventArgs)
        Dim UIservice As IUIService = CType(Me.GetService( _
            GetType(System.Windows.Forms.Design.IUIService)), IUIService)
        If Not (UIservice Is Nothing) Then
            UIservice.ShowToolWindow(StandardToolWindows.TaskList)
        End If
    End Sub

End Class

' Provides an example Form class used by the 
' IUIServiceTestDesigner.showDialog method.
Friend Class ExampleForm
    Inherits System.Windows.Forms.Form

    Public Sub New()
        Me.Text = "Example Form"
        Dim okButton As New System.Windows.Forms.Button()
        okButton.Location = New Point(Me.Width - 70, Me.Height - 70)
        okButton.Size = New Size(50, 20)
        okButton.Anchor = AnchorStyles.Right Or AnchorStyles.Bottom
        okButton.DialogResult = DialogResult.OK
        okButton.Text = "OK"
        Me.Controls.Add(okButton)
    End Sub
End Class

' This control is associated with the IUIServiceTestDesigner, 
' and can be sited in design mode to use the sample.
<DesignerAttribute(GetType(IUIServiceTestDesigner), GetType(IDesigner))> _
Public Class IUIServiceExampleControl
    Inherits UserControl

    Public Sub New()
        Me.BackColor = Color.Beige
        Me.Width = 255
        Me.Height = 60
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        If Me.DesignMode Then
            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)
        End If
    End Sub
End Class

[C#] 
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);
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.Design.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;

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

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

   // Provides a set of designer verb menu commands that call IUIService methods.
   __property System::ComponentModel::Design::DesignerVerbCollection* get_Verbs() {
      DesignerVerb* temp0 [] = {
         new DesignerVerb(S"Show a test message box using the IUIService", new EventHandler(this, &IUIServiceTestDesigner::showTestMessage)),
            new DesignerVerb(S"Show a test error message using the IUIService", new EventHandler(this, &IUIServiceTestDesigner::showErrorMessage)),
            new DesignerVerb(S"Show an example Form using the IUIService", new EventHandler(this, &IUIServiceTestDesigner::showDialog)),
            new DesignerVerb(S"Show the Task List tool window using the IUIService", new EventHandler(this, &IUIServiceTestDesigner::showToolWindow))
      };
      return new DesignerVerbCollection(temp0);
   }

private:
   // Displays a message box with message text, caption text
   // and buttons of a particular MessageBoxButtons style.
   void showTestMessage(Object* /*sender*/, EventArgs* /*e*/) {
      IUIService* UIservice = dynamic_cast<IUIService*>(this->GetService(__typeof(System::Windows::Forms::Design::IUIService)));
      if (UIservice != 0)
         UIservice->ShowMessage(S"Test message", S"Test caption", System::Windows::Forms::MessageBoxButtons::AbortRetryIgnore);
   }

   // Displays an error message box that displays the message
   // contained within a specified exception.
   void showErrorMessage(Object* /*sender*/, EventArgs* /*e*/) {
      IUIService* UIservice = dynamic_cast<IUIService*>(this->GetService(__typeof(System::Windows::Forms::Design::IUIService)));
      if (UIservice != 0)
         UIservice->ShowError(new Exception(S"This is a message in a test exception, displayed by the IUIService", new ArgumentException(S"Test inner exception")));
   }

   // Displays an example Windows Form using the
   // IUIService::ShowDialog method.
   void showDialog(Object* /*sender*/, EventArgs* /*e*/) {
      IUIService* UIservice = dynamic_cast<IUIService*>(this->GetService(__typeof(System::Windows::Forms::Design::IUIService)));
      if (UIservice != 0)
         UIservice->ShowDialog(new ExampleForm());
   }

   // Displays a standard tool window window using the
   // IUIService::ShowToolWindow method.
   void showToolWindow(Object* /*sender*/, EventArgs* /*e*/) {
      IUIService* UIservice = dynamic_cast<IUIService*>(this->GetService(__typeof(System::Windows::Forms::Design::IUIService)));
      if (UIservice != 0)
         UIservice->ShowToolWindow(StandardToolWindows::TaskList);
   }
};

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms.Design

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

IUIService Members | System.Windows.Forms.Design Namespace

Show:
© 2014 Microsoft