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.
AppManager.Show (new Form1, "")
AppManager.Show (new Forms, this, 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.
public class Start
{
public Start() {}
[STAThread]
static void Main() {
AppManager.Show(new Home(), "");
Application.Run();
}
}
Expand your Form
with your own common interface IForm
.
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.
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.
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.
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.