• (2 Pages)
  • +
  • 1
  • 2

Building an application - POS/Cash Register - Part one Custom keyboard and inheritence

#16 tlhIn`toq  Icon User is online

  • WillMyCodeWork = !FailedWhenYouTriedIt;
  • member icon

Reputation: 3277
  • View blog
  • Posts: 6,867
  • Joined: 02-June 10

Posted 02 February 2012 - 12:15 PM

CandymanJP said:

hey, i'm working on the POS register application that you designed. i can't get the buttons to display the number that was pressed. might have something to do with the part where i have to make button one send a 1 and so on.. right where you said.. "I trust you are smart enough to have btn1 send a '1', btn2' send a '2' and so on. For now, fill in code for buttons...


Rather than make a public comment on someone's profile page for something like this, a private message works a lot better so there can be two way communication.

UPDATE: Being a new user you can't yet use the PM system. Sorry. So about the only thing I can do is post your question and answer here. Hopefully that will clear up issues for anyone else that goggle's across this thread as well.


Ok, so you're having trouble getting a button to send a character. Maybe you missed the code earlier in the article where we have a method to raise an event.
namespace Keypad.cs
{
    public partial class GenericKeypad : UserControl
    {
        public GenericKeypad()
        {
            InitializeComponent();
        }

       #region Events
        public event KeyPressEventHandler ButtonPressed;
        #endregion Events

        #region Methods
        public void RaiseButtonPressed(char WhatToSend)
        {
            KeyPressEventHandler handler = ButtonPressed;
            if (handler != null)
            {
                handler(this, new KeyPressEventArgs(WhatToSend));
            }
        }
        #endregion Methods
    }




So when someone clicks the '1' button, you call RaiseButtonPressed with the char '1'. When someone clicks the '2' button, you call RaiseButtonPressed with the char '2' ... and so on.
Was This Post Helpful? 0
  • +
  • -

#17 Utael  Icon User is online

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 12-December 11

Posted 18 February 2012 - 05:36 PM

I Keep getting this error.

"Keypad\GenericKeypad.cs(16,13): error CS0103: The name 'InitializeComponent' does not exist in the current context"

What am I doing wrong?


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

namespace Keypad
{
    public partial class GenericKeypad : UserControl
    {
        public GenericKeypad()
        {
            InitializeComponent();
        }
        #region Events
        public event KeyPressEventHandler ButtonPressed;
        #endregion Events

        #region Methods
        public void RaiseButtonPressed(char WhatToSend)
        {
            KeyPressEventHandler handler = ButtonPressed;
            if (handler != null)
            {
                handler(this, new KeyPressEventArgs(WhatToSend));
            }
        }
        #endregion Methods
    }
}


This post has been edited by Utael: 18 February 2012 - 05:37 PM

Was This Post Helpful? 0
  • +
  • -

#18 tlhIn`toq  Icon User is online

  • WillMyCodeWork = !FailedWhenYouTriedIt;
  • member icon

Reputation: 3277
  • View blog
  • Posts: 6,867
  • Joined: 02-June 10

Posted 18 February 2012 - 05:49 PM

Did you by chance choose: Add | Class instead of Add | UserControl

Attached Image


Your GenericKeypad should look like this in Solution Explorer. Double check that the icon looks like this and it has a designer.cs file.

Attached Image


InitializeComponet(); is found in the designer.cs file. Do you *have* a designer.cs file? Does it have this method in it?

Attached Image

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#19 tlhIn`toq  Icon User is online

  • WillMyCodeWork = !FailedWhenYouTriedIt;
  • member icon

Reputation: 3277
  • View blog
  • Posts: 6,867
  • Joined: 02-June 10

Posted 18 February 2012 - 06:01 PM

If nothing else, you can try make a new UserControl again, just like in the first screenshot above. Visual Studio will make the designer file automatically along with the constructor in the code file pre-filled with the call to InitializeComponents();

All that should be automatic and not require any typing on your part.
Was This Post Helpful? 0
  • +
  • -

#20 Utael  Icon User is online

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 12-December 11

Posted 19 February 2012 - 06:05 PM

Some how it fixed itself, after the third time of completely starting fresh.
Was This Post Helpful? 0
  • +
  • -

#21 Utael  Icon User is online

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 12-December 11

Posted 19 February 2012 - 06:37 PM

Warning 1 The type 'Keypad.cs.RegisterKeypad' in 'WindowsFormsApplication1\RegisterKeypad.cs' conflicts with the imported type 'Keypad.cs.RegisterKeypad' in 'WindowsFormsApplication1\Keypad.cs\bin\Debug\Keypad.cs.dll'. Using the type defined in 'WindowsFormsApplication1\RegisterKeypad.cs'. \WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs 31 50 Demo POS
 private void InitializeComponent()
        {
            this.registerKeypad1 = new Keypad.cs.RegisterKeypad();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // registerKeypad1
            // 



Error 2 'WindowsFormsApplication1.Form1' does not contain a definition for 'registerKeypad1_Load' and no extension method 'registerKeypad1_Load' accepting a first argument of type 'WindowsFormsApplication1.Form1' could be found (are you missing a using directive or an assembly reference?) \WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs 42 71 Demo POS


            this.registerKeypad1.Location = new System.Drawing.Point(0, 59);
            this.registerKeypad1.Name = "registerKeypad1";
            this.registerKeypad1.Size = new System.Drawing.Size(283, 309);
            this.registerKeypad1.TabIndex = 0;
            this.registerKeypad1.ButtonPressed += new System.Windows.Forms.KeyPressEventHandler(this.registerKeypad1_ButtonPressed);
            this.registerKeypad1.Load += new System.EventHandler(this.registerKeypad1_Load);




Warning 3 The type 'Keypad.cs.RegisterKeypad' in '\WindowsFormsApplication1\WindowsFormsApplication1\RegisterKeypad.cs' conflicts with the imported type 'Keypad.cs.RegisterKeypad' in '\WindowsFormsApplication1\Keypad.cs\bin\Debug\Keypad.cs.dll'. Using the type defined in '\WindowsFormsApplication1\WindowsFormsApplication1\RegisterKeypad.cs'. \WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs 67 27 Demo POS


        private Keypad.cs.RegisterKeypad registerKeypad1;
        private System.Windows.Forms.TextBox textBox1;




Using Visual Studio Ultimate 2010...
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2