NumericPad Issue

Nov 26, 2009 at 8:49 AM
Edited Nov 26, 2009 at 8:52 AM

 

using Fluid.Classes;
using Fluid.Controls;
using Fluid.Drawing;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SmartDeviceProject8
{
	class ConversionPage : FluidPanel, ICommandContainer
	{
		private NumericPad		numPad;
		private FluidLabel		inputLabel;
		private FluidLabel		outputLabel;
		private FluidTextBox	inputValue;
		private FluidTextBox	outputValue;

		/// <summary>
		/// Class contructor
		/// </summary>
		/// <param name="x">x value</param>
		/// <param name="y">y value</param>
		/// <param name="w">width</param>
		/// <param name="h">height</param>
		public ConversionPage(int x, int y, int w, int h) : base(x, y, w, h) { }

		/// <summary>
		/// 
		/// </summary>
		protected override void InitControl()
		{
			base.InitControl();

			BackColor	= Color.White;
			Bounds		= new Rectangle(0, 0, Width, Height);
			Anchor		= AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;

			inputValue = AddTextLabel("Input value", 10, ref inputLabel, true, true);
			outputValue = AddTextLabel("Converted value", 50, ref outputLabel, true, false);

			numPad = new NumericPad();
			
			MakeButtonsGlowing();

			numPad.Bounds = new Rectangle(0, 150, Width, 200);

			numPad.EnableDoubleBuffer	= false;
			numPad.Buttons[15].Enabled	= false;

			numPad.Corners	= RoundedCorners.None;
			numPad.Anchor	= AnchorStyles.None;

			Controls.Add(numPad);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="title"></param>
		/// <param name="top"></param>
		/// <param name="label"></param>
		/// <param name="visible"></param>
		/// <param name="enable"></param>
		/// <returns></returns>
		FluidTextBox AddTextLabel(string title, int top, ref FluidLabel label, bool visible, bool enable)
		{
			label = new FluidLabel(title, 10, top + 5, Width - 20, 16);
			label.Anchor = AnchorStyles.Left | AnchorStyles.Top;
			label.Font = new Font(FontFamily.GenericSansSerif, 8f, FontStyle.Regular);
			label.ForeColor = Color.Black;
			label.Visible = visible;
			Controls.Add(label);

			FluidTextBox textbox = new FluidTextBox("", 10, top + 19, Width - 20, 24);
			textbox.Anchor = AnchorStyles.Left | AnchorStyles.Top;
			textbox.Visible = visible;
			textbox.Enabled = enable;
			textbox.CanShowInputPanel = false;
			Controls.Add(textbox);
			return textbox;
		}

		private void MakeButtonsGlowing()
		{
			FluidButton[] buttons = numPad.Buttons;
			foreach (FluidButton btn in buttons) btn.PressedBackColor = Color.DarkBlue;
			buttons[11].PressedBackColor = Color.Red;
			buttons[15].PressedBackColor = Color.Green;
		}
	}
}

 

And the implementation of ConversionPage:

 

using Fluid.Controls;
using Fluid.Classes;

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SmartDeviceProject8
{
	public partial class Form1 : Form
	{
		ConversionPage browse;

		public Form1()
		{
			InitializeComponent();

			browse = new ConversionPage(0, 0, host.Width, host.Height);
			browse.ShowMaximized(ShowTransition.None);
		}
	}
}

 

 

 

In the above code everything works ok, but the NumericPad item is being shown buggy ... only the first row ( 1 / 2 / 3 / clr) and the last one ( * / 0+ / #_ )

 

Aug 9, 2011 at 4:16 AM

esix4u,

Did you ever find a solution to this problem? I'm having the same issue (first and last rows).

Aug 9, 2011 at 5:16 AM

I have come up with a fix, or a workaround, depending on your perspective.

The problem is that the missing buttons are there, just in the wrong place. The following two functions should sort it out. Call it last thing, because setting the various properties of the numeric pad effects the positions of the controls:

        public static void FixNumericPad(ref NumericPad numPad)
        {
            AlignButtonWithAboveButton(numPad.Buttons[0], numPad.Buttons[4]); // 1
            AlignButtonWithAboveButton(numPad.Buttons[1], numPad.Buttons[5]); // 2
            AlignButtonWithAboveButton(numPad.Buttons[2], numPad.Buttons[6]); // 3
            AlignButtonWithAboveButton(numPad.Buttons[4], numPad.Buttons[8]); // 7
            AlignButtonWithAboveButton(numPad.Buttons[5], numPad.Buttons[9]); // 8
            AlignButtonWithAboveButton(numPad.Buttons[6], numPad.Buttons[10]); // 9

        }
        private static void AlignButtonWithAboveButton(FluidButton upperButton, FluidButton lowerButton)
        {
            //lowerButton.Bounds = new Rectangle(upperButton.Bounds.X, upperButton.Bounds.Y + upperButton.Bounds.Height,
            //    upperButton.Bounds.Width, upperButton.Bounds.Height);
            lowerButton.Bounds = new Rectangle(upperButton.Bounds.X, upperButton.Bounds.Y,
                upperButton.Bounds.Width, upperButton.Bounds.Height);

        }