By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

Sharing Code between Window Forms and Windows Mobile

P: n/a
I'm embarking on a project that will have both a desktop application and a
Pocket PC application. It seems logical to have as much code as possible
sitting in a shared project, which would be referenced and utilized by both
the Windows Forms application and the Mobile Device application.

Are there any "gotchas" (ie. warnings) that anyone knows about in following
this approach?

Robert W.
Vancouver, BC

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
My suggestion would be to only share code that is non-UI related and if you
really want to share assemblies make sure that the code conforms to the
lowest common denominator by compiling against the Compact Framework.

--
Tim Wilson
..Net Compact Framework MVP

"Robert W." <Ro*****@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
I'm embarking on a project that will have both a desktop application and a
Pocket PC application. It seems logical to have as much code as possible
sitting in a shared project, which would be referenced and utilized by both the Windows Forms application and the Mobile Device application.

Are there any "gotchas" (ie. warnings) that anyone knows about in following this approach?

Robert W.
Vancouver, BC

Nov 17 '05 #2

P: n/a
Hi Tim,

Thanks for this. Have you personally run into problems sharing code as I
described?

I also immediately thought about avoiding sharing code that involves
controls. But today I noticed that both a Windows.Forms form and a Mobile
Device form each have the identical 'using' statement at the top:

using System.Windows.Forms;

It'll be interesting to see if a DataLibrary with the above 'using'
statement would support code as follows for both platforms:

private void GetAllControls(Control.ControlCollection parent, ArrayList
container)
{
foreach(Control c in parent)
{
if(c.HasChildren)
{
GetAllControls(c.Controls,container);
}
container.Add(c);
}
}
I definitely need to do some tests, but added my post on here to tap into
the experiences of others who have tried this.

Robert


"Tim Wilson" wrote:
My suggestion would be to only share code that is non-UI related and if you
really want to share assemblies make sure that the code conforms to the
lowest common denominator by compiling against the Compact Framework.

--
Tim Wilson
..Net Compact Framework MVP

"Robert W." <Ro*****@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
I'm embarking on a project that will have both a desktop application and a
Pocket PC application. It seems logical to have as much code as possible
sitting in a shared project, which would be referenced and utilized by

both
the Windows Forms application and the Mobile Device application.

Are there any "gotchas" (ie. warnings) that anyone knows about in

following
this approach?

Robert W.
Vancouver, BC


Nov 17 '05 #3

P: n/a
> Have you personally run into problems sharing code
as I described? No. But then again I haven't really had a whole lot of need to do this.

The CF (Compact Framework) team modeled the namespaces, classes, etc. to
mimic the FF (Full Framework). So you'll notice lots of similarities between
the FF and CF. This was absolutely by design. This allows devs to leverage
their knowledge between the two frameworks. But keep in mind that the CF
emphasizes the word "compact". So the CF is a subset of the FF. If you look
at the documentation you'll notice the statement "supported by the .NET
Compact Framework" on certain members (now I must warn you that the docs are
not 100% accurate, particularly with the event members). This gives you an
idea of what you can and cannot use between CF and FF. So in your code
example, the "HasChildren" property would not compile against the CF since
it's not supported. But you could always just check the Count of the
Controls collection. So there are usually work arounds. You'll just need to
find the combination that works for both the CF and FF and then compile that
in a project against the CF.

The reason that I implied that it's best not to share UI related code is
mostly for two reasons:
(1) The form factor of a device (like a Pocket PC or Smartphone) is
drastically different from a typical desktop computer display. So the UI is
pretty much a rewrite anyways.
(2) Through the designer, the generated resx files for Forms are not
compatible between FF and CF projects.

So there's nothing wrong with having utility methods to perform tasks on
controls, but you'll want to ensure that you have different projects, one
for the FF and one for the CF, so that you can more easily define proper
UI's.

--
Tim Wilson
..Net Compact Framework MVP

"Robert W." <Ro*****@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com... Hi Tim,

Thanks for this. Have you personally run into problems sharing code as I
described?

I also immediately thought about avoiding sharing code that involves
controls. But today I noticed that both a Windows.Forms form and a Mobile
Device form each have the identical 'using' statement at the top:

using System.Windows.Forms;

It'll be interesting to see if a DataLibrary with the above 'using'
statement would support code as follows for both platforms:

private void GetAllControls(Control.ControlCollection parent, ArrayList
container)
{
foreach(Control c in parent)
{
if(c.HasChildren)
{
GetAllControls(c.Controls,container);
}
container.Add(c);
}
}
I definitely need to do some tests, but added my post on here to tap into
the experiences of others who have tried this.

Robert


"Tim Wilson" wrote:
My suggestion would be to only share code that is non-UI related and if you really want to share assemblies make sure that the code conforms to the
lowest common denominator by compiling against the Compact Framework.

--
Tim Wilson
..Net Compact Framework MVP

"Robert W." <Ro*****@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
I'm embarking on a project that will have both a desktop application and a Pocket PC application. It seems logical to have as much code as possible sitting in a shared project, which would be referenced and utilized by

both
the Windows Forms application and the Mobile Device application.

Are there any "gotchas" (ie. warnings) that anyone knows about in

following
this approach?

Robert W.
Vancouver, BC


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.