📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace HatchSelection
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
HatchBrush _panelBrush = null;
private System.Windows.Forms.ComboBox hatchStyleCombo;
private System.Windows.Forms.Panel panel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
hatchStyleCombo.SelectedIndex = 0;
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.hatchStyleCombo = new System.Windows.Forms.ComboBox();
this.panel = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// hatchStyleCombo
//
this.hatchStyleCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.hatchStyleCombo.Items.AddRange(new object[] {
"BackwardDiagonal",
"Cross",
"DarkDownwardDiagonal",
"DarkHorizontal",
"DarkUpwardDiagonal",
"DarkVertical",
"DashedDownwardDiagonal",
"DashedHorizontal",
"DashedUpwardDiagonal",
"DashedVertical",
"DiagonalBrick",
"DiagonalCross",
"Divot",
"DottedDiamond",
"DottedGrid",
"ForwardDiagonal",
"Horizontal",
"HorizontalBrick",
"LargeCheckerBoard",
"LargeConfetti",
"LargeGrid",
"LightDownwardDiagonal",
"LightHorizontal",
"LightUpwardDiagonal",
"LightVertical",
"Max",
"Min",
"NarrowHorizontal",
"NarrowVertical",
"OutlinedDiamond",
"Percent05",
"Percent10",
"Percent20",
"Percent25",
"Percent30",
"Percent40",
"Percent50",
"Percent60",
"Percent70",
"Percent75",
"Percent80",
"Percent90",
"Plaid",
"Shingle",
"SmallCheckerBoard",
"SmallConfetti",
"SmallGrid",
"SolidDiamond",
"Sphere",
"Trellis",
"Vertical",
"Wave",
"Weave",
"WideDownwardDiagonal",
"WideUpwardDiagonal",
"ZigZag"});
this.hatchStyleCombo.Location = new System.Drawing.Point(40, 32);
this.hatchStyleCombo.MaxDropDownItems = 28;
this.hatchStyleCombo.Name = "hatchStyleCombo";
this.hatchStyleCombo.Size = new System.Drawing.Size(208, 21);
this.hatchStyleCombo.TabIndex = 1;
this.hatchStyleCombo.SelectionChangeCommitted += new System.EventHandler(this.hatchStyleCombo_SelectionChangeCommitted);
//
// panel
//
this.panel.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.panel.Location = new System.Drawing.Point(0, 88);
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size(296, 224);
this.panel.TabIndex = 2;
this.panel.Paint += new System.Windows.Forms.PaintEventHandler(this.panel_Paint);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 310);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel,
this.hatchStyleCombo});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MainForm";
this.Text = "HatchBrush Example";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void hatchStyleCombo_SelectionChangeCommitted(object sender, System.EventArgs e)
{
if(_panelBrush != null)
_panelBrush.Dispose();
switch((string)hatchStyleCombo.SelectedItem)
{
case "BackwardDiagonal":
_panelBrush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.White, Color.Black);
break;
case "Cross":
_panelBrush = new HatchBrush(HatchStyle.Cross, Color.White, Color.Black);
break;
case "DarkDownwardDiagonal":
_panelBrush = new HatchBrush(HatchStyle.DarkDownwardDiagonal, Color.White, Color.Black);
break;
case "DarkHorizontal":
_panelBrush = new HatchBrush(HatchStyle.DarkHorizontal, Color.White, Color.Black);
break;
case "DarkUpwardDiagonal":
_panelBrush = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Color.White, Color.Black);
break;
case "DarkVertical":
_panelBrush = new HatchBrush(HatchStyle.DarkVertical, Color.White, Color.Black);
break;
case "DashedDownwardDiagonal":
_panelBrush = new HatchBrush(HatchStyle.DashedDownwardDiagonal, Color.White, Color.Black);
break;
case "DashedHorizontal":
_panelBrush = new HatchBrush(HatchStyle.DashedHorizontal, Color.White, Color.Black);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -