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
Related
So for the program I'm writing I have an overview of notes the user created. This I created with TextBoxes that are generated from database values. I want the user to not be able to enter and change anything in this overview.
I tried to use tb.ReadOnly = true; but this doesn't disable the entering of the textbox.
After that I tried tb.Enabled = false; but this applies a gray out to all the text.
Is there any way to remove this gray out or just make the TextBox unchangeable without any visual difference?
Create a label with border style as FixedSingle, flat style as Flat, and set padding to 5,5,5,5.
One option is to use a NuGet package such as Guna UI to add custom controls. Using Guna, you can use the Control.DisabledState:
textBox1.DisabledState.FillColor = Color.White;
textBox1.DisabledState.ForeColor = Color.Black;
Note: changing a UI control's disabled state to make it appear enabled is in general, bad practice. This is because a user may try to use the TextBox and get frustrated because the computer will not let them use it.
Or alternatively, you could use a Label instead of a TextBox.
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
I have a 'log' in my application. Currently I'm using richtextbox control to display colored text. The problem I want to have a simple animation from background images in the background. According to this answer: Can a background image be set on a Winforms TextBox? it's not recommended. I could use datagridview for log, but it flickers when new items are added and it makes it look unstable and ugly. What would be a good way on winforms to display colored text in log and have a background image? Thanks!
If you want something that is easy and looks at least decent your best bet is probably to use WPF Interop (ElementHost) and build the control in WPF. Winforms constrols are a real headache for this type of application.
The WPF TextBox already supports a background image and renders it well.
In your WinForms Project : Right-click, "Add" --> "New Item..."
Select "WPF" --> "UserControl".
Drag a WPF TextBox onto the control, set up background image as you like, etc.
In your Winforms form --> "WPF Interoperability" (in Tools pane) --> drag "ElementHost" to your form.
Set the "Selected Host Content" to your new WPF user control.
Job done.
Does anyone know if there's a way to fix this issue in .NET/WinForms with the Visual Studio designer?
Basically, if you take a blank form and add a TabControl and then set the Alignment property to Bottom and Appearance property to Buttons (or FlatButtons), the TabControl doesn't have a panel to work with. I can't add any controls to the TabPage at all. Is there a work-around for this? I have a nested TabControl that I want to use bottom/button tab appearance and I can't get this to work at all. I suppose I could use standard buttons with panels that I toggle the visibility on, but that's less than ideal.
Bonus question:
Why when I set the Alignment to Right or Left (Appearance = Buttons) is there such a huge gap between the tabs and the actual panel in the Tab Page?
Thank you!
EDIT: Using .NET 4.0 w/ VS2012
Appearance property = Button is the issue. Modify it to Normal.
I have a user control that contains multiple controls (CheckBox, Button, Label...).
I want to change the layout of this user control to support right to left languages but i can't find how to do it.
Currently i can change the controls alignement using the RightToLeft property. But how can i change their positions?
Thank you for your time.
Thank you guys for your answers but there is a better way to do it.
First we go to the user control properties and select the language property.
After changing it to another language a new resource file will be created for the user control.
After that, using the designer we can change the controls positions in the user control as we like.
The new values will be saved in the created resource file.
When the language has changed, the corresponding resource file will be loaded and the positions will be changed.
If the language is a right to left one, don't forget to specify the right to left property for the controls.
Hope this helps.
Use the layout controls with the RightToLeft property and follow the following links for implementation:
RightToLeft property in Form in C#
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.righttoleftlayout(vs.80).aspx:
Developing Arabic applications should be easy!
Implementing Mirror-Aware Controls for Windows Application with Visual Studio .NET
Try to use FlowLayoutPanel or TableLayoutPanel to hold your controls and change panels RightToLeft property
User control mirroring is not supported for user controls, see this connect article: http://connect.microsoft.com/VisualStudio/feedback/details/121202/usercontrol-mirroring-is-not-inherited-from-the-form
Their suggested workaround is to use a table layout panel which will mirror the controls in right to left.