Focus issue on textbox

rahul kumar 605 Reputation points
2023-06-24T12:34:33.0466667+00:00

Hi , I want to disable or modify the event for the all the seven textboxes in my form , in which when the cursor is already on any textbox ( there are seven textboxes on a form ) and in between if the user by using mouse ( only mouse ) tries to get into another textbox , he should be unable to do so . Is there a event which can cancel this .

Developer technologies Windows Forms
Developer technologies C#
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. David Lowndes 2,640 Reputation points MVP
    2023-06-24T12:58:40.9733333+00:00

    See if this gives you some ideas.

    I'd caution you against doing it though - it'll probably annoy your application's users at some point!


  2. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2023-06-25T09:41:33.28+00:00

    After thinking about this my opinion is to not go in this direction as it can make the user frustrated along with a non-standard path to do data entry. A more conventional approach is to allow the user to enter data in any order they choice then validate which is how web applications do. If open to this I have an article with source code to show how to do this for Windows Forms projects.

    Yes this goes against what you are after but it's the better method.

    Window forms data annotation. Sample screenshot from article.

    ValidateForm


  3. Anonymous
    2023-06-28T06:49:11.79+00:00

    Hi @rahul kumar ,Welcome to Microsoft Q&A.

    If you want to hide cursor in custom textbox.

    You can do this.

    [DllImport("user32.dll")]
        private static extern bool HideCaret(IntPtr hWnd);
    
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            HideCaret(Handle);
        }
    

    User's image

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.