1 Reply Latest reply: Apr 17, 2008 7:47 PM by 619485 RSS

    Can I use two or more .NET User Controls in the same gadget?

    634241
      I know this might go against the idea of the gadgets but we're trying to mimic (in a prototype for now) one web app we run here and I need at least two separate (forms??) user controls to work with.

      I have the first user control working and I can see it calling the second user control however the second user control never gets visible.

      Is that at least possible?

      thanks for your replies.

      GM
        • 1. Re: Can I use two or more .NET User Controls in the same gadget?
          619485
          You can place as many user controls on a gadget as you like. It's merely a matter of how much screen size you take up overall. The gadgets are resizable. So, you can use the entire displayable area, if that's what you need.

          The gadgets are WinForm-based UserControl objects themselves. Any WinForm based-controls can be used, including browser containers (WebBrowser control) for web / HTML content.

          I'm not sure how you are placing the user controls on the gadget panel / form. So, it's difficult to say what the problem is.

          One way to switch the UI display is to place a TabControl on the gadget and then place the individual user controls each into a separate tab of the TabControl. You can programmatically switch which tab is visible.

          Another more straight forward route would be to Add & Remove your UserControls to & from the gadget's "Controls" collection, programmatically switching which user control is displayed within the gadget's UI area. By this route you can remove one control and add the other control. Just keep a live reference of both controls to prevent them from going out of scope and being garbage collected, when removed from the Controls collection.

          Again, without discussing or seeing your code directly, it's difficult to determine the exact problem you are having. One way to switch UserControls in the gadget is provided below in C#. The VB code would be about the same. In this case two Controls are both programmatically placed into the gadget UI and switched into and out of visibility by adding one to & removing the other from the gadget's "Controls" collection.

          public sealed partial class Gadget1Gadget : BaseGadget
          {
          private System.Windows.Forms.WebBrowser webBrowser1 = null;
          private System.Windows.Forms.WebBrowser webBrowser2 = null;

          ...

          public override void Init()
          {
          //
          // CREATE THE FIRST USER CONTROL & DISPLAY IT webBrowser1
          //
          this.webBrowser1 = new System.Windows.Forms.WebBrowser();
          this.webBrowser1.Location = new System.Drawing.Point(15, 22);
          this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
          this.webBrowser1.Name = "webBrowser1";
          this.webBrowser1.Size = new System.Drawing.Size(389, 192);
          this.webBrowser1.TabIndex = 0;

          /// ADD TO THE GADGET'S UI CONTROLS COLLECTION
          this.Controls.Add(this.webBrowser1);

          this.webBrowser1.Navigate("http://www.oracle.com");

          /// CREATE USER CONTROL 2 (webBrowser2), FOR LATER USE
          this.webBrowser2 = new System.Windows.Forms.WebBrowser();

          }

          ...

          private void button1_Click(object sender, System.EventArgs e)
          {
          /// REMOVE THE FIRST USER CONTROL FROM THE UI
          this.Controls.Remove(this.webBrowser1);

          /// ADD THE SECOND USER CONTROL TO THE UI
          this.Controls.Add(this.webBrowser2);

          this.webBrowser2.Location = new System.Drawing.Point(16, 13);
          this.webBrowser2.MinimumSize = new System.Drawing.Size(20, 20);
          this.webBrowser2.Name = "webBrowser2";
          this.webBrowser2.Size = new System.Drawing.Size(250, 135);
          webBrowser2.Navigate("http://www.oracle.com/otn");

          }

          }