Empty RichTextBox start with Bold - c#

I have a problem. When i start working with RichTextBox (it is empty) I cannot change format to Bold.
I try to type (CTRL+B) but after I typed something the text is normal (not bold).
The text only changes format when I type something before. This happens again when I SelectAll and Clear all Content.
Is it bug in RichTextBox, or I can do something with it.
Best Regards,
_alexiej

Well, it's normal, usually you decide what is bold or not after you've written the text. If you want this button to act like ( on off ) you have to change it yourself.

Related

Edit individual character or word in RichEditBox?

Basically in RichEditBox you can paste text and it can automatically format that pasted text according to what you copied. I am wondering how to set a specific part of the document, such as a word, or sentence, to a specific form of font colour, or font style, or any other properties regarding text.
I cannot find any real documentation on how to do such a thing.
EDIT:
I found:
richEditBox.Document.GetRange(3, 10).CharacterFormat.ForegroundColor = Windows.UI.Colors.Blue;
If someone knows something nicer, post please.
Simply use
richEditBox.Document.GetRange(3, 10).CharacterFormat.ForegroundColor = Windows.UI.Colors.Blue;
Are you looking for something like this?
http://msdn.microsoft.com/en-us/library/0dhsw8eb(v=vs.90).aspx

Creating custom RichTextBox control

I believe am in need of creating custom RichTextBox in C#. One kind of like that:
I admit it might not even have to be RichTextBox, but after some research I decided it's gonna be the easiest way. Functionality I need are icons at each row, checkboxes and text formatting. My program will process each line of the text and mark lines that are correct, incorrect, and strike out lines not necessary in further work, while showing line that's currently processed and allowing user to edit some lines freely (here: lines before Around 3 000 won't be editable, but those under the line will).
What's the problem then? I have no idea how to get it done. I've seen tutorial on how to make single-line textBox with icon or checkbox nearby, but I have no idea how to make both, and for multiline textBox (so I could freely scroll and everything would work fluently). I've read some questions on SO as well, but neither helped me.
I just don't know how to get started, I realize it won't be 5 min work, but I'm willing to do it. Until now I've been only able to create custom control deriving from RichTextBox, but I have no idea which methods and how to override. Any help appreciated.
Try to use WebBrowser control instead RichTextBox.
You can add CheckBoxes and editable content by setting a correct HTML code to it.
Set each TextBox or CheckBoxes ids and use GetElementsByTagName or GetElementById to access inner elements to get or set its attributes or values.

How To Highlight Text in a textBox While Typing in another textBox?

I'm making a typing windows program that has two text Boxes,
the first is the Source Text textBox and it is read only,
the other is where the user get to type in the text that is in the source TextBox.
When the user typing a letter in the TypingTextBox, I want that letter to be highlighted in the SourceTextBox..
I tried doing this in a couple of events, but none really worked:
SourceTextBox.Select(TypingTextBox.SelectionStart , 1);
I even Tried Making my own event, Also didn't work.
The thing is, I won't see the SourceTextBox highlighting unless I click on it.
and As I mentioned, I tried putting the above code in events like:
Mouse-Focus-Leave in the SourceTextBox
and: TextChanged in the TypingTextBox.
All didn't work .. :(
and If I manged to do that, Can I change the Highlight color ?
Assuming this is WinForm, you need to set the HideSelection property on the TextBox to "False". As far as changing the highlight colour, none that I'm aware of.

Is it possible to have left-aligned text in a combobox whose 'RightToLeft' property is set to 'Yes'?

I have a combobox on a form whose 'RightToLeft' property is set to 'Yes' - this places the drop-down arrow on the lefthand side of the control and the text is on the right as shown below.
[X__________________________My Text]
But what I would like to have is this if it's possible? And if so how do I achieve it?
[XMy Text__________________________]
Thanks for your feedback on this.
You can create a custom control and use ComboBoxRenderer to draw the arrow where you want.
Hans Passant says:
Don't use RightToLeft, it is only appropriate for RTL languages like
Arabic and Hebrew. It causes rendering problems for English text, you
haven't seen any only by accident. Try "[My Text]" for example. Every
non middle-eastern user expects the arrow on the right.
Thanks for reading.

RichTextBox invisible selectable character at end of string

When selecting text in a RichTextBox using the mouse, or arrow keys + shift, I can select an extra blank character at the end of the string. To reproduce:
type a few characters (or nothing at all) in a RichTextBox
set the cursor to the end of the string
hold shift and press the right arrow key
You'll see a narrow highlighted selection appear, which cannot be deleted.
This causes a problem in my application because the SelectionFont property returns null when the extra character is selected along with some valid text. Any ideas on how to disable this extra character, or work around it otherwise?
c# winforms, visual studio 2010
Interesting. (This is not Dr House, MD, speaking.)
When nothing is selected in an empty RTF edit control, SelectedRtf returns:
"{\rtf1\ansi\ansicpg1252\deff0\deflang2055\uc1 }"
When the "phantom" stuff is selected in the empty RTF edit control, SelectedRtf returns:
"{\rtf1\ansi\ansicpg1252\deff0\deflang2055{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17\par
}"
Of course, SelectedText returns the empty string in both cases.
So I suspect what is selected is the metainfo that makes sure that newly entered text that would replace the empty selection will be inserted with the correct font.
However, that seems to be nonsense since newly entered text will be inserted with the correct font even if nothing is selected.
So all that does not make sense. (Well, it does, kind of -- see last paragraph)
Which makes me believe this is a bug, or at least a glitch, in RichTextBox.
The formatting info is probably created by the selection routine which makes sure that selected non-empty text will be replaced by the newly typed text formatted in the same format as the text it replaces. For this to work, a selection must always contain the formatting info, even if no text is selected. I think. Maybe one can pre-select a char and paragraph formatting different from the default one, somehow, and then typing text uses that format.
FIred up a new winforms app in studio 2010 and wasn't really able to reproduce this. I can select the invisible 'character' but it doesn't cause me any problems. SelectedFont still returns a valid object for me. I can get the text without issue.
The SelectionFont property for the RichTextBox control can ONLY return a single font. If the selected range contains more than one font, reading the SelectionFont property will throw a NullReferenceException.
Most likely what is happening is that the RichTextBox Font property is different than the current font you are using on the selected range. That "extra" character selected at the end is your Font property, not your SelectionFont property.
If your RichTextBox is just using a single font, just make sure the Font and SelectionFont property are the same.
Otherwise, just check if it's null:
if (richTextBox1.SelectionFont != null) {
//do something
}

Categories

Resources