1

My question may sound simple but I can't get the answer i'm looking for anywhere. I want to do a login page for a Windows Form program but I don't want the form to have the top right classic buttons (Minimize, Maximize, Close). I can't find a property to hide the buttons.

Anyone know a good way to this ? Thanks in advance

phadaphunk
  • 12,785
  • 15
  • 73
  • 107

3 Answers3

2

For the minimize and maximize buttons, just set these properties (e.g. in constructor):

public Form1()
{      
    MaximizeBox = false;
    MinimizeBox = false;
    ControlBox = false;
}
Fischermaen
  • 12,238
  • 2
  • 39
  • 56
1

The Form has two properties called MinimizeBox and MaximizeBox, set both of them to false.

Close button

During construction and creation of the Form object, .NET would use the default creation parameters available in the base class CreateParams property.

In fact, CreateParams property is available in Forms.Control class. In form class (derived from System.Windows.Forms.Form), override this property and modify the creation flags. For disabling the Close button use 0x200 to modify the ClassStyle member of the CreateParams.

private const int CP_NOCLOSE_BUTTON = 0x200;
 protected override CreateParams CreateParams
 {
     get
     {
        CreateParams myCp = base.CreateParams;
        myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
        return myCp;
     }
 } 

pls go through this link for more info

Glory Raj
  • 17,397
  • 27
  • 100
  • 203
0

Thinking a little outside the box, have you considering showing the Windows password dialog rather than writing your own? This has the advantage of making your dialog look and feel more native.

You can get the dialog to show, customised for your needs, with the CredUIPromptForCredentials API. There are lots of C# wrappers around but it's a pretty straight forward p/invoke if you fancy doing it yourself. I quick websearch revealed this Stack Overflow question with the necessary p/invoke work already done.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490