"Scribble Code deceptive series" Zjut database large experiment-student management System (IV): Building the main interface

Source: Internet
Author: User

Student Management System (iv) building the main interface

Before you build a model, you need to say something about WPF.

WPF is an MVVM pattern that effectively separates the UI layer from the logical layer, and an introduction to MVVM can look at. NET MVVM Design Patterns.

In WPF, the UI layer of code is generally written in XAML (can be read as dirty, one letter by one, nobody hits you, see you mood) in the file, XAML is also markup language, similar to HTML, you can do most of the UI drawing and animation effects. You can open the Xaml.cs file under a XAML file, which is where you write the background C # code. Interacting with the UI is called events, and you can register events with the control to respond to various actions.

For example, in the previous login interface, the user experience was reduced by 10,000 times times because the window's border was hidden, causing it to drag, so now it's time to add the drag event.

Now in the XAML file, select the window control (the first line of the code), and precede the right angle brackets with the code

Mouseleftbuttondown= "Window_mouseleftbuttondown"

VS automatically prompts you to create a new event, and then adds an event to the. cs file. Enter. CS to see the bottom of one more way to add code inside

        Private void Window_mouseleftbuttondown (object  sender, MouseButtonEventArgs e)        {            this. DragMove ();        }

This completes the definition of the drag, the user experience and hooves hooves kiss. Of course, this also involves the issue of routed events, the specific can look at the routed event overview, not much to say here.

Next, start drawing the main interface.

WPF drawings Use device-independent dimensions and do not show different results because of different resolutions. That is, they are drawn at a fixed dpi and cannot be fully displayed on a small screen if the drawing is too large.

Generally I like fixed size, because it is convenient, and not because the user changed the size of the window to affect the display effect, but in most cases, fixed window size is a very poor experience of the setting, users will use up a bit feel uncomfortable. So, here I only fix the smallest width and height, so that the element is not hidden because the window is too small.

Open the previous MainWindow.xaml file, modify the basic style, add the Close and minimize button (maximize to change the icon, too much trouble first) as well as a logout button and add two buttons to the event.

  

1      Public Partial classMainwindow:window2     {3          PublicMainWindow ()4         {5 InitializeComponent ();6         }7 8         Private voidClosebutton_click (Objectsender, RoutedEventArgs e)9         {Ten Application.Current.Shutdown (); One         } A  -         Private voidMinisizbutton_click (Objectsender, RoutedEventArgs e) -         { theWindowState =windowstate.minimized; -         } -  -         Private voidLogout_click (Objectsender, RoutedEventArgs e) +         { - App.AppDbconnection.Resize (); +             NewLogin (). Show (); A              This. Close (); at         } -}

Open App.xaml.cs, add read/write to RememberMe, note set to private, plus a reset method to restore the setting to its original state.

1      Public classappdbconnection2     {3         //Other code ...4 5          Public BOOLRemeberme {Get;Private Set; } =Settings.Default.remeberMe;6 7          Public voidReset ()8         {9 Settings.Default.Reset ();Ten Settings.Default.Save (); OneAppconnectionstring =Settings.Default.connectionString; ARemeberme =false; -         } -}

Back in Login.xaml.cs, modify the code for the construction method and the logon event.

1          PublicLogin ()2         {3 InitializeComponent ();4             if(App.AppDbconnection.RemeberMe)5             {6                 NewMainWindow (). Show ();7                  This. Close ();8             }9         }Ten         Private voidLoginbutton_click (Objectsender, RoutedEventArgs e) One         { A             varSuccess = App.AppDbconnection.Login (Uidtextbox.text, Pwstextbox.password, remebermecheckbox.ischecked??false); -             if(Success) -             { the                 NewMainWindow (). Show (); -                  This. Close (); -             } -             Else +MessageBox.Show ("Something wrong!"); -}

Now you can switch between the two windows in a cheerful.

Back to MainWindow.xaml, let me think about what the interface should be (art online (Error

Yes, it's painted.

  

In addition, in the Windowstyle=none, the maximized window will cover the taskbar, I checked, the online method is basically used to Win32 API, I stole a lazy, only in the MainWindow of the construction method to add a maximum height limit good.

1          Public MainWindow () 2         {3            InitializeComponent (); 4             this. MaxHeight = SystemParameters.WorkArea.Height; 5         }

And finally the Github:github\lzxhahaha\educationmanager.

"Scribble Code deceptive series" Zjut database large experiment-student management System (IV): Building the main interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.