Click here to Skip to main content
6,630,289 members and growing! (23,915 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » User Interface     Advanced License: The GNU General Public License (GPL)

Windows Mobile - Attractive UI Part-I

By Atanu Mandal

Windows Mobile - Attractive UI (Description about AlphaMobilecontrols)
C#, .NET CF, Mobile, Architect, Dev
Version:13 (See All)
Posted:17 Sep 2009
Views:5,350
Bookmarked:22 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
6 votes for this article.
Popularity: 3.70 Rating: 4.75 out of 5

1

2
1 vote, 16.7%
3

4
5 votes, 83.3%
5

Introduction

This article describes how to develop a mobile application with .NET CF having features like background transparency. There is one set of controls created by Rémy Baudet available at AlphaMobileControls. These controls offer background transparent images, image buttons and labels. I have added the following items to the library provided by alphamobilecontrols:

  • AlphaButton
  • AlphaListBox
  • Modified the AlphaImage control so that image can stretch itself as per size of the control

In Part I, I shall describe details about the existing AlphaMobileControls and then in the next part, we will discuss about building controls on top of AlphaMobileControls:

Using_AlphaButton.jpg

Background transparency of the controls

Background

Mobile thick client applications are getting more and more popular every day. When I started developing a client application, I did not have much knowledge about .NET Compact Framework. I found that CF class library controls are not sufficient for creating smart looking UIs. Then I tried a number of third party controls - most of them were either too heavy to use in handheld devices or they are very error prone (specifically memory leakage was the common problem of these third party controls). Then I came to know about AlphaMobileControls developed by Rémy Baudet. But, they did not have all the features that I wanted, i.e. a key navigable button control and a list control to display list of items.

How Alpha Mobile controls Work !!

AlphaControl has been derived from control base class and Alpha button derives from alpha control.

public class AlphaControl : Control
public class AlphaButton : AlphaControl

Alpha controls should be placed over an alpha container class - either alphaform or alphapanel. This container classes contain the main trick of transparency. It has a paint method which in turn fires the draw method of all containing alpha controls:

    /// <summary>
    /// Handles the Paint event, it is where the magic happens :-)
    /// </summary>
    public void OnPaint(PaintEventArgs e)
    {
        if (_backBuffer != null)
        {
            // We need a Graphics object on the buffer to get an HDC
            using (Graphics gxBuffer = Graphics.FromImage(_backBuffer))
            {
                // Since we nop'd OnPaintBackground, take care of it here
                gxBuffer.Clear(_control.BackColor);

                Region gxClipBounds = new Region(Rectangle.Ceiling(gxBuffer.ClipBounds));

                // Iterates the child control list in reverse order
                // to respect the Z-order
                for (int i = _control.Controls.Count - 1; i >= 0; i--)
                {
                    // Handle controls inheriting AlphaControl only
                    AlphaControl ctrl = _control.Controls[i] as AlphaControl;
                    if (ctrl == null)
                        continue;

                    // Something to draw?
                    Rectangle clipRect = 
			Rectangle.Intersect(e.ClipRectangle, ctrl.Bounds);
                    if (clipRect.IsEmpty)
                        continue;

                    // Clip to the control bounds
                    gxBuffer.Clip = new Region(clipRect);

                    // Perform the actual drawing
                    ctrl.DrawInternal(gxBuffer);
                }

                // Restore clip bounds
                gxBuffer.Clip = gxClipBounds;
            }

            // Put the final composed image on screen.
            e.Graphics.DrawImage
		(_backBuffer, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);
        }
        else
        {
            // This should never happen, should it?
            e.Graphics.Clear(_control.BackColor);
        }
    }
}

AlphaControl inherits from the Control class and hides itself.

/// <summary>
/// Default constructor.
/// </summary>
public AlphaControl()
{
    base.Visible = false;
}

It has a method drawinternal which is called from its parent container (either AlphaPanel or AlphaForm). This drawinteral method calls the draw method of the derived classes. The draw method paints/draws the control on the container using methods like drawstring, drawrectangle, drawline.

/// <summary>
/// Internal Draw method, called by the container.
/// Will call the actual Draw method if the control is visible.
/// </summary>
internal void DrawInternal(Graphics gx)
{
     if (_visible)
         Draw(gx);
}

/// <summary>
/// Must be overridden.
/// </summary>
public virtual void Draw(Graphics gx)
{
}

What'll Be There in Part II and Part III

I shall post further articles:

  • Part II will contain AlphaImage controls
  • Part III will contain AlphaButton, AlphaListBox and other controls. Once those articles are posted, I shall update this article with the links.

Points of Interest

AlphaMobile controls have been a very interesting piece of development with a lot of scope to extend the functionalities and control collections. Some possible enhancements can be empowering controls with designer support. This can be very useful while using Alpha Datagrid controls or other list controls.

History

  • 17th September, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPL)

About the Author

Atanu Mandal


Member
I am a software developer wroking at Kolkata India. I have three years of software development experience in ASP.NET, WPF, WCF, WF. I am also interested in MS SQL SERVER.
Occupation: Software Developer
Company: A CMMI Level 5 Company
Location: India India

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
  • Pocket 1945 - A C# .NET CF Shooter
    An article on Pocket PC game development
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
Generalaccess internet from emulator PinmemberPushpa8619:40 9 Nov '09  
GeneralI am waiting for the list box control too PinmemberMember 39057967:15 28 Oct '09  
GeneralRe: I am waiting for the list box control too PinmemberAtanu Mandal1:34 2 Nov '09  
GeneralStretch ImageButton Image. PinmemberMember 26612285:59 27 Oct '09  
GeneralGreat article! PinmemberRemy Baudet4:25 3 Oct '09  
GeneralGood Work PinmemberArindam Sinha8:49 19 Sep '09  
Generalgreat articale PinmemberAsit Sen7:27 17 Sep '09  
GeneralRe: great articale PinmemberAtanu Mandal7:31 17 Sep '09  
GeneralRe: great articale PinmemberMember 39057967:11 28 Oct '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Sep 2009
Editor: Deeksha Shenoy
Copyright 2009 by Atanu Mandal
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project