英語で読む

次の方法で共有


IUIService インターフェイス

定義

デザイナーをホストしている開発環境オブジェクトのユーザー インターフェイスとの対話を有効にします。

C#
[System.Runtime.InteropServices.Guid("06A9C74B-5E32-4561-BE73-381B37869F4F")]
public interface IUIService
属性

次のコード例では、デザイナーのメソッドを呼び出すデザイナー動詞メニュー コマンドを提供するデザイナーを IUIService作成します。 この例を使用するには、サンプル コードをアセンブリにコンパイルし、Windows フォーム アプリケーションでアセンブリへの参照を追加します。 Visual Studioを使用している場合は、IUIServiceExampleControlツールボックスに自動的に追加 されます。 のインスタンスを IUIServiceExampleControl 追加します Form。 メソッドを呼び出す IUIService デザイナー動詞コマンドにアクセスするには、コントロールの画面を右クリックするか、コントロールのスマート タグ グリフをクリックして、スマート タグ パネルから項目を選択します。

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);
        }
    }
}

注釈

IUIService では、ディクショナリ プロパティを使用して、エラー メッセージの表示、ダイアログ ボックスの表示、ホストのアンビエント プロパティ (ダイアログ ボックスや配色のフォントなど) を Styles 取得できます。

プロパティ

Styles

ホストの環境に固有なスタイルのコレクションを取得します。

メソッド

CanShowComponentEditor(Object)

コンポーネントが ComponentEditorForm を表示できるかどうかを示します。

GetDialogOwnerWindow()

ダイアログ ボックスを表示するときに所有者として使用するウィンドウを取得します。

SetUIDirty()

UI が変更されたことを示すフラグを設定します。

ShowComponentEditor(Object, IWin32Window)

コンポーネントの ComponentEditorForm を表示しようとします。

ShowDialog(Form)

指定したフォームをダイアログ ボックスに表示しようとします。

ShowError(Exception)

指定した例外および例外に関する情報をメッセージ ボックスに表示します。

ShowError(Exception, String)

指定した例外および例外に関する情報をメッセージ ボックスに表示します。

ShowError(String)

指定したエラー メッセージをメッセージ ボックスに表示します。

ShowMessage(String)

指定したメッセージをメッセージ ボックスに表示します。

ShowMessage(String, String)

キャプションを指定して、指定したメッセージをメッセージ ボックスに表示します。

ShowMessage(String, String, MessageBoxButtons)

キャプションおよびダイアログ ボックスに配置するボタンを指定して、指定したメッセージをメッセージ ボックスに表示します。

ShowToolWindow(Guid)

指定したツール ウィンドウを表示します。

適用対象

製品 バージョン
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7