• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • Last Modified:

C# WinForms - TextBox selection

Hi,

How can you make a text box that you can:
- Select text from
- Cannot modify the text

Does anybody know?

Thank you :)
0
Endelm
Asked:
Endelm
  • 4
  • 2
1 Solution
 
EndelmAuthor Commented:
Is it possable to display the textbox as gray  (like when it is disabled) and be able to select text from it?

Thank you.
0
 
Bob LearnedCommented:
You wouldn't have to disable the control, just block all keys:

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            e.Handled = true;
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

Bob

0
 
EndelmAuthor Commented:
Is there any way of having it gray looking (like when it is disabled) but still be able to select text from the TextBox?

Thank you.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Bob LearnedCommented:
Sure, set the ForeColor to SystemColors.GrayText, and block the keyboard.

Bob
0
 
EndelmAuthor Commented:
Thank you TheLearnedOne.

This makes the text inside the textbox gray (not the textbox itself).

How can I make the textbox gray?
0
 
EndelmAuthor Commented:
Found it.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now