Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This seems actually uniquely horrible to do on Windows, depending on the degree to wish you want to go to (e.g. if you want text to be selectable or not, if you want to be able to do text formatting).</p> <p>I discovered this some time ago but was fortunate to find the horror was reasonably well documented on various blogs. It seems you can use a RichTextBox, but create event handlers to prevent end users from modifying it's contents.</p> <p>e.g. RichTextBox called "myRichTextBox" then you would want add the following to the Designer.cs for the form:</p> <pre><code>this.myRichTextBox.SelectionChanged += new System.EventHandler(this.MyRichTextBox_Deselect); this.myRichTextBox.DoubleClick += new System.EventHandler(this.MyRichTextBox_Deselect); this.myRichTextBox.GotFocus += new System.EventHandler(this.MyRichTextBox_Deselect); this.myRichTextBox.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.MyRichTextBox_LinkClicked); </code></pre> <p>And then you'd want to create methods like the following in your form:</p> <pre><code>public void MyRichTextBox_Deselect(object sender, EventArgs e) { // When user tries to select text in the rich text box, // set selection to nothing and set focus somewhere else. RichTextBox richTextBox = sender as RichTextBox; richTextBox.SelectionLength = 0; richTextBox.SelectionStart = richTextBox.Text.Length; // In this case I use an instance of separator bar on the form to switch focus to. // You could equally set focus to some other element, but take care not to // impede accessibility or visibly highlight something like a label inadvertently. // It seems like there should be a way to drop focus, perhaps to the Window, but // haven't found a better approach. Feedback very welcome. mySeperatorBar.Focus(); } public void MyRichTextBox_LinkClicked(object sender, LinkClickedEventArgs e) { System.Diagnostics.Process.Start(e.LinkText); } </code></pre> <p>Obviously you may not care about the LinkClickedEventHandler() handler, but I'm sure wanting that functionality it's fairly common, given the RichTextBox control has the option to automatically identify and colorise URL's.</p> <p>I have no idea why there doesn't seem to be a more elegant solution and would welcome input from anyone who knows of a better approach.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload