Hi @rahul kumar , Welcome to Microsoft Q&A.
Do you mean that when the custom textbox control is dragged into the form, its background is automatically modified as the form background?
You can modify in onparentchange event.
Here I set the border to 3D, just for the convenience of display, modify it according to your own needs.
using System;
using System.Windows.Forms;
namespace _6_xx_uc2
{
public partial class CustomTextBox : TextBox
{
public CustomTextBox()
{
this.BorderStyle = BorderStyle.Fixed3D;
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
protected override void OnParentChanged(EventArgs e)
{
base.OnParentChanged(e);
if (this.Parent != null)
{
this.BackColor = this.Parent.BackColor;
}
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.