Changing InfoPath control background color via IOLECommand - InfoPath Dev
in

InfoPath Dev

Changing InfoPath control background color via IOLECommand

Last post 10-15-2007 12:50 PM by davehacker. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 09-17-2007 07:26 AM

    Changing InfoPath control background color via IOLECommand

    I have an InfoPath control hosted in Winforms app. My problem is that I need to change the background color to match the 'skin' of the hosting form. To my delight, there was this Microsoft sample (http://www.microsoft.com/downloads/details.aspx?FamilyId=F65C20DF-ADC2-446A-8FBC-D7C5ED5DD83F&displaylang=en) that I've downloaded that seem to include code to do just that. Unfortunately, (you guessed it right) it doesn't work. Instead, I'm getting a DRAGDROP_E_NOTREGISTERED or DRAGDROP_E_ALREADYREGISTERED exception depending on which form or control (e.g. NotifyHost call @ XDocument.OnLoad) event I've issued the command to set the BackgroundColor property.

    Here's the code snippet:              

    public Color BackgroundColor
      {
       set
       {
        UInt32 vaIn;
        try
        {
         vaIn = Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(value));
        }
        catch (Exception ex)
        {
         throw new HostedException("An error occurred while attempting to set the background color", ex);
        }
        ChkResult(ExecuteCommand(FormControlCommandIds.CommandIds.SetSelectedTextBackgroundColor, vaIn));
       }
      }

    public object ExecuteCommand(FormControlCommandIds.CommandIds commandId, object vaIn)
      {
       //remember the last command executed
       lastCommandExecuted = commandId.ToString();

       //indicates to Exec call to do the default option
       const int EXECUTE_OPTION_DO_DEFAULT = 0;

       //holds the return result
       object vaOut = null;

       // Get the commandTarget from the control
       IOleCommandTarget commandTarget = _infoPathControl.GetOcx() as IOleCommandTarget;

       try
       {
        commandTarget.Exec(ref FormControlCommandIds.CommandGroup, Convert.ToUInt16(commandId,CultureInfo.CurrentCulture),
         EXECUTE_OPTION_DO_DEFAULT, ref vaIn, ref vaOut);
        return vaOut;
       }
       catch (Exception ex)
       {
        throw new HostedException("An error occurred while executing command " + commandId.ToString(), ex);
       }
      }

    What puzzles me is that the sample application contains lots of formatting options that are disabled by default. I have no idea how to enable them and there's zero documentation on how it is suppose to work.

    Any help would be greatly appreciated.

    Thanks,

    Menard

  • 10-11-2007 08:13 AM In reply to

    Re: Changing InfoPath control background color via IOLECommand

    Sorry, not much help here.  I have the exact same problem.  I tried both the C# and C++ examples and all the form design\customization options are disabled.  With the C++ project (HostIP), I get the following error:

    ---------------------------
    Command cannot be performed at this time, it is either not supported or disabled
    ---------------------------
    OK  
    ---------------------------

     This seems to be the same behavior that you get when you open a form in InfoPath.  You can't edit the form.  However, from within InfoPath all I need to do is click the 'Design this Form' button and I can then make changes.

     Does anybody know how to embed an EDITABLE InfoPath control from within a Windows Application?  Thanks in advance for any tips!  I'll post if I find anything out...

  • 10-15-2007 12:50 PM In reply to

    Re: Changing InfoPath control background color via IOLECommand

    I just received word (although not 'official' word), that hosting the infopath controls in design mode is not supported.

     This confuses me because the sample code referenced earlier looks like it is setup to design (edit) the form.  Oh well.

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.