Professional Documents
Culture Documents
Mango TV
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 1/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
Hello, in this tutorial we will create a custom TextBox with soft rounded corners, rectangular
and underline style, border color and size, text color, and be able to set a placeholder, where
the text should be obtained naturally, either field from password or not.
After having initialized the previous properties, it only remains to add a text box to the user
control and set the Dock property of the text box to FILL , to fit the entire user control.
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 2/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
And finally remove the border from the text box . In this way, the text box remains
centered on the user control, thanks to the Padding established above.
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 3/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
// Fields
private Color borderColor = Color. MediumSlateBlue ;
private Color borderFocusColor = Color. HotPink ;
private int borderSize = 2 ;
private bool underlinedStyle = false ;
private bool isFocused = false ;
We will create a method to set the placeholder, and another method to remove it.
A method of getting the graphics path of the control with rounded corners.
Finally, a method that will be in charge of setting a suitable height for the user
control (RJTextBox) and text box (textBox1), and in addition to restricting the
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 4/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
height change when the text box is not multiline (textBox1.Multiline = false) .
path. StartFigure () ;
path. AddArc ( rect. X , rect. Y , curveSize, curveSize, 180 , 90 ) ;
path. AddArc ( rect. Right - curveSize, rect. Y , curveSize, curveSize, 2
path. AddArc ( rect. Right - curveSize, rect. Bottom - curveSize, curveSi
path. AddArc ( rect. X , rect. Bottom - curveSize, curveSize, curveSize,
path. CloseFigure () ;
return path;
}
private void SetTextBoxRoundedRegion ()
{
GraphicsPath pathTxt;
if ( Multiline )
{
pathTxt = GetFigurePath ( textBox1. ClientRectangle , borderRadius -
textBox1. Region = new Region ( pathTxt ) ;
}
else
{
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 5/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 6/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
}
}
{
borderRadius = value ;
this . Invalidate () ; // Redraw control
}
}
}
{
base . OnLoad ( e ) ;
UpdateControlHeight () ;
}
protected override void OnPaint ( PaintEventArgs e )
{
base . OnPaint ( e ) ;
Graphics graph = e. Graphics ;
{
this . Region = new Region ( this . ClientRectangle ) ;
penBorder. Alignment = System. Drawing . Drawing2D . PenAlignment
if ( isFocused ) penBorder. Color = borderFocusColor;
Note: To know what the default event of a control is, you just have to double click on the
control and the default event method will be created.
[ DefaultEvent ( "_TextChanged" )]
public partial class RJTextBox: UserControl
{
// Default Event
public event EventHandler _TextChanged;
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 11/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
this . Invalidate () ;
RemovePlaceholder () ;
}
private void textBox1_Leave ( object sender, EventArgs e )
{
isFocused = false ;
this . Invalidate () ;
SetPlaceholder () ;
}
Well that's it :), I hope you liked it and helped you understand the use of user controls
alongside other controls to make custom controls.
downloads
SEE FULL CODE (GITHUB)
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 12/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
Part 2:
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 13/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
Leave a reply
Your email address will not be published. Required fields are marked with *
Commentary
Name *
E-mail *
Web
Welcome to blog
Look for …
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 14/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
Follow me
Category:
.NET
ASP .NET
C#
Mistakes
F#
Visual basic
Windows Forms
Layered Architecture
Database
MySQL
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 15/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
SQL Server
Custom controls
courses
.NET (Course)
Create .Net Installer
Full Login C #, VB, SQL Server
Software Patterns (Course)
OOP (Course)
Desk
GUI
Software Patterns
OOP
Uncategorized
Web
Recent logins
Circular Picture Box - Border Gradient color + Styles - C # & WinForms
Custom ProgressBar - WinForms & C #
Custom TextBox Full - Rounded & Placeholder - WinForm, C #
Custom ComboBox - Icon, Back, Text & Border Color - WinForm C #
Custom Text Box - Custom controls WinForm C #
Recent comments
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 16/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 17/18
7/22/2021 Custom TextBox Full - Rounded & Placeholder - WinForm, C # - RJ Code Advance
https://rjcodeadvance.com/custom-textbox-full-rounded-placeholder-winform-c/ 18/18