Laden...

Problem mit Bildschirmtastatur

Erstellt von Simon Heinzmann vor 16 Jahren Letzter Beitrag vor 16 Jahren 1.414 Views
Simon Heinzmann Themenstarter:in
43 Beiträge seit 2008
vor 16 Jahren
Problem mit Bildschirmtastatur

Hi,
ich komme einfach nich weiter, weis auch irgendwie nicht wo der Fehler liegen könnte.

Mein Ziel ist es eine Bildschirmtastatur auf einem Touchscreen. Ich hab schon einen Super Codeschnipsel gefunden den ich einfach nachgebaut hab. http://www.codeproject.com/KB/miscctrl/touchscreenkeyboard.aspx

Problem: Die Mauskoordinaten werden nicht an das Benutzersteuerelement übergeben, es passiert einfach gar nix, der Debugger läuft durch.

Form: FormBrowsersteuerung (Richtextfeld und Benutzersteuerelement)

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

namespace WindowsFormsApplication1
{
    public partial class FormBrowserSteuerung : Form
    {
        public FormBrowserSteuerung()
        {
            InitializeComponent();
        }

        private void userControlTS_UserKeyPressed (object sender, KeyboardEventArgs e)
        {
            richTextBox1.Focus();
            SendKeys.Send(e.KeyboardKeyPressed);
        }


    }

}

Benutzersteuerelement: UserControlTS

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

namespace WindowsFormsApplication1
{
    public partial class UserControlTS : UserControl
    {
        public UserControlTS()
        {
            InitializeComponent();
        }

        //Variable die speichert ob Shift gedrückt wurde oder nicht
        private Boolean shiftindicator = false;
        
        //String (Taste die gedrückt wurde)
        private string pvtKeyboardKeyPressed = "";
        
        [Category("Mouse"), Description("Return value of mouseclicked key")]
        public event KeyboardDelegate UserKeyPressed;
        protected virtual void OnUserKeyPressed(KeyboardEventArgs e)
        {
            if (UserKeyPressed != null)
                UserKeyPressed(this, e);
        }

        //Funktion (Wenn auf Picture Box geklickt wird)
        private void pictureBoxKeyboard_MouseClick(object sender, MouseEventArgs e)
        {
            // Koordinaten der Maus
            Single xpos = e.X;
            Single ypos = e.Y;

            // Handleaufruf zur Abfrage welche Taste geklickt wurde
            pvtKeyboardKeyPressed = HandleTheMouseClick(xpos, ypos);

            KeyboardEventArgs dea = new KeyboardEventArgs(pvtKeyboardKeyPressed);
            OnUserKeyPressed(dea);
        }

        // Handle zur unterschiedlichen Darstellung der Shift-Taste
        private void HandleShiftClick()
        {
            if (shiftindicator)
            {
                shiftindicator = false;
                pictureBoxShiftDown.Visible = false;
            }
            else
            {
                shiftindicator = true;
                pictureBoxShiftDown.Visible = true;
            }

        }        
        // Handle der den MouseClick abfrägt
        private string HandleTheMouseClick(Single x, Single y)
        {
            string Keypressed = null;
            // Abfrage ob Mouse im gültigem Bereich x=[1;480] y =[1;202]
            // Übergabe von Keypressed an HandlesShiftaableKey -> Prüfung Gross/Kleinschreibung
            if (x >= 1 && x < 480 && y >= 1 && y < 202)
            {
                //Erste Zeile
                if (y <= 53)
                {
                    if (x >= 1 && x < 48) Keypressed = HandleShiftableKey("q");
                    else Keypressed = null;
                }
                //Zweite Zeile
                //Dritte Zeile
                else if (y >= 106 && y < 158)
                {
                    if (x >= 1 && x < 129) HandleShiftClick();
                    else Keypressed = null;
                }
                else
                {
                    Keypressed = null;
                }
            }

            //Prüfung ob gültige Taste gedrückt wurde:
            //wenn ja Return "Keypressed" und Prüfung ob Shifttaste zurückgesetzt werden muss
            //wenn nein Return "null"
            if (Keypressed != null)
            {
                if (shiftindicator) HandleShiftClick();
                return Keypressed;
            }
            else
            {
                return null;
            }
        }



        //Buchstaben ohne Shift-Taste werden einfacht zurückgegeben
        //Buchstaben mit Shift-Taste wird ein + hinzugefügt und zurückgegeben
        private string HandleShiftableKey(string theKey)
        {
            if (shiftindicator)
            {
                return "+" + theKey;
            }
            else
            {
                return theKey;
            }
        }

        // Klick auf Shift wenn die Shifttaste gedrückt wurde
        private void pictureBoxShiftDown_Click(object sender, MouseEventArgs e)
        {
            HandleShiftClick();
        }
            
    }
    public delegate void KeyboardDelegate(object sender, KeyboardEventArgs e);

    public class KeyboardEventArgs : EventArgs
    {
        private readonly string pvtKeyboardKeyPressed;

        public KeyboardEventArgs(string KeyboardKeyPressed)
        {
            this.pvtKeyboardKeyPressed = KeyboardKeyPressed;
        }

        public string KeyboardKeyPressed
        {
            get
            {
                return pvtKeyboardKeyPressed;
            }
        }
    }
}

FormBrowserSteuerung.Desginer.cs

namespace WindowsFormsApplication1
{
    partial class FormBrowserSteuerung
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.userControlTS = new WindowsFormsApplication1.UserControlTS();
            this.SuspendLayout();
            // 
            // richTextBox1
            // 
            this.richTextBox1.Location = new System.Drawing.Point(31, 12);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(514, 103);
            this.richTextBox1.TabIndex = 0;
            this.richTextBox1.Text = "";
            // 
            // userControlTS
            // 
            this.userControlTS.Location = new System.Drawing.Point(40, 121);
            this.userControlTS.Name = "userControlTS";
            this.userControlTS.Size = new System.Drawing.Size(480, 202);
            this.userControlTS.TabIndex = 1;
            this.userControlTS.UserKeyPressed += new WindowsFormsApplication1.KeyboardDelegate(this.userControlTS_UserKeyPressed);
            // 
            // FormBrowserSteuerung
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(604, 378);
            this.Controls.Add(this.userControlTS);
            this.Controls.Add(this.richTextBox1);
            this.Name = "FormBrowserSteuerung";
            this.Text = "FormBrowserSteuerung";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.RichTextBox richTextBox1;
        private UserControlTS userControlTS;
        
   }
}

Gruss

2.760 Beiträge seit 2006
vor 16 Jahren

Die Mauskoordinaten werden nicht an das Benutzersteuerelement übergeben, es passiert einfach gar nix, der Debugger läuft durch.

Dann mal ne blöde Frage: Registrierst du das Moue event überhaupt irgendwo? Hab jetzt da nicht nichts gesehen.

Simon Heinzmann Themenstarter:in
43 Beiträge seit 2008
vor 16 Jahren

Genau das hat gefehlt!!!!!!!!!!!

this.pictureBoxKeyboard.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBoxKeyboard_MouseClick);