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 class IUIService

NameDescription
System_CAPS_pubpropertyStyles

Gets the collection of styles that are specific to the host's environment.

NameDescription
System_CAPS_pubmethodCanShowComponentEditor(Object^)

Indicates whether the component can display a ComponentEditorForm.

System_CAPS_pubmethodGetDialogOwnerWindow()

Gets the window that should be used as the owner when showing dialog boxes.

System_CAPS_pubmethodSetUIDirty()

Sets a flag indicating the UI has changed.

System_CAPS_pubmethodShowComponentEditor(Object^, IWin32Window^)

Attempts to display a ComponentEditorForm for a component.

System_CAPS_pubmethodShowDialog(Form^)

Attempts to display the specified form in a dialog box.

System_CAPS_pubmethodShowError(Exception^)

Displays the specified exception and information about the exception in a message box.

System_CAPS_pubmethodShowError(Exception^, String^)

Displays the specified exception and information about the exception in a message box.

System_CAPS_pubmethodShowError(String^)

Displays the specified error message in a message box.

System_CAPS_pubmethodShowMessage(String^)

Displays the specified message in a message box.

System_CAPS_pubmethodShowMessage(String^, String^)

Displays the specified message in a message box with the specified caption.

System_CAPS_pubmethodShowMessage(String^, String^, MessageBoxButtons)

Displays the specified message in a message box with the specified caption and buttons to place on the dialog box.

System_CAPS_pubmethodShowToolWindow(Guid)

Displays the specified tool window.

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.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.
ref class ExampleForm: public System::Windows::Forms::Form
{
public:
   ExampleForm()
   {
      this->Text = "Example Form";
      System::Windows::Forms::Button^ okButton = gcnew 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 = "OK";
      this->Controls->Add( okButton );
   }
};

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

   property System::ComponentModel::Design::DesignerVerbCollection^ Verbs 
   {
      // Provides a set of designer verb menu commands that call IUIService methods.
      virtual System::ComponentModel::Design::DesignerVerbCollection^ get() override
      {
         array<DesignerVerb^>^temp0 = {gcnew DesignerVerb( "Show a test message box using the IUIService",gcnew EventHandler( this, &IUIServiceTestDesigner::showTestMessage ) ),gcnew DesignerVerb( "Show a test error message using the IUIService",gcnew EventHandler( this, &IUIServiceTestDesigner::showErrorMessage ) ),gcnew DesignerVerb( "Show an example Form using the IUIService",gcnew EventHandler( this, &IUIServiceTestDesigner::showDialog ) ),gcnew DesignerVerb( "Show the Task List tool window using the IUIService",gcnew EventHandler( this, &IUIServiceTestDesigner::showToolWindow ) )};
         return gcnew 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( System::Windows::Forms::Design::IUIService::typeid ));
      if ( UIservice != nullptr )
            UIservice->ShowMessage( "Test message", "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( System::Windows::Forms::Design::IUIService::typeid ));
      if ( UIservice != nullptr )
            UIservice->ShowError( gcnew Exception( "This is a message in a test exception, displayed by the IUIService",gcnew ArgumentException( "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( System::Windows::Forms::Design::IUIService::typeid ));
      if ( UIservice != nullptr )
            UIservice->ShowDialog( gcnew 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( System::Windows::Forms::Design::IUIService::typeid ));
      if ( UIservice != nullptr )
            UIservice->ShowToolWindow( StandardToolWindows::TaskList );
   }
};

// This control is associated with the IUIServiceTestDesigner,
// and can be sited in design mode to use the sample.

[DesignerAttribute(IUIServiceTestDesigner::typeid,IDesigner::typeid)]
ref class IUIServiceExampleControl: public UserControl
{
public:
   IUIServiceExampleControl()
   {
      this->BackColor = Color::Beige;
      this->Width = 255;
      this->Height = 60;
   }

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

.NET Framework
Available since 1.1
Return to top
Show: