// Process mouse-down behavior for click.
 protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (state_ != TextServiceState.ServiceProvided)
         {
             // Attempt to update text from service, and set color
             // state accordingly.
             TextService ts = (TextService)serviceContainer.GetService(typeof(TextService));
             if (ts != null)
             {
                 this.label = ts.text;
                 state      = TextServiceState.ServiceObtained;
             }
             else
             {
                 this.label = "Service Not Found";
                 state      = TextServiceState.ServiceNotFound;
             }
         }
     }
     if (e.Button == MouseButtons.Right)
     {
         if (state_ == TextServiceState.ServiceProvided)
         {
             // Remove service if the container provided it.
             if (serviceContainer.GetService(typeof(TextService)) != null)
             {
                 serviceContainer.RemoveService(typeof(TextService), true);
                 state      = TextServiceState.ServiceNotObtained;
                 this.label = "Service Removed";
             }
         }
         else
         {
             // Obtain string and provide text service.
             using (StringInputDialog form = new StringInputDialog("Test String"))
             {
                 form.StartPosition = FormStartPosition.CenterParent;
                 if (form.ShowDialog() == DialogResult.OK)
                 {
                     if (serviceContainer.GetService(typeof(TextService)) != null)
                     {
                         serviceContainer.RemoveService(typeof(TextService), true);
                     }
                     parent.ResetServiceTree(this, new EventArgs());
                     serviceContainer.AddService(typeof(TextService), new TextService(form.inputTextBox.Text), true);
                     state      = TextServiceState.ServiceProvided;
                     this.label = "Provided Text: " + form.inputTextBox.Text;
                 }
             }
         }
     }
     parent.UpdateServiceCoverage();
 }
 public ServiceObjectControl(ServiceObjectControl serviceContainerParent, Size size, Point location, ServiceForm parent)
 {
     this.state_    = TextServiceState.ServiceNotObtained;
     this.BackColor = Color.Beige;
     this.label     = string.Empty;
     this.Size      = size;
     this.Location  = location;
     this.parent    = parent;
     if (serviceContainerParent == null)
     {
         serviceContainer = new ServiceContainer();
     }
     else
     {
         serviceContainer = new ServiceContainer(serviceContainerParent.serviceContainer);
     }
 }
Ejemplo n.º 3
0
        public ServiceContainerControl(IServiceContainer ParentServiceContainer,
                                       Size size, Point location, ServiceForm parent)
        {
            this.state_       = TextServiceState.ServiceNotObtained;
            localServices     = new SortedList();
            localServiceTypes = new SortedList();

            this.BackColor     = Color.Beige;
            this.label         = string.Empty;
            this.Size          = size;
            this.Location      = location;
            this.parent        = parent;
            this.serviceParent = ParentServiceContainer;

            // If a parent is specified, set the parent property of this
            // linkable IServiceContainer implementation.
            if (ParentServiceContainer != null)
            {
                serviceParent = ParentServiceContainer;
            }
        }
Ejemplo n.º 4
0
        // Process mouse-down behavior for click.
        protected override void OnMouseDown(
            System.Windows.Forms.MouseEventArgs e)
        {
            //  This example control responds to mouse clicks as follows:
            //
            //      Left click - control attempts to obtain a text service
            //      and sets its label text to the text provided by the service
            //      Right click - if the control has already provided a text
            //      service, this control does nothing. Otherwise, the control
            //      shows a dialog box to specify text to provide as a new text
            //      service, after clearing the tree's services.

            if (e.Button == MouseButtons.Left)
            {
                if (state_ != TextServiceState.ServiceProvided)
                {
                    // Attempt to update text from service, and set
                    // color state accordingly.
                    TextService ts =
                        (TextService)GetService(typeof(TextService));
                    if (ts != null)
                    {
                        this.label = ts.text;
                        state      = TextServiceState.ServiceObtained;
                    }
                    else
                    {
                        this.label = "Service Not Found";
                        state      = TextServiceState.ServiceNotFound;
                    }
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                if (state_ == TextServiceState.ServiceProvided)
                {
                    // Remove the service if the container provided it.
                    if (GetService(typeof(TextService)) != null)
                    {
                        RemoveService(typeof(TextService), true);
                        state      = TextServiceState.ServiceNotObtained;
                        this.label = "Service Removed";
                    }
                }
                else
                {
                    // Obtain string and provide text service.
                    using (StringInputDialog form =
                               new StringInputDialog("Test String"))
                    {
                        form.StartPosition = FormStartPosition.CenterParent;
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            if (GetService(typeof(TextService)) != null)
                            {
                                RemoveService(typeof(TextService), true);
                            }
                            parent.ResetServiceTree(this, new EventArgs());

                            AddService(typeof(TextService),
                                       new TextService(form.inputTextBox.Text), true);

                            // The following commented method uses a service creator callback.
                            // AddService(typeof(TextService),
                            //  new ServiceCreatorCallback(this.CreateTextService));

                            state      = TextServiceState.ServiceProvided;
                            this.label = "Provided Text: " + form.inputTextBox.Text;
                        }
                    }
                }
            }
            parent.UpdateServiceCoverage();
        }