Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C # WinForm to make login interface

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use C # WinForm to make a login interface". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to make a login interface with C # WinForm".

Find Form1.cs in solution Explorer, click, and the shortcut F2 is renamed to "Login.cs" (naming is important, otherwise there will be more projects based on not knowing what the content of which project is)

Modify the form [Text] property, [size] property, and [FormBoardStyle] property

Add a new form

Ctrl+Shift+A, select [Windows form] in the pop-up box and name it main.cs

Cancel the login interface to maximize and minimize the close button is displayed on the parent window menu bar

Maximize: MaximizeBox, minimize: MinimizeBox

If you set one to False, it will show that it is not available, and when both are set to False, both buttons will disappear.

The close button is not available without a setting

However, there is a ControlBox property that disappears when the minimize, maximize, and close buttons are set to False.

You can also add the following code to login.Designer.cs

This.MaximizeBox = false; / / disable the maximize button, where this refers to the form object this.MinimizeBox = false; / / disable the minimize button / / this.ControlBox = false; / / and disable the maximize and minimize close button

If the close button is disabled, the window cannot be closed through the system's native features. You have to write another off function to turn it off.

Change the code in Program.cs to the following

The added code is

Public static bool isValidUser; if (isValidUser = = true) {Application.Run (new main ());}

Add three Label controls to the login interface, arrange them vertically, and change their [Text] properties to "user name:", "password" and "user Type" respectively.

Drag and drop two TextBox controls and a ComboBox control from the Toolbox, place them on the right side of the corresponding Label control, and change their [Name] properties to "textBoxUserName" and "textBoxPassword", respectively.

"comboBoxLoginType".

Add another CheckBox control and change its [Text] property to "automatic login"

-continue to drag and drop two Button controls from the Toolbox to the form, and change their [Name] properties to "buttonOK" and "buttonCancel", and [Text] properties to "OK" and "cancel", respectively.

Double-click the OK button control with the mouse to automatically add the Click event, and then change the event code to the following:

Private void buttonOK_Click (object sender, EventArgs e) {Program.isValidUser = true; this.Close ();}

Also double-click the cancel button control with the mouse to automatically add the Click event, and then change the event code to the following:

Private void buttonCancel_Click (object sender, EventArgs e) {Program.isValidUser = false; this.Close ();}

The meaning of the above code is: click "OK", pop up the next interface, main;, click cancel, and close the login screen.

After changing the button event code, we add the following to the constructor:

ComboBoxLoginType.Items.AddRange (new object [] {"Chinese-simplified", "English-US"}); comboBoxLoginType.SelectedIndex = 0

The purpose of this code is to add the options for the drop-down box. Press [F5] after you finish these, and the results are as follows:

Add a new form

Ctrl+Shift+A, select [Windows form] in the pop-up box and name it OtherForm.cs

Open the design interface of main.cs and design the function of the main form.

The interface is designed as follows:

Follow the design steps of login.cs 's design interface, change the [AutoSize] property of the first Label control to "False", and the [BorderStyle] property to "Fixed3D" [TextAlign] property to "MiddleCenter".

Change the [Name] property of textBox after "name" to "textBoxName"

Change the [Name] property of textBox after "basic Information" to "textBoxBaseInfo"

Change the [Name] property of textBox after "other Information" to "textBoxOtherInfo"

Other control properties can be set as before.

Modify the [Name] properties of the "auto-fill text box", "pop-up dialog box" and "pop-up new form" buttons to "buttonFillText", "buttonShowDialog" and "buttonShowNewForm" to automatically add the corresponding Click event code, and modify the code as follows:

Private void buttonFillText_Click (object sender, EventArgs e) {textBoxName.Text = "Jiang Shan"; textBoxBaseInfo.Text = "male, 27 years old"; textBoxOtherInfo.Text = "hobby, basketball";} private void buttonShowDialog_Click (object sender, EventArgs e) {MessageBox.Show ("OK");} private void buttonShowNewForm_Click (object sender, EventArgs e) {OtherForm otherForm = new OtherForm (); otherForm.ShowDialog ();}

Add TabControl controls to the OtherForm.cs interface

Set up Dock

Find the TabPage property in the property

Click the button with three ellipses to enter the tab editing interface, the tabPage Collection Editor, where you can add, delete, tab, reposition tabs, and edit tab properties, as shown in the following figure

You can also dynamically edit tabs in the code, for example, the code for adding or removing tabs is:

Hide tab labels for TabControl

Add the following code to * *. Designer.cs

/ / Hidden tab header / / method 1 tabControl1.SizeMode = TabSizeMode.Fixed; tabControl1.ItemSize = new Size (0,17); tabControl1.Appearance = TabAppearance.FlatButtons;// method II this.tabControl1.Region = new Region (this.tabPage1.Left, this.tabPage1.Top, this.tabPage1.Width, this.tabPage1.Height) Thank you for your reading, the above is the content of "how to make login interface with C # WinForm". After the study of this article, I believe you have a deeper understanding of how to use C# WinForm to make login interface, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report