Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
PopupColorPickerTool problem!
posted
I want to enable Live preview feature for my app with color picker, just like Word. But I don't see any event that occurs when the mouse is over the color item in the color picker. I have searched in the net but don't see any topic about this. I wonder that you have supported it or not, or I have to create a custom control for my own? Thank you.
  • 44743
    posted

    It looks like this is not directly supported, but you can accomplish it with the UIElements in the color picker drop down. Here is the code you need (make sure to hook the BeforeToolDropdown and AfterToolCloseup events of the toolbars manager):

    private UltraControlBase hookedControl;

    private void HookControl( UltraControlBase control )
    {
     this.UnhookControl();

     if ( control == null )
      return;

     control.MouseEnterElement += new UIElementEventHandler( this.control_MouseEnterElement );
     control.MouseLeaveElement += new UIElementEventHandler( this.control_MouseLeaveElement );
     this.hookedControl = control;
    }

    private void UnhookControl()
    {
     if ( this.hookedControl == null )
      return;

     this.hookedControl.MouseEnterElement -= new UIElementEventHandler( this.control_MouseEnterElement );
     this.hookedControl.MouseLeaveElement -= new UIElementEventHandler( this.control_MouseLeaveElement );
     this.hookedControl = null;
    }

    private void ultraToolbarsManager1_BeforeToolDropdown( object sender, BeforeToolDropdownEventArgs e )
    {
     if ( e.Tool is PopupColorPickerTool )
      this.HookControl( e.Tool.Control as UltraControlBase );
    }

    private void ultraToolbarsManager1_AfterToolCloseup( object sender, ToolDropdownEventArgs e )
    {
     this.UnhookControl();
    }

    private void control_MouseEnterElement( object sender, UIElementEventArgs e )
    {
     CustomColorBoxHotTrackingButtonUIElement colorBox = e.Element as CustomColorBoxHotTrackingButtonUIElement;

     if ( colorBox != null )
     {
      CustomColor customColor = (CustomColor)colorBox.GetContext();
      Color color = customColor.Color;

      // The mouse has entered a color box, show the live preview with the color.
     }
    }

    private void control_MouseLeaveElement( object sender, UIElementEventArgs e )
    {
     if ( e.Element is CustomColorBoxHotTrackingButtonUIElement )
     {
      // The mouse has left the color box, clear the live preview
     }
    }

  • 120
    posted
    Please, give me some advices , I really need the answer.