0

I have a RichTextBox in my application which starts out disabled (gray) and becomes enabled once a file is opened (white). This has been working fine.

But when I set the ShowSelectionMargin property to True (which will be a very helpful change for this app), it turns the background to gray permanently. I think this is probably a bug in DotNet (I believe this is running under .NET 4.5 at the moment), but might there be a workaround?

(May be related to Why does my control extending RichTextBox defaults to gray background? .)

Oh, I just figured out a workaround, but I'll go ahead and post this (and answer it), in case others come looking (or have better solutions).

Community
  • 1
  • 1
Jon Coombs
  • 2,135
  • 2
  • 25
  • 26

2 Answers2

0

Ok, I think the issue here might be related to the fact that it was actually the containing control (that the RichTextBox was embedded in) that was being enabled/disabled. (I inherited this code and sometimes have trouble keeping track of all the pieces)

Anyway, the workaround in this case was to very clearly toggle that. This is part of the code that runs upon successfully opening a file:

_sfmEditorView.Enabled = false; // had to add this line
_sfmEditorView.Enabled = true;
Jon Coombs
  • 2,135
  • 2
  • 25
  • 26
0

Here's another workaround (which I just found at How to change the background color of a rich text box when it is disabled?) which isn't exactly to enable/disable (since selection/copying are still available), but it probably would have been much more convenient in my case:

richTextBox.ReadOnly = true; 
Community
  • 1
  • 1
Jon Coombs
  • 2,135
  • 2
  • 25
  • 26