Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Composite UI Application Block issues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joachim - 22 Nov 2006 13:50 GMT
I'm trying to figure out how to make a SmartPart visible on my screen through
a SmartPartPlaceHolder. I have the following code (I don't have so much
understanding of CAB yet so there might be a few things wrong here and there
- I hope you can help and correct me):

//------ CABTest2 project -------------

//Program.cs
using System;

namespace CABTest2
{
   static class Program
   {
       [STAThread]
       static void Main()
       {
           new MainShell().Run();
       }
   }
}

//ProfileCatalog.xml
<?xml version="1.0" encoding="utf-8" ?>
<SolutionProfile xmlns="http://schemas.microsoft.com/pag/cab-profile" >
 <Modules>
   <ModuleInfo AssemblyFile="Module1.dll"/>
 </Modules>
</SolutionProfile>

//MainShell.cs
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.WinForms;

namespace CABTest2
{
   class MainShell : FormShellApplication<WorkItem, MainForm>
   {
       protected override void AfterShellCreated()
       {
           base.AfterShellCreated();
           
           RootWorkItem.UIExtensionSites.RegisterSite(
               "MainMenu",
               Shell.MainMenuStrip);
           
           ToolStripMenuItem l_mi = new ToolStripMenuItem("File");
           RootWorkItem.UIExtensionSites["MainMenu"].Add(l_mi);
       }
   }
}

//MainForm.cs
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI;

namespace CABTest2
{
   public partial class MainForm : Form
   {
       WorkItem m_root;
       
       [ServiceDependency]
       public WorkItem RootWorkItem
       {
           set
           {
               m_root = value;
           }
       }
       
       public MainForm()
       {
           InitializeComponent();
       }
   }
}

//MainForm.Designer.cs
namespace CABTest2
{
   partial class MainForm
   {
       /// <summary>
       /// Required designer variable.
       /// </summary>
       private System.ComponentModel.IContainer components = null;

       /// <summary>
       /// Clean up any resources being used.
       /// </summary>
       /// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
       protected override void Dispose(bool disposing)
       {
           if (disposing && (components != null))
           {
               components.Dispose();
           }
           base.Dispose(disposing);
       }

       #region Windows Form Designer generated code

       /// <summary>
       /// Required method for Designer support - do not modify
       /// the contents of this method with the code editor.
       /// </summary>
       private void InitializeComponent()
       {
           this.menuStrip1 = new System.Windows.Forms.MenuStrip();
           this.smartPartPlaceHolder1 = new
Microsoft.Practices.CompositeUI.WinForms.SmartPartPlaceholder();
           this.SuspendLayout();
           //
           // menuStrip1
           //
           this.menuStrip1.Location = new System.Drawing.Point(0, 0);
           this.menuStrip1.Name = "menuStrip1";
           this.menuStrip1.Size = new System.Drawing.Size(292, 24);
           this.menuStrip1.TabIndex = 0;
           this.menuStrip1.Text = "menuStrip1";
           //
           // smartPartPlaceHolder1
           //
           this.smartPartPlaceHolder1.BackColor =
System.Drawing.Color.Transparent;
           this.smartPartPlaceHolder1.Location = new
System.Drawing.Point(12, 126);
           this.smartPartPlaceHolder1.Name = "smartPartPlaceHolder1";
           this.smartPartPlaceHolder1.Size = new System.Drawing.Size(219,
66);
           this.smartPartPlaceHolder1.SmartPartName = "TestSmartPart";
           this.smartPartPlaceHolder1.TabIndex = 1;
           this.smartPartPlaceHolder1.Text = "TestSmartPart";
           //
           // MainForm
           //
           this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
           this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
           this.ClientSize = new System.Drawing.Size(292, 266);
           this.Controls.Add(this.smartPartPlaceHolder1);
           this.Controls.Add(this.menuStrip1);
           this.MainMenuStrip = this.menuStrip1;
           this.Name = "MainForm";
           this.Text = "Form1";
           this.ResumeLayout(false);
           this.PerformLayout();

       }

       #endregion

       private System.Windows.Forms.MenuStrip menuStrip1;
       private
Microsoft.Practices.CompositeUI.WinForms.SmartPartPlaceholder
smartPartPlaceHolder1;
   }
}

//-------------- Module1 project -----------------

//Module1Init.cs
using Microsoft.Practices.CompositeUI;

namespace Module1
{
   public class Module1Init : ModuleInit
   {
       WorkItem m_root;
       
       [ServiceDependency]
       public WorkItem RootWorkItem
       {
           set
           {
               m_root = value;
           }
       }
       
       public override void AddServices()
       {
           base.AddServices();
           
           //Add services programmatically here...
       }

       public override void Load()
       {
           base.Load();
           
           //Display the user-interface here or perform startup custom
logic...

           Module1WorkItem l_wi = m_root.WorkItems.AddNew<Module1WorkItem>();
           l_wi.Run();
       }
   }
}

//Module1WorkItem.cs
using Microsoft.Practices.CompositeUI;
using Module1;

namespace Module1
{
   public class Module1WorkItem : WorkItem
   {
       protected override void OnRunStarted()
       {
           base.OnRunStarted();

           MainUserControl csp =
SmartParts.AddNew<MainUserControl>("TestSmartPart");

           //MainUserControl l_uc = SmartParts.AddNew<MainUserControl>();
           //Workspaces["MyMainWorkspace"].Show(l_uc);
       }
   }
}

//MainUserControl.cs
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI.SmartParts;

namespace Module1
{
   [SmartPart]
   public partial class MainUserControl : UserControl
   {
       public MainUserControl()
       {
           InitializeComponent();
       }
   }
}

NOTE that I also have set the SmartPartName
Joachim - 22 Nov 2006 15:17 GMT
It works perfectly fine if I use the workspace approach, but I'm really
having problems getting the SmartPartPlaceHolder to show anything.
Forrest - 23 Nov 2006 08:37 GMT
> I'm trying to figure out how to make a SmartPart visible on my screen
> through
[quoted text clipped - 11 lines]
> {
>    static class Program
...
...
...

Please try this link

http://msdn.microsoft.com//msdnmag/issues/06/09/SmartClients/default.aspx

Sorry, but your code is terible.

Regards
Forrest
Joachim - 24 Nov 2006 06:28 GMT
> > I'm trying to figure out how to make a SmartPart visible on my screen
> > through
[quoted text clipped - 18 lines]
>
> http://msdn.microsoft.com//msdnmag/issues/06/09/SmartClients/default.aspx

Not much that helped me there, except for

"Views can be displayed by using SmartPartPlaceHolder classes or through
what CAB calls a workspace. These are simply layout containers used to
display your views in a given arrangement. If you have ever worked with the
Java abstract windows toolkit (AWT), you should be familiar with this
concept."

> Sorry, but your code is terible.

Thanks, that was encouraging and informative.

> Regards
> Forrest

Joachim

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.