Previous topicNext topic
Help > 开发指南 > SanMuGrid平台编程 > 扩展示例 >
自定义登陆窗口

虽然本平台集成了一个现成的用户登陆界面,但是绝大多数人开发系统都是希望有一个个性化的登陆界面的,这样子显得有特色。我们平台中允许用户创建自己的用户登陆界面。理论上我们只需要在项目事件BeforeOpenUserLoginForm中,将e.LoginForm赋值一个自己自定义的登陆窗体即可。

理论上这个登陆窗口用户是可以随意设计的,但是为了配合我平台中一些常规数据的加载,最好还是在我提供的Demo基础上作修改,这样既省心,又可以作扩展,还可以做界面的自定义美化。

第一步,先根据示例,自定义一个窗体。

第二步,给各个控件写事件代码。

Vb.Net
Imports System
Imports System.Text
Imports System.IO
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Drawing.Text
Imports System.Diagnostics
Imports System.Collections
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Imports System.Collections.Specialized
Imports System.Windows.Forms
Imports System.Reflection
Imports Microsoft.CSharp
Imports Microsoft.VisualBasic
Imports sanMuSoft.Utility
Imports System.Linq
Imports System.Threading
Imports System.Threading.Tasks
Imports System.Net.Http
Imports C1.C1Excel
Imports C1.C1Zip
Imports C1.Win.C1Command
Imports C1.Win.C1FlexGrid
Imports C1.Win.C1Input
Imports C1.Win.C1Ribbon
Imports C1.Win.C1Themes
Imports sanMuSoft.CS.Framework
Imports sanMuSoft.CS.Framework.Editor
Imports sanMuSoft.CS.Framework.FormDesigner
Imports sanMuSoft.CS.Framework.DropDownForms
Imports sanMuSoft.CS.WinForm
Imports sanMuSoft.CS.WinForm.Editor
Imports sanMuSoft.CS.WinForm.Controls
Imports sanMuSoft.CS.WinForm.Controls.Grid
Imports sanMuSoft.CS.WinForm.Controls.BoxControls
Imports sanMuSoft.CS.Workflow
Imports sanMuSoft.CS.Report
Imports sanMuSoft.Data
Imports sanMuSoft.Data.TableBuilder

Namespace FormEvents
    Public Class Form13e950a0815f4d76b4ed5f5f1f9c9b9d
        Inherits FormEventsBase
        Private chkUser As SmCheckBox
        Private txtUser As sanMuSoft.CS.WinForm.Controls.SmComboBox
        Private btnCancel As sanMuSoft.CS.WinForm.Controls.SmButton
        Private btnConfirm As sanMuSoft.CS.WinForm.Controls.SmButton
        Private picBigLogo As sanMuSoft.CS.WinForm.Controls.SmPictureBox
        Private btnResetPassword As sanMuSoft.CS.WinForm.Controls.SmButton
        Private chkPassword As sanMuSoft.CS.WinForm.Controls.SmCheckBox
        Private txtPassword As sanMuSoft.CS.WinForm.Controls.SmTextBox
        Public Sub 用户登陆窗口_Load(sender As Object,e As  System.EventArgs)
            chkUser=Me.SmForm.ControlDictionary()("chkUser")
            txtUser=Me.SmForm.ControlDictionary()("txtUser")
            btnCancel=Me.SmForm.ControlDictionary()("btnCancel")
            btnConfirm=Me.SmForm.ControlDictionary()("btnConfirm")
            picBigLogo=Me.SmForm.ControlDictionary()("picBigLogo")
            btnResetPassword=Me.SmForm.ControlDictionary()("btnResetPassword")
            chkPassword=Me.SmForm.ControlDictionary()("chkPassword")
            txtPassword=Me.SmForm.ControlDictionary()("txtPassword")
            
            SysLogin.FormLoad(txtUser,chkUser,btnCancel)
        End Sub
        Public Sub 用户登陆窗口_AfterLoad(sender As Object,e As  System.EventArgs)
            SysLogin.FormAfterLoad(txtUser,chkUser,btnCancel,picBigLogo,Me.SmForm)
        End Sub
        Public Sub btnCancel_Click(sender As Object,e As  System.EventArgs)
            SysLogin.ButtonCancelClick(Me.SmForm,btnResetPassword)
        End Sub
        
        Public Sub btnConfirm_Click(sender As Object,e As  System.EventArgs)
            SysLogin.ButtonConfirmClick(txtUser,txtPassword,chkUser,chkPassword,Me.SmForm)
        End Sub
        
        Public Sub btnResetPassword_Click(sender As Object,e As  System.EventArgs)
            SysLogin.ButtonResetPasswordClick()
        End Sub
        
        Public Sub txtUser_ValueChanged(sender As Object,e As  System.EventArgs)
            SysLogin.TextBoxUserValueChanged(txtUser,txtPassword,chkPassword)
        End Sub
        
        Public Sub 用户登陆窗口_FormClosing(sender As Object,e As  System.Windows.Forms.FormClosingEventArgs)
            SysLogin.FormLoginClosing(Me.SmForm)
        End Sub
        
    End Class
End Namespace

C#
using System;
using System.Text;
using System.IO;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
using System.Windows.Forms;
using System.Reflection;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using sanMuSoft.Utility;
using sanMuSoft.Data.Pivot;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Data.Common;
using System.Net.Http;
using C1.C1Excel;
using C1.C1Zip;
using C1.Win.C1Command;
using C1.Win.C1FlexGrid;
using C1.Win.C1Input;
using C1.Win.C1Ribbon;
using C1.Win.C1Themes;
using sanMuSoft.CS.Framework;
using sanMuSoft.CS.Framework.Editor;
using sanMuSoft.CS.Framework.FormDesigner;
using sanMuSoft.CS.Framework.DropDownForms;
using sanMuSoft.CS.WinForm;
using sanMuSoft.CS.WinForm.Editor;
using sanMuSoft.CS.WinForm.Controls;
using sanMuSoft.CS.WinForm.Controls.Grid;
using sanMuSoft.CS.WinForm.Controls.BoxControls;
using sanMuSoft.CS.Workflow;
using sanMuSoft.CS.Report;
using sanMuSoft.Data;
using sanMuSoft.Data.TableBuilder;
using sanMuSoft.CS.ShareFunc;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Aliyun.OSS;

namespace FormEvents
{
    public class Form747e4dbd2d5548198e0735c1c4f7fefd: FormEventsBase
    {
        private SmButton btnCancel;
        private SmCheckBox chkPassword;
        private SmCheckBox chkUser;
        private SmTextBox txtPassword;
        private SmComboBox txtUser;
        private SmButton btnResetPassword;
        public void 用户登陆窗口CSharp_Load(object sender, System.EventArgs e)
        {
            //初始化控件引用
            btnCancel = this.SmForm.ControlDictionary()["btnCancel"] as SmButton ;
            chkPassword = this.SmForm.ControlDictionary()["chkPassword"] as SmCheckBox ;
            chkUser = this.SmForm.ControlDictionary()["chkUser"] as SmCheckBox ;
            txtPassword = this.SmForm.ControlDictionary()["txtPassword"] as SmTextBox ;
            txtUser = this.SmForm.ControlDictionary()["txtUser"] as SmComboBox ;            
            btnResetPassword = this.SmForm.ControlDictionary()["btnResetPassword"] as SmButton ;
            

            SysLogin.FormLoad(txtUser,chkUser,btnCancel);
        }
        public void btnCancel_Click(object sender, System.EventArgs e)
        {
            SysLogin.ButtonCancelClick(this.SmForm,btnResetPassword);
        }
        
        public void btnConfirm_Click(object sender, System.EventArgs e)
        {
            SysLogin.ButtonConfirmClick(txtUser,txtPassword,chkUser,chkPassword,this.SmForm);
        }
        
        public void btnResetPassword_Click(object sender, System.EventArgs e)
        {
            SysLogin.ButtonResetPasswordClick();
        }
        
        public void txtUser_ValueChanged(object sender, System.EventArgs e)
        {
            SysLogin.TextBoxUserValueChanged(txtUser,txtPassword,chkPassword);
        }
        
        public void 用户登陆窗口CSharp_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            SysLogin.FormLoginClosing(this.SmForm);
        }
        
        public void 用户登陆窗口CSharp_AfterLoad(object sender, System.EventArgs e)
        {
            SmPictureBox picBigLogo = this.SmForm.ControlDictionary()["picBigLogo"] as SmPictureBox ;
            SysLogin.FormAfterLoad(txtUser,chkUser,btnCancel,picBigLogo,this.SmForm);
        }
        
    }
}

第三步,在项目事件BeforeOpenUserLoginForm中,将e.LoginForm赋值一个自己自定义的登陆窗体即可。

窗体模板可以到论坛下面地址下载:

【分享】自定义登陆窗口模板 - 功能分享 - 苏州三木软件科技有限公司 - SanMuGrid森之格