winform窗体模板_如何验证角模板驱动的窗体

winform窗体模板

介绍 (Introduction)

In this article, we will learn about validations in Angular template-driven forms. We will create a simple user registration form and implement some inbuilt validations on it. Along with the inbuilt validations, we will also implement some custom validations for the template-driven form.

在本文中,我们将学习Angular模板驱动形式的验证。 我们将创建一个简单的用户注册表单,并在其上实现一些内置的验证。 除了内置的验证,我们还将为模板驱动的表单实现一些自定义验证。

We will consider the following custom validations for this demo:

我们将为此演示考虑以下自定义验证:

  • Checking for user name availability

    检查用户名可用性
  • Password pattern validation

    密码模式验证
  • Matching the password entered in two different fields

    匹配在两个不同字段中输入的密码

Take a look at the application in action.

看一下实际的应用程序。

先决条件 (Prerequisites)

  • Install Visual Studio code from here

    这里安装Visual Studio代码

  • Install the latest version of Angular CLI from here

    此处安装最新版本的Angular CLI

  • Install the latest LTS version of Node.js from here

    此处安装最新的LTS版本的Node.js

源代码 (Source Code)

You can get the source code from GitHub.

您可以从GitHub获取源代码。

创建Angular应用 (Create the Angular app)

Navigate to the folder where you want to create your project file. Open a command window and run the command shown below:

导航到要在其中创建项目文件的文件夹。 打开命令窗口并运行以下命令:

ng new angular-forms-validation --routing=false --style=scss

We are specifying the command to create a new Angular application. The option to create the routing module is set to false and style files extension is set to SCSS. This command will create the Angular project with the name angular-forms-validation.

我们正在指定创建新Angular应用程序的命令。 创建路由模块的选项设置为false,样式文件扩展名设置为SCSS。 此命令将使用名称angular-forms-validation创建Angular项目。

Change directories to the new project and open the project in VS Code using the set of commands below:

将目录更改为新项目,并使用以下命令集在VS Code中打开项目:

cd angular-forms-validation
code .

安装引导程序 (Install Bootstrap)

Run the following command to install Bootstrap:

运行以下命令以安装Bootstrap:

npm install bootstrap --save

Add the following import definition in the styles.scss file:

styles.scss文件中添加以下导入定义:

@import "~bootstrap/dist/css/bootstrap.css";

创建验证服务 (Create the validation service)

Run the following command to create a new service:

运行以下命令以创建新服务:

ng g s services\customvalidation

This command will create a folder named services that has two files inside it – customvalidation.service.ts and customvalidation.service.spec.ts. Open customvalidation.service.ts and put the following code inside it:

此命令将创建一个名为services的文件夹,其中有两个文件– customvalidation.service.tscustomvalidation.service.spec.ts 。 打开customvalidation.service.ts并将以下代码放入其中:

import { Injectable } from '@angular/core';
import { ValidatorFn, AbstractControl } from '@angular/forms';
import { FormGroup } from '@angular/forms';

@Injectable({
  providedIn: 'root'
})
export class CustomvalidationService {

  patternValidator(): ValidatorFn {
    return (control: AbstractControl): { [key: string]: any } => {
      if (!control.value) {
        return null;
      }
      const regex = new RegExp('^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{8,}$');
      const valid = regex.test(control.value);
      return valid ? null : { invalidPassword: true };
    };
  }

  MatchPassword(password: string, confirmPassword: string) {
    return (formGroup: FormGroup) => {
      const passwordControl = formGroup.controls[password];
      const confirmPasswordControl = formGroup.controls[confirmPassword];

      if (!passwordControl || !confirmPasswordControl) {
        return null;
      }

      if (confirmPasswordControl.errors && !confirmPasswordControl.errors.passwordMismatch) {
        return null;
      }

      if (passwordControl.value !== confirmPasswordControl.value) {
        confirmPasswordControl.setErrors({ passwordMismatch: true });
      } else {
        confirmPasswordControl.setErrors(null);
      }
    }
  }

  userNameValidator(userControl: AbstractControl) {
    return new Promise(resolve => {
      setTimeout(() => {
        if (this.validateUserName(userControl.value)) {
          resolve({ userNameNotAvailable: true });
        } else {
          resolve(null);
        }
      }, 1000);
    });
  }

  validateUserName(userName: string) {
    const UserList = ['ankit', 'admin', 'user', 'superuser'];
    return (UserList.indexOf(userName) > -1);
  }
}

The method patternValidator is used to validate the password pattern in our form. The parameter for this method is of type AbstractControl which is a base class for the FormControl.

patternValidator方法用于验证表单中的密码模式。 此方法的参数类型为AbstractControl ,它是FormControl的基类。

We will use a regular expression to validate the password. This regular expression will check for the following four conditions in the password:

我们将使用正则表达式来验证密码。 此正则表达式将检查密码中的以下四个条件:

  • The password should be a minimum of eight characters long

    密码长度至少为八个字符
  • It should have at least one lower case letter

    至少应有一个小写字母
  • It should have at least one upper case letter

    它应该至少包含一个大写字母
  • It should have at least one number

    它应该至少有一个数字

If the password fails the regex check, we will set the invalidPassword property to true.

如果密码未通过正则表达式检查,我们会将invalidPassword属性设置为true。

The method MatchPassword is used to compare the passwords in two fields. This method will accept two parameters of type string. These parameters represent the name of the fields to be matched. We will get the FormControl for these two fields and then match the values in them. If the values do not match, we will set the passwordMismatch property to true.

MatchPassword方法用于比较两个字段中的密码。 此方法将接受两个字符串类型的参数。 这些参数表示要匹配的字段的名称。 我们将获得这两个字段的FormControl ,然后匹配它们中的值。 如果值不匹配,我们将passwordMismatch属性设置为true。

The method userNameValidator is used to verify if the username is already taken or not. This method will accept a parameter of type AbstractControl.

方法userNameValidator用于验证用户名是否已被使用。 此方法将接受类型为AbstractControl的参数。

We will check if the value of this field is present in a static array, UserList. If the value entered by the user is already present, we will set the userNameNotAvailable property to true.

我们将检查此字段的值是否存在于静态数组UserList中。 如果用户输入的值已经存在,则将userNameNotAvailable属性设置为true。

We are using the setTimeout function to invoke this check every two seconds. This will ensure that the error will be thrown after two seconds from the time the user stops typing in the field.

我们正在使用setTimeout函数每两秒钟调用一次此检查。 这将确保从用户停止在该字段中键入内容起两秒钟后将引发该错误。

For the sake of simplicity of this article, we are using a static array to search for the availability of user names. Ideally, it should be a service call to the server to search for the value in a database.

为了简化本文,我们使用静态数组来搜索用户名的可用性。 理想情况下,应该是对服务器的服务调用,以在数据库中搜索值。

创建用户模型 (Create the User model)

Create a new folder called models inside the src/app folder. Add a new file called user.ts inside the models folder. Put the following code in the user.ts file.

src/app文件夹中创建一个名为models的新文件夹。 在models文件夹中添加一个名为user.ts的新文件。 将以下代码放入user.ts文件中。

export class User {
    public name: string;
    public email: string;
    public username: string;
    public password: string;
    public confirmPassword: string;
}

创建自定义指令 (Create custom directives)

We will create custom directives to implement custom validators for template-driven forms.

我们将创建自定义指令,以为模板驱动的表单实现自定义验证器。

Run the command shown below to create the passwordPattern directive:

运行下面显示的命令以创建passwordPattern指令:

ng g d directives\passwordPattern

This command will create a folder named directives that has two files inside it – passwordPattern.directive.ts and passwordPattern.directive.spec.ts. Open passwordPattern.directive.ts and put the following code inside it.

此命令将创建一个名为指令的文件夹,其中有两个文件– passwordPattern.directive.tspasswordPattern.directive.spec.ts 。 打开passwordPattern.directive.ts并将以下代码放入其中。

import { Directive } from '@angular/core';
import { NG_VALIDATORS, Validator, AbstractControl } from '@angular/forms';
import { CustomvalidationService } from '../services/customvalidation.service';

@Directive({
  selector: '[appPasswordPattern]',
  providers: [{ provide: NG_VALIDATORS, useExisting: PasswordPatternDirective, multi: true }]
})
export class PasswordPatternDirective implements Validator {

  constructor(private customValidator: CustomvalidationService) { }

  validate(control: AbstractControl): { [key: string]: any } | null {
    return this.customValidator.patternValidator()(control);
  }
}

This directive is used to validate the password pattern. We will implement the Validator interface on the class PasswordPatternDirective. We will override the validate method which accepts a parameter of type AbstractControl, that is the control we want to validate. We will then invoke the patternValidator method from the service.

此伪指令用于验证密码模式。 我们将在类PasswordPatternDirective上实现Validator接口。 我们将覆盖validate方法,该方法接受类型为AbstractControl的参数,这是我们要验证的控件。 然后,我们将从服务中调用patternValidator方法。

Run the command shown below to create the matchPassword directive:

运行以下所示的命令以创建matchPassword指令:

ng g d directives\matchPassword

Open matchPassword.directive.ts and put the following code inside it:

打开matchPassword.directive.ts并将以下代码放入其中:

import { Directive, Input } from '@angular/core';
import { NG_VALIDATORS, Validator, ValidationErrors, FormGroup } from '@angular/forms';
import { CustomvalidationService } from '../services/customvalidation.service';

@Directive({
  selector: '[appMatchPassword]',
  providers: [{ provide: NG_VALIDATORS, useExisting: MatchPasswordDirective, multi: true }]
})
export class MatchPasswordDirective implements Validator {
  @Input('appMatchPassword') MatchPassword: string[] = [];

  constructor(private customValidator: CustomvalidationService) { }

  validate(formGroup: FormGroup): ValidationErrors {
    return this.customValidator.MatchPassword(this.MatchPassword[0], this.MatchPassword[1])(formGroup);
  }
}

This directive is used to validate if the passwords entered in two fields are matching or not. This directive will accept an input of the type string array, which contains the fields to match. We will override the validate method and pass the parameter of type FormGroup. We will then invoke the MatchPassword method from the service.

此伪指令用于验证在两个字段中输入的密码是否匹配。 该指令将接受类型为字符串数组的输入,其中包含要匹配的字段。 我们将覆盖validate方法,并传递FormGroup类型的参数。 然后,我们将从服务中调用MatchPassword方法。

Run the command shown below to create the validateUserName directive:

运行下面显示的命令以创建validateUserName指令:

ng g d directives\validateUserName

Open validateUserName.directive.ts and put the following code inside it:

打开validateUserName.directive.ts并将以下代码放入其中:

import { Directive, forwardRef } from '@angular/core';
import { Validator, AbstractControl, NG_ASYNC_VALIDATORS } from '@angular/forms';
import { CustomvalidationService } from '../services/customvalidation.service';
import { Observable } from 'rxjs';

@Directive({
  selector: '[appValidateUserName]',
  providers: [{ provide: NG_ASYNC_VALIDATORS, useExisting: forwardRef(() => ValidateUserNameDirective), multi: true }]

})
export class ValidateUserNameDirective implements Validator {

  constructor(private customValidator: CustomvalidationService) { }

  validate(control: AbstractControl): Promise<{ [key: string]: any }> | Observable<{ [key: string]: any }> {
    return this.customValidator.userNameValidator(control);
  }
}

This directive is used to validate the availability of the user name. We will override the validate method and pass the parameter of type AbstractControl. We will then invoke the userNameValidator method from the service. This method will return a promise.

该伪指令用于验证用户名的可用性。 我们将覆盖validate方法并传递类型AbstractControl的参数。 然后,我们将从服务中调用userNameValidator方法。 此方法将返回一个承诺。

创建模板驱动的表单组件 (Create the template-driven form component)

Run the command shown below to create the template-driven-form component:

运行下面显示的命令以创建模板驱动表单组件:

ng g c template-driven-form

Open template-driven-form.component.ts and put the following code in it:

打开template-driven-form.component.ts并将以下代码放入其中:

import { Component } from '@angular/core';
import { User } from '../models/user';

@Component({
  selector: 'app-template-driven-form',
  templateUrl: './template-driven-form.component.html',
  styleUrls: ['./template-driven-form.component.scss']
})
export class TemplateDrivenFormComponent {

  userModal = new User();

  constructor() { }

  onSubmit() {
    alert('Form Submitted succesfully!!!\n Check the values in browser console.');
    console.table(this.userModal);
  }
}

We have created an object userModal of type User. We will bind the form fields with the property of this object. The onSubmit method will show the success message on the screen and print the contents of the form to the console.

我们已经创建了类型为User的对象userModal 。 我们将表单域与该对象的属性绑定。 onSubmit方法将在屏幕上显示成功消息,并将表单内容打印到控制台。

Open template-driven-form.component.html and put the following code in it:

打开template-driven-form.component.html并将以下代码放入其中:

<div class="container">
    <div class="row">
        <div class="col-md-8 mx-auto">
            <div class="card">
                <div class="card-header">
                    <h3>Angular Template-driven Form</h3>
                </div>
                <div class="card-body">
                    <form class="form" #registerForm="ngForm" [appMatchPassword]="['password', 'confirmPassword']"
                        (ngSubmit)="registerForm.form.valid && onSubmit()" novalidate>
                        <div class=" form-group">
                            <label>Name</label>
                            <input type="text" class="form-control" [(ngModel)]="userModal.name" name="name"
                                #name="ngModel" required>
                            <span class="text-danger"
                                *ngIf="(name.touched || registerForm.submitted) && name.errors?.required">
                                Name is required
                            </span>
                        </div>
                        <div class="form-group">
                            <label>Email</label>
                            <input type="text" class="form-control" [(ngModel)]="userModal.email" name="email"
                                #email="ngModel" required email>
                            <span class="text-danger"
                                *ngIf="(email.touched || registerForm.submitted) && email.errors?.required">
                                Email is required
                            </span>
                            <span class="text-danger" *ngIf="email.touched && email.errors?.email">
                                Enter a valid email address
                            </span>
                        </div>
                        <div class="form-group">
                            <label>User Name</label>
                            <input type="text" class="form-control" [(ngModel)]="userModal.username" name="username"
                                #username="ngModel" appValidateUserName required>
                            <span class="text-danger"
                                *ngIf="(username.touched || registerForm.submitted) && username.errors?.required">
                                User Name is required
                            </span>
                            <span class="text-danger" *ngIf="username.touched && username.errors?.userNameNotAvailable">
                                User Name not available
                            </span>
                        </div>
                        <div class="form-group">
                            <label>Password</label>
                            <input type="password" class="form-control" [(ngModel)]="userModal.password" name="password"
                                #password="ngModel" appPasswordPattern required>
                            <span class="text-danger"
                                *ngIf="(password.touched || registerForm.submitted) && password.errors?.required">
                                Password is required
                            </span>
                            <span class="text-danger" *ngIf="password.touched && password.errors?.invalidPassword">
                                Password should have minimum 8 characters, at least 1 uppercase letter, 1 lowercase
                                letter and 1 number
                            </span>
                        </div>
                        <div class="form-group">
                            <label>Confirm Password</label>
                            <input type="password" class="form-control" [(ngModel)]="userModal.confirmPassword"
                                name="confirmPassword" #confirmPassword="ngModel" required>
                            <span class="text-danger"
                                *ngIf="(confirmPassword.touched || registerForm.submitted) && confirmPassword.errors?.required">
                                Confirm Password is required
                            </span>
                            <span class="text-danger"
                                *ngIf="confirmPassword.touched && confirmPassword.errors?.passwordMismatch">
                                Passwords doesnot match
                            </span>
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-success">Register</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

We will create a template-driven form and use the Bootstrap card for styling. The card header will contain a title whereas the card body will have the form fields.

我们将创建一个模板驱动的表单,并使用Bootstrap卡进行样式设置。 卡片标题将包含标题,而卡片正文将具有表单字段。

We will use the appMatchPassword directive on our form and pass the password and confirmPassword fields for validation. The ngModel property is used to bind the form control to the model.

我们将在appMatchPassword上使用appMatchPassword指令,并传递密码和confirmPassword字段进行验证。 ngModel属性用于将表单控件绑定到模型。

For validating the user name availability we will use the appValidateUserName directive on the username field. Similarly, we will use the appPasswordPattern directive on the password field to validate the password pattern.

为了验证用户名的可用性,我们将在用户名字appValidateUserName上使用appValidateUserName指令。 同样,我们将在密码字段上使用appPasswordPattern指令来验证密码模式。

We will check for the errors in the form controls and then display the appropriate validation error message on the screen.

我们将检查表单控件中的错误,然后在屏幕上显示相应的验证错误消息。

创建导航栏组件 (Create the nav-bar component)

Run the command shown below to create the nav-bar component:

运行下面显示的命令以创建导航栏组件:

ng g c nav-bar

Open nav-bar.component.html and put the following code in it:

打开nav-bar.component.html并将以下代码放入其中:

<nav class="navbar navbar-expand-sm navbar-dark bg-dark fixed-top">
    <a class="navbar-brand" [routerLink]='["/"]'>Form Validation Demo</a>
    <div class="collapse navbar-collapse">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item">
                <a class="nav-link" [routerLink]='["/template-form"]'>Template Form</a>
            </li>
        </ul>
    </div>
</nav>

Here we are adding the navigation link to the template-driven form component.

在这里,我们将导航链接添加到模板驱动的表单组件。

更新应用程序组件 (Update the app component)

Open the app.component.html file and put the following code in it:

打开app.component.html文件,并将以下代码放入其中:

<app-nav-bar></app-nav-bar>
<div class="container">
  <router-outlet></router-outlet>
</div>

更新应用程序模块 (Update the App module)

We will import the forms module and also set up the routing for our application in the app module. Add the following code in the app.module.ts file. You can refer to GitHub for the complete source code of this file:

我们将导入表单模块,并在app模块中为我们的应用程序设置路由。 在app.module.ts文件中添加以下代码。 您可以参考GitHub以获得此文件的完整源代码:

import { RouterModule } from '@angular/router';
import { FormsModule } from  '@angular/forms';

@NgModule({
  ...    
  imports: [
    ...
    FormsModule,
    RouterModule.forRoot([
      { path: '', component: TemplateDrivenFormComponent },
      { path: 'template-form', component: TemplateDrivenFormComponent }
    ]),
  ],
})

执行演示 (Execution demo)

Use the following command to start the webserver:

使用以下命令启动网络服务器:

ng serve -o

This command will launch the application in your default browser at http://localhost:4200/. You can perform all the form validations which we have discussed here.

此命令将在您的默认浏览器http://localhost:4200/启动应用程序。 您可以执行我们在此处讨论的所有表单验证。

This application is also hosted at https://ng-forms-validation.herokuapp.com/. Navigate to the link and play around with it for a better understanding.

此应用程序还托管在https://ng-forms-validation.herokuapp.com/上 。 导航至该链接,并对其进行处理以更好地理解。

摘要 (Summary)

We have created a sample user registration form using the template-driven form approach in Angular. We have implemented the inbuilt validations as well as custom validations to the form. The Bootstrap library is used to style the form.

我们使用Angular中的模板驱动表单方法创建了一个示例用户注册表单。 我们已经实现了表单的内置验证以及自定义验证。 Bootstrap库用于设置表单样式。

Get the source code from GitHub and play around with it for a better understanding.

GitHub获取源代码并试用它,以更好地理解。

也可以看看 (See Also)

You can find this post Template-Driven Form Validation In Angular and others like it on Ankit Sharma's Blog.

您可以在Ankit Sharma的Blog上找到这篇文章Angular中的模板驱动表单验证和其他类似文章

翻译自: https://www.freecodecamp.org/news/how-to-validate-angular-template-driven-forms/

winform窗体模板

第2章 QQ企业通    2.1 设计思路 28   2.2 关键技术 28   2.2.1 INI文件的应用 28   2.2.2 线程的应用 30   2.2.3 在Socket中发送大容量的消息 30   2.2.4 将流序列化或反序列化为对象 31   2.2.5 用InnerList列表记录信息 31   2.3 设计过程 32   2.3.1 类库的设计 33   2.3.2 客户端注册模块设计 40   2.3.3 客户端登录模块设计 42   2.3.4 客户端QQ模块设计 43   2.3.5 客户端消息发送模块设计 48   2.3.6 服务器端控制台模块设计 52 第3章 SQL数据表提取器模块    3.1 概述 56   3.2 关键技术 56   3.2.1 如何备份数据库 56   3.2.2 如何还原数据库 57   3.2.3 如何附加数据库 58   3.2.4 如何分离数据库 59   3.2.5 设置数据库模式 59   3.3 设计过程 61   3.3.1 主窗体 61   3.3.2 获取服务器名称 62   3.3.3 获取所有数据库 63   3.3.4 获取所有数据表 64   3.3.5 备份数据库 66   3.3.6 还原数据库 67   3.3.7 附加数据库 68   3.3.8 分离数据库 70   3.3.9 导出表结构 71   3.3.10 导出数据 74 第4章 万能搜索模块    4.1 设计思路 80   4.2 关键技术 80   4.2.1 如何制作一个接口程序 80   4.2.2 实现接口程序的信息互传 80   4.2.3 如何将接口程序加载到其他程序中 82   4.2.4 怎样操作RichtextBox控件的选择文本 82   4.2.5 如何获取数据表中字段的描述信息 83   4.3 设计过程 83   4.3.1 获取数据表中字段的中文信息 84   4.3.2 添加数据表的查询条件 86   4.3.3 向SQL语句中添加括号 89   4.3.4 查询生成后的SQL语句 90   4.3.5 主程序获得接口信息 92 第5章 万能打印模块    5.1 设计思路 94   5.2 关键技术 94   5.2.1 打印设置(PrintDocument类) 94   5.2.2 打印预览对话框(PrintPreview Dialog) 95   5.2.3 打印对话框(PrintDialog) 96   5.2.4 获取指定颜色值和字体样式 97   5.2.5 DataGridView控件的相关应用 97   5.3 设计过程 98   5.3.1 打印信息的设置 98   5.3.2 表格样式的设置 100   5.3.3 打印类的设置 101   5.3.4 打印数据信息 108 第6章 决策分析模块    6.1 设计思路 112   6.2 关键技术 112   6.2.1 游标的基本操作 112   6.2.2 存储过程的基本操作 115   6.2.3 透视表的基本概念 117   6.2.4 统计表的基本操作 117   6.2.5 单击显示右键菜单 118   6.3 设计过程 118   6.3.1 主窗体的初始化 119   6.3.2 透视表的筛选 127   6.3.3 透视表的设计 130   6.3.4 统计表的设计 132 第7章 自定义图表控件    7.1 设计思路 136   7.2 关键技术 137   7.2.1 控件的生成 137   7.2.2 如何在项目中添加控件 137   7.2.3 在“属性”对话框中添加属性 137   7.2.4 用GDI+绘制图形 139   7.2.5 如何在控件上绘制图形 143   7.2.6 获取扇形外弧中心点的位置 143   7.3 设计过程 144   7.3.1 向自定义控件中添加属性 144   7.3.2 获取绘制图表的初始值数据 149   7.3.3 绘制标签框 153   7.3.4 绘制图表中的表格 157   7.3.5 绘制条形图 163   7.3.6 绘制面形图 170   7.3.7 绘制饼形图 174 第8章 电子邮件收发模块    8.1 概述 180   8.2 关键技术 180   8.2.1 Base64编码格式 180   8.2.2 SMTP服务 181   8.2.3 POP3协议 184   8.2.4 使用Jmail组件接收邮件 186   8.2.5 邮件发送类的使用 188   8.2.6 使用正则表达式验证邮件格式 190   8.3 设计过程 191   8.3.1 数据库设计 191   8.3.2 系统登录 191   8.3.3 邮件发送实现 192   8.3.4 为邮件上传多个附件 193   8.3.5 邮件接收实现 194   8.3.6 查看邮件详细信息 196   8.3.7 下载附件的实现 197   8.3.8 删除邮件实现 198   8.3.9 用户管理 198 第9章 短信群发模块    9.1 设计思路 202   9.2 关键技术 202   9.2.1 短信猫中API函数的使用 202   9.2.2 短信猫中的短信接收格式 205   9.2.3 窗体间的互操作 205   9.2.4 锁定模块主窗体 206   9.2.5 使用ADO.NET连接Access数据库 206   9.3 设计过程 207   9.3.1 数据库设计 207   9.3.2 群发短信实现 209   9.3.3 已发送短信管理 213   9.3.4 接收短信实现 215   9.3.5 常用联系人管理 219   9.3.6 常用短语管理 221 第10章 桌面精灵模块    10.1 概述 226   10.2 关键技术 226   10.2.1 阴阳历转换算法 226   10.2.2 调用系统API实现鼠标穿透效果 230   10.2.3 修改注册表控制程序开机自启动 231   10.2.4 通过控制窗体透明度实现日历透明显示效果 231   10.2.5 拖动无标题栏窗体 232   10.2.6 将窗体的关闭位置写入到注册表中 232   10.2.7 将程序图标写入到托盘 232   10.3 设计过程 233   10.3.1 桌面精灵模块公共类设计 233   10.3.2 当前日期的农历、天干地支年、节日及星座显示 235   10.3.3 定时提醒的实现 240   10.3.4 日历窗体效果控制 242   10.3.5 转到某天、某周、某月及某年的实现 243   10.3.6 节日管理 245   10.3.7 提醒管理 249 第11章 文件批量处理器    11.1 概述 256   11.2 关键技术 256   11.2.1 文件流技术 256   11.2.2 文件解压缩技术 258   11.2.3 获取系统文件及文件夹图标 262   11.2.4 获取指定目录下的所有文件及文件夹 265   11.2.5 Word操作技术 266   11.2.6 进度条的显示 266   11.2.7 对ListView控件中的项进行排序 267   11.3 设计过程 267   11.3.1 主窗体预览 267   11.3.2 批量复制、剪切文件 268   11.3.3 批量复制、剪切文件夹 270   11.3.4 批量重命名文件 271   11.3.5 批量删除文件及文件夹 275   11.3.6 搜索文件及文件夹 276   11.3.7 批量压缩、解压文件 278   11.3.8 分割、合并文件 280 第12章 图片管理工具模块    12.1 概述 286   12.2 关键技术 286   12.2.1 上下移动ListBox选中项 286   12.2.2 将文件复制到剪切板 287   12.2.3 格式转换 288   12.2.4 图片幻灯片 288   12.2.5 图片旋转 289   12.3 设计过程 290   12.3.1 主窗体 290   12.3.2 打开图片目录 291   12.3.3 图片格式转换 292   12.3.4 设为桌面背景 294   12.3.5 图片特效 296   12.3.6 图片调节 300   12.3.7 图片水印 304   12.3.8 幻灯片放映 306   12.3.9 图片打印 308 、
一、应用场景与出发点 同一个系统中,为了解决不同的客户可能需要设计不同的单据打印模板,实现此方法可能是: 1、设计不同的自带RDLC报表文件,根据当前客户加载不同的报表并打印 2、GDI+绘图 和 打印组件 ,不同的客户创建不同的绘图XML格式的模板内容 3、其他第三方组件 主要对比一下前两种方法,第一种方法不好之处在于,不灵活,开发者必须地每个客户制订一个报表,不推荐采用。第二种方法,修改对应的模板内容就可以了, 模板内容可以是Xml文件,也可以是存放在数据库中的Xml格式字符串。推荐采用这种方法。然后这种方法的也有一个棘手问题 :如何让用户快速、方便地设计打印模板,本示例就是为了解决这个问题。 二、实现思路与原理 功能概要:设计一个界面,支持用户自由添加 要打印的项,文本,直线,图片 等,并且可以方便改变打印项的 字体、颜色、粗细、位置,设计时支持效果预览。 技术要点:GDI+绘图、拖动控件、XML解析、自定义控件 三、相关类介绍 绘图工具类:DrawHelper 实现 xml格式模板 与 打印项 之间进行互相转换,在目标画板中绘制 拖动工具类:WinHelper 实现控件的鼠标拖动,键盘移动 自定义控件:用于显示文字的文本框 TextBoxExt、用于显示直线的标签 LabelExt 主窗体代码:用于用户操作,添加,删除,编辑,打印项 详细介绍请参照我的博文:http://de.cel.blog.163.com/blog/static/51451236201472215450939/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值