/// <summary>/// 为Form1注入一个方法/// </summary>
public static class MyFormExt
{
public staticvoidTest(this Form1 form1){
MessageBox.Show("扩展Form类");}}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp11
{
public partial class Form1 : Form
{
public Form1(){InitializeComponent();}
private voidForm1_Load(object sender, EventArgs e){
Form1 form1 = new Form1();
form1.Test();}}/// <summary>/// 为Form1注入一个方法/// </summary>
public static class MyFormExt
{
public staticvoidTest(this Form1 form1){
MessageBox.Show("扩展Form类");}}}