In CSS we're able to edit the text selection's colors by using the ::selection pseudo-tag. Is it possible, to overwrite the default background color of the selection just for one control, e.g. a RichTextBox? I know, that there is no way to change the default behaviour by something like CSS, but at least overwrite it for this control might be possible.
I already googled for about an hour now, but I only found snippets of syntax highlighting. I want the text to be e.g. yellow instead the typical Windows blue.
EDIT
Like in this fiddle: http://jsfiddle.net/W99Gt/
In WPF you can accomplish this as follows:
myRichTextBox.SelectionBrush = System.Windows.Media.Brushes.Yellow; // WPF
myRichTextBox.IsInactiveSelectionHighlightEnabled = true;
Unfortunately, the desired behavior is not possible in Windows Forms (details here). The workaround would be to use a WPF RichTextBox in the Windows Form through ElementHost.
References:
TextBoxBase.SelectionBrush Property (WPF)
TextBoxBase.IsInactiveSelectionHighlightEnabled Property (WPF)
EDIT: Removed the WinForms solution, because SelectionBackColor does not provide the desired behavior.
There is a property RichTextBox.SelectionColor which should do the work. Quoting MSDN
A Color that represents the color to apply to the current text
selection
Related
can anyone help me to creat a textBox with the bottom border only in C#? I'm using WinForms and .Net Framework 4.8. Here is the image that I want to create.
I need the correct solution for this.
One way to achieve this would be to dock a label to bottom of TextBox like so
textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
var label = new Label()
{
Height = 1,
Dock = DockStyle.Bottom,
BackColor = Color.Black
};
textBox1.Controls.Add(label);
This specific Textbox that you mentioned by showing a picture is called Material TextBox and such an UI is called Material UI.
You can refer this link:
How to use material design controls c# winforms
The accepted answer will work perfectly fine however if you want something more professional, this could be your choice.
The link explains how to use the Nuget Package MaterialSkin.Updated in your winforms application to make a beautiful UI.
EDIT :
If you are not a coding geek and you need to do it without much coding part, you can create a simple user control with a textbox(design the backcolor and textcolour to suit your needs).
Then add a panel at the bottom with size (0,1) and set it to be visible only when the textbox gets focus.
This link provides examples to add placeholder to textboxes : Placeholder StackOverFlow
I know that this WPF cell background issue has been covered many times, but all the solutions I've seen use xaml (see: Change DataGrid cell colour based on values)
You may think, why no xaml? Xaml is nice if you have static colouring rules, which I do not. (My app is an electrical solver which will highlight values over and under certain security limits defined by the grid operator)
Well, I cannot have static rules to colour the cells (something like if input>0.5 return red)
because the rules of colouring are defined by the user at run time.
Is there any way of achieving cell styling without using any xaml?
Right now what I use is the windows forms datagrid embeeded in a windows forms host in a WPF UI (Ugly, but works) I would really like to have the WPF data grid since its performance is much better.
Any help is appreciated.
It is still proper databinding scenario and I see no reason to evaluate anything in your view's codebehind code. The key is to split colour calculation and it's visual representation.
Encapsulate your color switching logic in row's ViewModel property with proper notification changes when colour should change.
Create a converter which takes your ViewModel property type ie. string and created a Brush out of it
Bind cell content's Background property to row's property using converter created in 2.
I'm trying to force Minimize/Maximize/Close buttons' tooltips (in ribbonform) to get a look from a lookAndFeel. So far I created a ribbonform, then I placed defaultLookAndFeel component on it ahd I chose an OfficeBlue skin. My ribbon form changed however the tooltips for control buttons(minimize,maximize,close) look the same. I also tried to use DefaultToolTipControler however changing properties on appearance section didn't get any results.
Is there any way to change appearance of tooltips mentioned before?
You're probably trying to get rid of the Aero integration.
Set AllowFormGlass to false.
I am looking for some control that can do following 2 :
1.highlight some of the text in different colors.
easy databind.
checked richtextbox - but it is hard to databind with it.
checked textbox but it problem to text hight light with it.
any suggestions
Use the RichTextBox - or even better the Extended RichTextBox here (it allows easy DataBinding): http://wpftoolkit.codeplex.com/wikipage?title=RichTextBox.
If you don't want to have to include another control you can create an AttachedProperty to make it possible to bind to the built in RichTextBox. Check this out here: http://michaelsync.net/2009/06/09/bindable-wpf-richtext-editor-with-xamlhtml-convertor
How to change the color of text, when a control is disabled.I want to set different color when control is disabled in c# winforms.
Edit: I had made the same mistake as Cody in the comments so corrected my answer.
It depends on which control it is.
For example, if it's a TextBox maybe you could make it ReadOnly instead of disabled. And for some other controls you might be able to do similar things to make them appear disabled without actually being disabled.
However, if you want to do it properly you need to make them Owner-draw or override the OnPaint event and draw the text yourself.
You can just do it manually -- when you disable the control, just change the text colour too?
If you have many controls, you can do this:
attach your form OnChildAdded event
in the event, use if ... is of type structure to determine control type
depending on the control type, register proper OnEnabledChange event
in the event, change text color appropriately
That way, you will have a piece of code that will work for all your forms and will gradually expand to use all the controls you need.
I'll provide some code if that's the way you want to go...