5,276,156 members and growing! (19,921 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » Applications     Intermediate

Pocket Fuzzy Quotient Calculator

By Andy Weston

The Pocket Fuzzy Quotient Calculator is a .NET Compact Framework sample application that calculates your FQ based on your mood.
C#, Windows, .NET CF, .NET, CE .NET 4.0, CE .NET 4.1, CE .NET 4.2, WinCE, Mobile, VS, VS.NET2003, Dev

Posted: 23 Apr 2004
Updated: 23 Apr 2004
Views: 25,062
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
21 votes for this Article.
Popularity: 3.90 Rating: 2.95 out of 5
10 votes, 47.6%
1
2 votes, 9.5%
2
3 votes, 14.3%
3
4 votes, 19.0%
4
2 votes, 9.5%
5

Sample Image - FuzzyQuotient.gif

Introduction

Pocket Fuzzy Quotient Calculator is a .NET Compact Framework sample application that lets you enter your opinions on various topics throughout the day depending on your mood. It then calculates your overall FQ, or Fuzzy Quotient. This program was inspired by Bio-Rythms, Fortune Cookies and Horoscopes.

Along the way, the coding topics of interest include:

  • how to create an application for the PocketPC
  • using an XML dataset to configure and generate user interface controls
  • deriving a new control to display color gradients 

Using the code

This application was created by using the File > New Project > Smart Device Application within Visual Studio 2003. This gives us the main form and the main menu. The Fuzzy Quotient main display needs to show topic controls on it that scroll to include any number of topics. To accomplish this, a Panel-derived class called AutoScrollPanel was created and added to the main form. This class is basically 2 nested panels with a scroll bar. It goes something like this.

namespace FuzzyQuotient
{
    public class AutoScrollPanel : Panel
    {
        public Panel Contents
        {
            get { return contents; }
        }
        Panel contents;
        VScrollBar vScroll;

        public AutoScrollPanel()
        {
            // create a scroll bar

            this.vScroll = new VScrollBar();
            this.vScroll.Parent = this;
            this.vScroll.Visible = true;
            this.vScroll.Minimum = 0;
            this.vScroll.SmallChange = 20;
            this.vScroll.ValueChanged +=
                new EventHandler (this.scrollbar_ValueChanged);

            // create the contents panel that holds the controls to scroll

            this.contents = new Panel();
            this.contents.Parent = this;
            this.contents.Width =
                this.ClientSize.Width - this.vScroll.Size.Width;
        }
...

Next, the topic configuration data needed to be loaded from an XML file in order to create the topic controls that get added to the scrolling panel. The following schema was chosen for the configuration XML:

<?xml version="1.0" encoding="utf-8" ?> <Topics> <Topic> <Name>Mood</Name> <Values> <Value> <Score>1</Score> <Text>Sad</Text> </Value> <Value> <Score>10</Score> <Text>Happy</Text> </Value> </Values> </Topic> <Topic> <Name>Weather</Name> <Values> <Value> <Score>1</Score> <Text>Lousy</Text> </Value> <Value> <Score>10</Score> <Text>Really, Really Nice!</Text> </Value> </Values> </Topic> </Topics>

This XML is then read into a DataSet class. The "Topics" table is scanned and rows of controls are built based upon the data. The color ranges for each topic needed to be displayed as a gradient but unfortunately the Graphics class doesn't directly support gradient brushes on the compact framework. So, I decided to roll my own new GradientControl with a custom OnPaint message to handle that.

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;

namespace FuzzyQuotient
{
    public class GradientControl
    : Control     { public
    Color
        Start = Color.Blue; public Color
        End = Color.Red; private const
        int STEPS = 20; public GradientControl()

                {
               
        }

        protected override void OnPaint (PaintEventArgs e)
        {
            Pen blackPen = new Pen (System.Drawing.Color.Black);

            // step through each of the color components

            int step = Width / STEPS;
            float startR = (float) Start.R;
            float stepR = ((float) End.R - (float) Start.R) / (float) STEPS;
            float startG = (float) Start.G;
            float stepG = ((float) End.G - (float) Start.G) / (float) STEPS;
            float startB = (float) Start.B;
            float stepB = ((float) End.B - (float) Start.B) / (float) STEPS;
            
            // draw each color band one at a time

            for (int i = 0; i < Width; i += step)
            {
                e.Graphics.FillRectangle(new SolidBrush(
                    Color.FromArgb((int)startR, (int)startG, (int)startB)),
                    i, 0, step, Height);
                if ((stepR > 0 && (startR < End.R)) ||
                    (stepR < 0 && (startR > End.R)))
                    startR += stepR;
                if ((stepG > 0 && (startG < End.G)) ||
                    (stepG < 0 && (startG > End.G)))
                    startG += stepG;
                if ((stepB > 0 && (startB < End.B)) ||
                    (stepB < 0 && (startB > End.B)))
                    startB += stepB;
            }

            //draw the border

            e.Graphics.DrawRectangle (blackPen, 0, 0,
                this.ClientRectangle.Width - 1,
                this.ClientRectangle.Height - 1);
        }
    }
}

There you have it!

The FQ calculation button just takes the average score for now but you can see how it would be easy to take this farther and do some fun stuff.

Future Enhancements

  • add a Configuration dialog to setup the topics to track
  • save the score data to an XML dataset
  • track your scores by date
  • use real fuzzy logic calculations
  • sync the entered data with a desktop application
  • post the results to a web application
  • view scores enter by other users, group by: friends, ZIP code, state, country
  • draw a map of the US that shows the average score colors for each state, animate by each topic

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

About the Author

Andy Weston



Occupation: Web Developer
Location: United States United States

Other popular Mobile Development articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralVB translationmemberSprout31:56 3 Dec '04  
GeneralRe: VB translationmemberAndy Weston15:12 3 Dec '04  

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

PermaLink | Privacy | Terms of Use
Last Updated: 23 Apr 2004
Editor: Chris Maunder
Copyright 2004 by Andy Weston
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project