0

I want to customize the controlbox of my winform with a different background for it and different button images. How can I do so? Is there any way to make a custom controlbox with usercontrol or something like that and then add it to the winform?

Victor Mukherjee
  • 10,487
  • 16
  • 54
  • 97

3 Answers3

1

You have no influence on that using .NET framework means. You'd have to implement custom drawing for the non-client area of the form. The following might help you here: http://www.codeplex.com/wikipage?ProjectName=CustomerBorderForm&title=Painting%20NonClient%20Area

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
0

You can create your own custom controls by inheriting from a UserControl like so

class MyControl : System.Windows.Forms.Button //this could also have been System.Windows.Forms.UserControl or any other existing control type as a template
{
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        //Paint whatever you wish on this buttons graphics using e.Graphics
    }
}

There is a lot to programming custom controls. To much to answer here. A good reference is: http://msdn.microsoft.com/en-us/library/6hws6h2t.aspx

You could create your own sort of Forms control and hide the parents controlbox. Or maybe you can inherit from System.Windows.Form and createa a custom form. But I have never tried that myself.

And for using OnPaint you have to keep some rules in mind if you care about performance and/or flickering and such: What is the right way to use OnPaint in .Net applications?

Community
  • 1
  • 1
Mike de Klerk
  • 11,906
  • 8
  • 54
  • 76
-1

I don't know if I understand correct. Do you want create your own control? If is, try this:

  • Create a Custom Control.
  • Alter the type of your control.

Change:

public partial class MyCustomControl : Control { ... }

For:

public partial class MyCustomControl : Form { ... }
  • Alter the value of Controlbox properties to false.
  • Alter any properties you want customize.
  • Create a new Form.
  • Alter the type of your form.

Change:

   public partial class MyForm : Form { ... }

For:

public partial class MyForm : MyCustomControl { ... }

And now your MyForm it's like your MyCustomControl and you can reuse in all your project.

monteirobrena
  • 2,562
  • 1
  • 33
  • 45