Matt Hanson
Matt Hanson

Reputation: 3504

Reproduce Windows Product Key Input

I'm starting to put together an activation dialog as part of my application. I really like the way Microsoft did theirs recently with Windows 7, more specifically the way the hyphens that separate each quintet of the product key are added and removed automatically.

After taking a quick look at it, it seems like it's a bit more difficult to implement smoothly than I had first though. That or I've been starring at the issue for too long. Is there any sample code or tutorial that reproduces this behavior for a TextBox?

alt text

Upvotes: 1

Views: 800

Answers (1)

Stephen
Stephen

Reputation: 3084

This can be done with a "MaskedTextBox" control

public void Form1_Load(Object sender, EventArgs e) 
{
    maskedTextBox1.Mask = "0000 - 0000 - 0000 - 0000";
}

http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx

http://msdn.microsoft.com/en-us/library/kkx4h3az.aspx

Upvotes: 2

Related Questions