-1

I am working on WindowsForm C#.

The border i create becomes problem when maximized!

private void App_Paint(object sender, PaintEventArgs e)
    {
        ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Crimson, ButtonBorderStyle.Solid);
    }

Normal: enter image description here

Maximized: enter image description here

Am i doing something wrong?

Is there a better way of doing this?

Hassaan Raza
  • 91
  • 1
  • 11

3 Answers3

1

DrawBorder() has a parameter that can be used to remove a previously drawn border, just set ButtonBorderStyle to None

Example:

ControlPaint.DrawBorder(e.Graphics, (sender as Control).ClientRectangle, Color.Red, ButtonBorderStyle.None);

The only thing I don't like as much of my approach, is that it requires calls to the Paint event, which can get slow.

See this to refresh the form at runtime

shxdow
  • 31
  • 1
  • 5
0

Based on the information provided, I see it twice, meaning the painted information is being retained (relative to the position of the form) from the previous instance.

I'd strongly recommend staying away from trying to paint the non-client area.

If you have a custom request such as this, create a form with FormBorderStyle.None. Then, have a custom event to paint the Split Container's border. The top panel will have the custom min/max buttons. The rest of the content should be in the lower panel that fills below the min/max button.

Stay away from non-client painting. It's more trouble than it's worth.

Ctznkane525
  • 7,297
  • 3
  • 16
  • 40
0

I did it my self :D

1) Create a button, turn its FlatStyle to flat.

2) Turn Enable property to false, also remove all text

3) Dock the button to fill.

4) If previous button,labels(control) got hidden because of button, right click the button , send it to back!

Hassaan Raza
  • 91
  • 1
  • 11