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 7067547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:12:55+00:00 2026-05-28T05:12:55+00:00

I have a class derived from TextBox in C#. I override OnClick method to

  • 0

I have a class derived from TextBox in C#. I override OnClick method to show a file open dialog. Is it possible to lose focus after that? I don’t want the user to be able to edit the text because at a moment the file name might be invalid. I tried to set ReadOnly = true, but one can change the text after selecting the file.

EDIT:

I added the relevant code for this. As it is now the focus will be set to next control from my Form.

class Property : TextBox
class FileSelectTextBox : Property
{
    protected override void OnClick(EventArgs e)
    {
        OpenFileDialog dialog = new OpenFileDialog();
        Enabled = false;
        if (dialog.ShowDialog(this) == DialogResult.OK)
        {
            Text = dialog.FileName;
        }
        Enabled = true;
    }
}
  • 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-28T05:12:55+00:00Added an answer on May 28, 2026 at 5:12 am

    You have several options here:

    1. Make the textbox ReadOnly. The textbox will still fire OnClick events but the text won’t be editable by the user.
    2. Disable the textbox at the end of your click event — the disadvantage is that the click event won’t fire a second time (which means the user won’t be able to change their mind and pick a new file).
    3. Simply set the focus somewhere else at the end of the click event. (someOtherTextBox.Focus())

    Edit: Once last suggestion: you may want your file popup to happen in FocusGained rather than OnClick, that way the dialog will still pop up if the user tabs into the control. Of course it’s your decision if that behavior is desired or not.

    Edit 2: Ignore that last edit. It’s a bad suggestion that I didn’t think through. (Thanks for the heads up commenter)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class derived from window to show message to user. The problem
Say I have class B derived from class A Is it possible to invoke
i have a class 'MyTextBox' that derives from the default TextBox in Silverlight. This
I have a class derived from CTreeCtrl . In OnCreate() I replace the default
I have a class derived from Dictionary. I need this class to simulate a
I have a c++ class derived from a base class in a framework. The
I have a class which is derived from a base class, and have many
I have a class, say DerivedBindingList<T> , which is derived from BindingList<T> . I
I have a derived derived class from an abstract class. The code is below.
I have a basic class that derived subclasses inherit from, it carries the basic

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.