Layout Manager and Compact Framework

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

I've just "converted" from Java and would like to know how
to implement some sort of dynamic GUI layout in the
Compact Framework, one that resizes and add components
("controls") on the fly.
Anchoring is not available in CF, the examples Microsoft
give for dynamic layouts -
http://samples.gotdotnet.com/quickstart/aspplus/default.asp
x?url=%2fquickstart%2fwinforms%2fdoc%
2fWinFormsFormLayout.aspx and
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dndotnet/html/custlaywinforms.asp
and generic examples of how to implement a layout manager
http://www.csharphelp.com/archives/archive7.html only
apply to the full framework - (again will not work in CF).

I'm beginning to get annoyed at having just paid $1000 for
Visual Studio I find it can't do some of the most *basic*
things that Java is capable of!
 
CompactFramework doesn't support any automatic layouts simply because of
size constraints. Most GUI's on portable devices aren't dynamic because
constraints on memory and real-estate, howerver, it is possible to create a
dynamic layout system if you want.

Thinking about how normal Windows Forms works, we know that when a new
control is added, the layout manager will do something with the control.
Now, we can create a helper class to expose a few events for our dynamic
Form, and then when a new Control is added/removed our Form can do whatever
it needs to do. If you are really creative, your layout manager would attach
itself to these events and perform necessary work for the Form....

This should get you started thinking in the right direction:

public delegate void DynamicControlEventHandler(object sender,
System.Windows.Forms.Control control);

public class DynamicControlCollection :
System.Windows.Forms.Control.ControlCollection

{

public event DynamicControlEventHandler ControlAdded;

public event DynamicControlEventHandler ControlRemoved;

protected virtual void OnControlAdded(Control c)

{

if(ControlAdded != null)

ControlAdded(this, c);

}

protected virtual void OnControlRemoved(Control c)

{

if(ControlRemoved != null)

ControlRemoved(this, c);

}

public override void Add(Control value)

{

base.Add (value);

OnControlAdded(value);

}

public override void Remove(Control value)

{

base.Remove (value);

OnControlRemoved(value);

}

}

public class Form1 : System.Windows.Forms.Form

{

private DynamicControlCollection controls = new
DynamicControlCollection();

public new DynamicControlCollection Controls

{

get

{

return controls;

}

}

}
 
My point being I should be "upgrading" to C#, if J2ME can
support it why doesn't the compact framework? I'm even
having to write a properties file loader to load
application configuration settings because the app config
(I forget the class name) class is available under the
full frameowrk but not under CF. I'm feeling overall
disappointed by the upgrade experience :/

Thanks for the suggestion btw, I'll try that and the above
and hopefully not hit any more shortcomings.
 
Remember that it's not Java that supports that, it's the windowing library
that Java provides. No doubt when .NET CF has been out for five years,
there will be a similar depth to the libraries, but right now, we're at less
than a year. What is the reason that you need dynamic layout? If you are
targeting Pocket PC devices, they are all the same screen size, so a simple,
static layout is actually a better solution (you don't have to spend the
memory and processor to do dynamic layout to achieve what would always be
the same answer). If you are targeting multiple, specific devices with
different screen sizes, you have two choices: define specific static layouts
for each device and choose the right one at run-time, or write your own
layout manager.

Paul T.
For me, choosing the right layout manager and getting the controls added
properly was always the most annoying part of programming in Java. I really
wished for a normal resource editor!
 
The cross platform functionality is key feature of Java
and I thought to an extent .NET, not supporting a dynamic
layout in its early stages IMHO seems to be a glaring
omission. I need such a layout to support a form whose
component change on each start dependent upon the XML file
it is parsing, the file can change on a weekly basis.
In addition on occasion the CF build may be needed on a
full laptop computer (its required in the field) and I
don't want to write two sets of code.

Ben
 
Thinking "out of the box" I'll bypass the problem APIs
altogether with a better solution. I'll write a simple web
server specfically for serving pages to Pocket IE, leaving
the browser to layout the UI.

Ben
 
Remember that "Java" and "cross-platform" have *nothing* to do with layouts.
In this application, it definitely looks like you would benefit from
automatic relayout, but I'm not convinced that this is the case in the
majority of applications (MS apparently wasn't convinced, either). If you
are changing the XML file every week, you might also incorporate the layout
information in there to work around this deficiency, or, as you noted, use a
completely different UI...

Paul T.
 
Back
Top