开发者

Custom TextBox Event

I am programming in C# using XNA GS 4.0.

I have start out by attempting to catch the keyboard input events which I have managed. I.e. when a key is pressed, it raises a key event thanks to the help of an IMessageFilter scanning for keyboard input.

This might sound a bit redundant but since XNA stops the default Form key events from triggering, this seemed like a simple solution.

Now that i have both the Message struct and a KeyEventArgs struct that I have pieced together from the Message, I can simply fire an event in the main code file.

The problem I have lies in that I want a text box to respond to these key event messages as it would normally.

Question:

I would like to send the Message over to the text box (An extended class) so that it can read the necessary data and respond as it normally would without me having to convert the message into a single character to appen开发者_如何学God manually. Thanks.

Edit: Source code for this problem is difficult to provide for this problem as there is actually very little code at this point.

For now all I can really give you is the method I am using to capture the windows Messages

public class KeyboardFilter : IMessageFilter
{

    public event EventHandler KeyboardMessage;

    // This method is only used to detect key presses, it will NEVER remove any messages from the message loop
    public bool PreFilterMessage(ref Message m)
    {
        if (KeyboardMessage != null)
            KeyboardMessage(m, EventArgs.Empty);                

        return false; // Allow the message to be used by the message loop
    }
}

The output from this filter is the Message object. I need some way to get the TextBox to use this and update its Text property manually because XNA is blocking normal keyboard input. I would like to use something built into the TextBox if it exists but if need be, I can manually append characters for each individual key press myself. I just want to know if a more elegant solution exists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜