Click here to Skip to main content
15,892,005 members
Articles / Programming Languages / C#
Article

Tiny WinForms Application Framework - Juju

Rate me:
Please Sign up or sign in to vote.
3.60/5 (5 votes)
23 Dec 20032 min read 50.3K   1.7K   32   7
Tiny WinForms Application Framework - Juju

Image 1

Introduction

Many times customer says 'we need Windows application which works like browser’. This article describes how to make WinForms Application which mimics a Browser. Because Tiny WinForms Application Framework is so long a name, I have called it JUJU.

What does the code do?

  • JUJU mimics MS Explorer - you can browse WinForms forward and backward
  • old Form sends arguments to the new Form
  • new Form inherits size and location properties
  • Forms are linked together with double linked list
  • Events are handled in separated class
  • easy to maintain

How to start

When you start to build a new Windows Application and it’s layout looks like Browser, include these files to our project and start to create the new Forms. You can jump from any form to another and the framework remembers how to go backwards or forwards. There is one main class that handles the behaviour of Browser. It is called AppManager (Application Manager). Every time when you create a new Form, and you want to create it to the same stack as previous form, you must create the new form via AppManager, example.

C#
AppManager.Show (new Form1, "")  //new stack, no arguments 
AppManager.Show (new Forms, this, arguments)  //same stack, with arguments   

Every Form has it’s own FormManager class, where you can hide all public events which are common to all Forms. FormManager takes care of usual Form events and it discuss with AppManager.

Main ideas, Juju

Main function is Start and it is the place where you initialize AppManager. AppManager glues all windows together with a Double Linked List, see code.

C#
public class Start   
{
  public Start() {}
  [STAThread]
    static void Main() { 
      AppManager.Show(new Home(), "");
      Application.Run();
  }
}

Expand your Form with your own common interface IForm.

C#
public class Form1 : System.Windows.Forms.Form, IForm{..}  

Add FormManager class to every Form which must have Browser like behaviour. FormManager class takes care of usual tasks which the Form must to do. It initialize Toolbars, Event Handler etc. After that you can concentrate real work, designing WinForms. Every common event is circulated via this class.

C#
publicForm1() { 
     InitializeComponent();                                
     FormManager frmManager = new FormManager( this);       
}                                                                 

Remember also to Implement all IForm functions.

When you want to create new window just call AppManager.Show(...). Every new form inherits properties from previous form (= location, layout). Old Form also send arguments to the new one so that it knows how to initialize data.

C#
AppManager.Show( new Form1(), this, argsOUT);

If the new Form is in the middle of stack when you call function AppManager.Show(..) it removes all the Forms from the right and after that it adds new Form to the end of stack. Previous form is hidden and new form is shown.

C#
publicstatic void Show(Form newForm, Form oldForm, string args) { 
  Node current = Activate(oldForm); 
  if (current.Right != null) Remove(current.Right.Value, true); 
    Node node = new Node(newForm, current, null); 
  current.Right = node; 
  nodes.Add(node); 
  InitForm(newForm, oldForm, args); 
  ShowHide(newForm, oldForm); 
  current = null; 
}                                                                 

Bugs and comments

If you have any ideas how to develop this idea don’t hesitate to contact me, dathava@jippii.fi. I would be pleased if someone can give me me ideas how to develop this idea further. Maybe there are better ways how to handle events. So if you invent any new features, let me know. Juju means a trick in Finnish.

What is needed?

Common Keyboard and Menu handlers.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Finland Finland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNice Article! Pin
soulprovidergr25-May-11 14:42
soulprovidergr25-May-11 14:42 
GeneralGenerator Pin
akorolev105-Jul-05 22:10
akorolev105-Jul-05 22:10 
GeneralNew Frames in Stack are going bigger and bigger Pin
DrFlow28-Apr-04 4:04
DrFlow28-Apr-04 4:04 
GeneralRe: New Frames in Stack are going bigger and bigger Pin
huuhaa9-May-04 7:10
huuhaa9-May-04 7:10 
GeneralRe: New Frames in Stack are going bigger and bigger Pin
DrFlow9-May-04 20:37
DrFlow9-May-04 20:37 
Thanks for your response,

I am not a big friend of XML stuff, but may be I will change my mind. Wink | ;-) I think it is great stuff and I can not understand that that sample got that less attention.


A little comment from my site:

This ImageList thing (ResourceHelper) to set the ToolBar Icons is very uncomfortable, may be there is another way to handle those. I am not a skilled Programmer and may be this is stupid, but it works fine for me.

public static ImageList LoadImageList ()
{
ImageList images = new ImageList();
images.ImageSize = imageSize;
string Path = (Application.StartupPath + "\\Resources\\Icons\\");

images.Images.Add(Image.FromFile(Path + "icon1.ICO"));
images.Images.Add(Image.FromFile(Path + "icon2.ICO"));
images.Images.Add(Image.FromFile(Path + "icon3.ICO"));
images.Images.Add(Image.FromFile(Path + "iconN.ICO"));

return images;
}


I could solve the sizing problem on myself. Do not ask me, what I did exactly, please. It guess it was just changing the bounds position. In this way it works.

public static void Show(Form newForm, Form oldForm, string args)
{
Node current = Activate(oldForm);
if (current.Right != null) Remove(current.Right.Value, true);
Node node = new Node(newForm, current, null);
current.Right = node;
nodes.Add(node);
InitForm(newForm, oldForm, args);
ShowHide(newForm, oldForm);
current = null;
}


// init form ? with arguments
private static void InitForm(Form newForm, string args)
{
IForm INew = (IForm)newForm;
Panel panelLeft = INew.Control("panelLeft") as Panel;
newForm.Text = "Window [" + Index (newForm) + "/" + Count(newForm) + "]";
INew.ArgsIN = args;
newForm.Location = XY;
}


// init form ?, inherit properties / old form
private static void InitForm(Form newForm, Form oldForm, string args) {
IForm INew = (IForm)newForm;
IForm IOld = (IForm)oldForm;
newForm.Bounds = oldForm.Bounds;
Panel panelLeftOld = IOld.Control("panelLeft") as Panel;
Panel panelLeftNew = INew.Control("panelLeft") as Panel;
panelLeftNew.BackColor = panelLeftOld.BackColor;
newForm.Text = "Window [" + Index (newForm) + "/" + Count(newForm) + "]";
newForm.BackColor = oldForm.BackColor;
INew.ArgsIN = args;
}




--

no sig
GeneralRe: New Frames in Stack are going bigger and bigger Pin
huuhaa10-May-04 2:35
huuhaa10-May-04 2:35 
GeneralThanks, it's interesting Pin
Aldamo27-Jan-04 23:29
Aldamo27-Jan-04 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.