Home > Software design >  Change panel border color at runtime
Change panel border color at runtime

Time:08-16

My problem is that i am trying to change a panel border color upon the activation of a textbox placed inside, any help will be much appreciated

CodePudding user response:

You can use the event Click of your TextBox (use the Property window from Form designer).

Then add the code:

    private void textbox1_Click(object sender, EventArgs e)
    {
        ControlPaint.DrawBorder(panel1.CreateGraphics(), panel1.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
    }

Obviously you can change the trigger event and adjust the color on your needs.

CodePudding user response:

I end up using the the enter and leave event of the text box as follow.

In the enter event

this.searchPanel.BorderStyle=BorderStyle.None;
        this.searchPanel.Refresh();
        ControlPaint.DrawBorder(
            graphics: this.searchPanel.CreateGraphics(),
            bounds: this.searchPanel.ClientRectangle,
            color: System.Drawing.Color.FromArgb(0,120,215),
            style: ButtonBorderStyle.Solid);

And in the leave event

this.searchPanel.BorderStyle = BorderStyle.FixedSingle;
this.searchPanel.Refresh();

Before enter image description here Afterenter image description here

  • Related