Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:55:30+00:00 2026-05-16T17:55:30+00:00

I have a small problem. After making a hex mask, I can not copy/paste

  • 0

I have a small problem. After making a hex mask, I can not copy/paste with Ctrl+C/V. If I right click in the textbox I can paste. But I would like to be able to just press Ctrl+V.

If I delete the hex mask, Ctrl+C/V works fine.

Here is a bit of the code:

private void maskedTextBox1(Object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        // this will allow a-f, A-F, 0-9, "," 
        if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "^[0-9a-fA-F,V,C,'\b']+$"))
            {
                e.Handled = true;
            }

        // if keychar == 13this ill allow <ENTER>
        if (e.KeyChar == (char)13)
            {
            button1_Click(sender, e);
            }
        // I thought I could fix it with the lines below but it doesnt work
       /* if (e.KeyChar == (char)22)
        {
            // <CTRL + C> 
            e.Handled = true;
        }
        if (e.KeyChar == (char)03)
        {
            // is <CTRL + V>
            e.Handled = true;
        }*/
        //MessageBox.Show(((int)e.KeyChar).ToString());
    }

Could someone give me some hints, Please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:55:31+00:00Added an answer on May 16, 2026 at 5:55 pm

    You need to catch these keystrokes with a KeyDown event handler, not KeyPressed. KeyPressed is only raised for typing keys.

    A MaskedTextBox is not ideal here, you can also do it with a regular TextBox. Use the Validating event to format the number and check for range. For example:

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e) {
            bool ok = e.KeyChar == 8;  // Backspace
            if ("0123456789ABCDEF".Contains(char.ToUpper(e.KeyChar))) ok = true;
            if (!ok) e.Handled = true;
        }
    
        private void textBox1_Validating(object sender, CancelEventArgs e) {
            int value;
            if (textBox1.Text.Length > 0) {
                if (!int.TryParse(this.textBox1.Text, System.Globalization.NumberStyles.HexNumber, null, out value)) {
                    this.textBox1.SelectAll();
                    e.Cancel = true;
                }
                else {
                    textBox1.Text = value.ToString("X8");
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have small problem with http 404 error, after click on 'allow' on facebook
I have an odd problem. Basicly my page works fine however after a small
I have a small problem which i can't seem to figure out. I tried
I have a small problem which i can't seem to solve myself. Look at
I have a small problem and I do not find any solutions. I want
I have a small problem regarding a count after grouping some elements from a
I have a small problem with TFS. I am trying to zip files after
I have small problem with my conception of deleting rows in UITableView. After user
I have small problem. I have made very simple bootloader. After it's creation I
I have a small problem with rollover effects. First time after loading everything's fine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.