把PathGradientBrush的属性设置放在一个界面里,可以看出整体效果来,效果还不错: (做一次更新,加了一些旋转、位移的设置)。 https://p-blog.youkuaiyun.com/images/p_blog_youkuaiyun.com/fdd2009/EntryImages/20090719/PathGradientBrush-App.jpg using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; using System.Collections; using System.Reflection; using System.Diagnostics; using System.Text; namespace TestApp { public class Form1 : Form { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } public Form1() { InitializeComponent(); MyInitialize(); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.label1 = new System.Windows.Forms.Label(); this.LabelCenterColor = new System.Windows.Forms.Label(); this.LabelCenterPos = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.DrawingPad = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.LeftBottonColor = new System.Windows.Forms.CheckBox(); this.RightBottonColor = new System.Windows.Forms.CheckBox(); this.RightTopColor = new System.Windows.Forms.CheckBox(); this.label2 = new System.Windows.Forms.Label(); this.LeftTopColor = new System.Windows.Forms.CheckBox(); this.FocusScaleX = new System.Windows.Forms.NumericUpDown(); this.GroupBoxScale = new System.Windows.Forms.GroupBox(); this.RadioRotatTransform = new System.Windows.Forms.RadioButton(); this.RadioScaleTransform = new System.Windows.Forms.RadioButton(); this.RadioTranslateTransform = new System.Windows.Forms.RadioButton(); this.RadioFocusScales = new System.Windows.Forms.RadioButton(); this.FocusScaleY = new System.Windows.Forms.NumericUpDown(); this.label8 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.label9 = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.BlendOk = new System.Windows.Forms.CheckBox(); this.PositionsStr = new System.Windows.Forms.TextBox(); this.FactorsStr = new System.Windows.Forms.TextBox(); this.label11 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.label12 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.FocusScaleX)).BeginInit(); this.GroupBoxScale.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.FocusScaleY)).BeginInit(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.ForeColor = System.Drawing.Color.DeepPink; this.label1.Location = new System.Drawing.Point(16, 61); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(75, 15); this.label1.TabIndex = 3; this.label1.Text = "CenterColor"; // // LabelCenterColor // this.LabelCenterColor.BackColor = System.Drawing.Color.Red; this.LabelCenterColor.Cursor = System.Windows.Forms.Cursors.Hand; this.LabelCenterColor.FlatStyle = System.Windows.Forms.FlatStyle.System; this.LabelCenterColor.Location = new System.Drawing.Point(96, 64); this.LabelCenterColor.Name = "LabelCenterColor"; this.LabelCenterColor.Size = new System.Drawing.Size(41, 12); this.LabelCenterColor.TabIndex = 4; this.LabelCenterColor.Text = "单击"; this.LabelCenterColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.LabelCenterColor.BackColorChanged += new System.EventHandler(this.LabelCenterColor_BackColorChanged); this.LabelCenterColor.Click += new System.EventHandler(this.LabelCenterColor_Click); // // LabelCenterPos // this.LabelCenterPos.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.LabelCenterPos.Cursor = System.Windows.Forms.Cursors.Hand; this.LabelCenterPos.FlatStyle = System.Windows.Forms.FlatStyle.System; this.LabelCenterPos.Location = new System.Drawing.Point(96, 87); this.LabelCenterPos.Name = "LabelCenterPos"; this.LabelCenterPos.Size = new System.Drawing.Size(41, 12); this.LabelCenterPos.TabIndex = 6; this.LabelCenterPos.Text = "单击"; this.LabelCenterPos.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.LabelCenterPos.Click += new System.EventHandler(this.LabelCenterPos_Click); // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label3.ForeColor = System.Drawing.Color.DeepPink; this.label3.Location = new System.Drawing.Point(16, 84); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(74, 15); this.label3.TabIndex = 5; this.label3.Text = "CenterPoint"; // // DrawingPad // this.DrawingPad.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.DrawingPad.Location = new System.Drawing.Point(14, 34); this.DrawingPad.Name = "DrawingPad"; this.DrawingPad.Size = new System.Drawing.Size(295, 176); this.DrawingPad.TabIndex = 8; this.DrawingPad.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.DrawingPad.Paint += new System.Windows.Forms.PaintEventHandler(this.DrawingPad_Paint); this.DrawingPad.DoubleClick += new System.EventHandler(this.DrawingPad_DoubleClick); this.DrawingPad.MouseMove += new System.Windows.Forms.MouseEventHandler(this.DrawingPad_MouseMove); this.DrawingPad.MouseDown += new System.Windows.Forms.MouseEventHandler(this.DrawingPad_MouseDown); // // groupBox1 // this.groupBox1.BackColor = System.Drawing.Color.Bisque; this.groupBox1.Controls.Add(this.label5); this.groupBox1.Controls.Add(this.label6); this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.LeftBottonColor); this.groupBox1.Controls.Add(this.RightBottonColor); this.groupBox1.Controls.Add(this.RightTopColor); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.LeftTopColor); this.groupBox1.Location = new System.Drawing.Point(194, 253); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(139, 91); this.groupBox1.TabIndex = 9; this.groupBox1.TabStop = false; this.groupBox1.Text = "SurroundColors"; // // label5 // this.label5.AutoSize = true; this.label5.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label5.ForeColor = System.Drawing.Color.DeepPink; this.label5.Location = new System.Drawing.Point(70, 60); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(33, 15); this.label5.TabIndex = 12; this.label5.Text = "右下"; // // label6 // this.label6.AutoSize = true; this.label6.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label6.ForeColor = System.Drawing.Color.DeepPink; this.label6.Location = new System.Drawing.Point(6, 21); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(33, 15); this.label6.TabIndex = 13; this.label6.Text = "左上"; // // label4 // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label4.ForeColor = System.Drawing.Color.DeepPink; this.label4.Location = new System.Drawing.Point(70, 21); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(33, 15); this.label4.TabIndex = 11; this.label4.Text = "右上"; // // LeftBottonColor // this.LeftBottonColor.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.LeftBottonColor.Cursor = System.Windows.Forms.Cursors.Hand; this.LeftBottonColor.Location = new System.Drawing.Point(37, 59); this.LeftBottonColor.Name = "LeftBottonColor"; this.LeftBottonColor.Size = new System.Drawing.Size(24, 13); this.LeftBottonColor.TabIndex = 10; this.LeftBottonColor.UseVisualStyleBackColor = false; this.LeftBottonColor.CheckedChanged += new System.EventHandler(this.LeftBottonColor_CheckedChanged); // // RightBottonColor // this.RightBottonColor.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.RightBottonColor.Cursor = System.Windows.Forms.Cursors.Hand; this.RightBottonColor.Location = new System.Drawing.Point(103, 59); this.RightBottonColor.Name = "RightBottonColor"; this.RightBottonColor.Size = new System.Drawing.Size(24, 13); this.RightBottonColor.TabIndex = 11; this.RightBottonColor.UseVisualStyleBackColor = false; this.RightBottonColor.CheckedChanged += new System.EventHandler(this.RightBottonColor_CheckedChanged); // // RightTopColor // this.RightTopColor.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.RightTopColor.Cursor = System.Windows.Forms.Cursors.Hand; this.RightTopColor.Location = new System.Drawing.Point(103, 20); this.RightTopColor.Name = "RightTopColor"; this.RightTopColor.Size = new System.Drawing.Size(24, 13); this.RightTopColor.TabIndex = 10; this.RightTopColor.UseVisualStyleBackColor = false; this.RightTopColor.CheckedChanged += new System.EventHandler(this.RightTopColor_CheckedChanged); // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.ForeColor = System.Drawing.Color.DeepPink; this.label2.Location = new System.Drawing.Point(6, 60); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(33, 15); this.label2.TabIndex = 10; this.label2.Text = "左下"; // // LeftTopColor // this.LeftTopColor.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.LeftTopColor.Cursor = System.Windows.Forms.Cursors.Hand; this.LeftTopColor.Location = new System.Drawing.Point(37, 20); this.LeftTopColor.Name = "LeftTopColor"; this.LeftTopColor.Size = new System.Drawing.Size(24, 13); this.LeftTopColor.TabIndex = 0; this.LeftTopColor.UseVisualStyleBackColor = false; this.LeftTopColor.CheckedChanged += new System.EventHandler(this.LeftTopColor_CheckedChanged); // // FocusScaleX // this.FocusScaleX.DecimalPlaces = 1; this.FocusScaleX.Increment = new decimal(new int[] { 1, 0, 0, 65536}); this.FocusScaleX.Location = new System.Drawing.Point(8, 20); this.FocusScaleX.Minimum = new decimal(new int[] { 100, 0, 0, -2147483648}); this.FocusScaleX.Name = "FocusScaleX"; this.FocusScaleX.Size = new System.Drawing.Size(56, 21); this.FocusScaleX.TabIndex = 12; this.FocusScaleX.ValueChanged += new System.EventHandler(this.FocusScaleX_ValueChanged); // // GroupBoxScale // this.GroupBoxScale.BackColor = System.Drawing.Color.Bisque; this.GroupBoxScale.Controls.Add(this.RadioRotatTransform); this.GroupBoxScale.Controls.Add(this.RadioScaleTransform); this.GroupBoxScale.Controls.Add(this.RadioTranslateTransform); this.GroupBoxScale.Controls.Add(this.RadioFocusScales); this.GroupBoxScale.Controls.Add(this.FocusScaleY); this.GroupBoxScale.Controls.Add(this.label8); this.GroupBoxScale.Controls.Add(this.label7); this.GroupBoxScale.Controls.Add(this.FocusScaleX); this.GroupBoxScale.Location = new System.Drawing.Point(16, 230); this.GroupBoxScale.Name = "GroupBoxScale"; this.GroupBoxScale.Size = new System.Drawing.Size(172, 114); this.GroupBoxScale.TabIndex = 13; this.GroupBoxScale.TabStop = false; this.GroupBoxScale.Text = "FocusScales"; // // RadioRotatTransform // this.RadioRotatTransform.AutoSize = true; this.RadioRotatTransform.BackColor = System.Drawing.Color.LightBlue; this.RadioRotatTransform.Location = new System.Drawing.Point(70, 92); this.RadioRotatTransform.Name = "RadioRotatTransform"; this.RadioRotatTransform.Size = new System.Drawing.Size(29, 16); this.RadioRotatTransform.TabIndex = 22; this.RadioRotatTransform.Text = "4"; this.RadioRotatTransform.UseVisualStyleBackColor = false; this.RadioRotatTransform.CheckedChanged += new System.EventHandler(this.RadioRotatTransform_CheckedChanged); // // RadioScaleTransform // this.RadioScaleTransform.AutoSize = true; this.RadioScaleTransform.BackColor = System.Drawing.Color.LightBlue; this.RadioScaleTransform.Location = new System.Drawing.Point(11, 92); this.RadioScaleTransform.Name = "RadioScaleTransform"; this.RadioScaleTransform.Size = new System.Drawing.Size(29, 16); this.RadioScaleTransform.TabIndex = 21; this.RadioScaleTransform.Text = "3"; this.RadioScaleTransform.UseVisualStyleBackColor = false; this.RadioScaleTransform.CheckedChanged += new System.EventHandler(this.RadioScaleTransform_CheckedChanged); // // RadioTranslateTransform // this.RadioTranslateTransform.AutoSize = true; this.RadioTranslateTransform.BackColor = System.Drawing.Color.LightBlue; this.RadioTranslateTransform.Location = new System.Drawing.Point(70, 62); this.RadioTranslateTransform.Name = "RadioTranslateTransform"; this.RadioTranslateTransform.Size = new System.Drawing.Size(29, 16); this.RadioTranslateTransform.TabIndex = 20; this.RadioTranslateTransform.Text = "2"; this.RadioTranslateTransform.UseVisualStyleBackColor = false; this.RadioTranslateTransform.CheckedChanged += new System.EventHandler(this.RadioTranslateTransform_CheckedChanged); // // RadioFocusScales // this.RadioFocusScales.AutoSize = true; this.RadioFocusScales.BackColor = System.Drawing.Color.LightBlue; this.RadioFocusScales.Checked = true; this.RadioFocusScales.Location = new System.Drawing.Point(11, 62); this.RadioFocusScales.Name = "RadioFocusScales"; this.RadioFocusScales.Size = new System.Drawing.Size(29, 16); this.RadioFocusScales.TabIndex = 19; this.RadioFocusScales.TabStop = true; this.RadioFocusScales.Text = "1"; this.RadioFocusScales.UseVisualStyleBackColor = false; this.RadioFocusScales.CheckedChanged += new System.EventHandler(this.RadioFocusScales_CheckedChanged); // // FocusScaleY // this.FocusScaleY.DecimalPlaces = 1; this.FocusScaleY.Increment = new decimal(new int[] { 1, 0, 0, 65536}); this.FocusScaleY.Location = new System.Drawing.Point(70, 20); this.FocusScaleY.Minimum = new decimal(new int[] { 100, 0, 0, -2147483648}); this.FocusScaleY.Name = "FocusScaleY"; this.FocusScaleY.Size = new System.Drawing.Size(57, 21); this.FocusScaleY.TabIndex = 14; this.FocusScaleY.ValueChanged += new System.EventHandler(this.FocusScaleY_ValueChanged); // // label8 // this.label8.AutoSize = true; this.label8.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label8.ForeColor = System.Drawing.Color.DeepPink; this.label8.Location = new System.Drawing.Point(89, 44); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(14, 15); this.label8.TabIndex = 15; this.label8.Text = "Y"; // // label7 // this.label7.AutoSize = true; this.label7.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label7.ForeColor = System.Drawing.Color.DeepPink; this.label7.Location = new System.Drawing.Point(25, 44); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(15, 15); this.label7.TabIndex = 14; this.label7.Text = "X"; // // comboBox1 // this.comboBox1.Cursor = System.Windows.Forms.Cursors.Hand; this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; this.comboBox1.Items.AddRange(new object[] { "Tile", "TileFlipX", "TileFlipY", "TileFlipXY", "Clamp"}); this.comboBox1.Location = new System.Drawing.Point(98, 33); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(101, 20); this.comboBox1.TabIndex = 14; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // label9 // this.label9.AutoSize = true; this.label9.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label9.ForeColor = System.Drawing.Color.DeepPink; this.label9.Location = new System.Drawing.Point(16, 34); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(69, 15); this.label9.TabIndex = 15; this.label9.Text = "WrapMode"; // // groupBox3 // this.groupBox3.BackColor = System.Drawing.Color.Bisque; this.groupBox3.Controls.Add(this.BlendOk); this.groupBox3.Controls.Add(this.PositionsStr); this.groupBox3.Controls.Add(this.FactorsStr); this.groupBox3.Controls.Add(this.label11); this.groupBox3.Controls.Add(this.label10); this.groupBox3.Location = new System.Drawing.Point(339, 198); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(237, 146); this.groupBox3.TabIndex = 16; this.groupBox3.TabStop = false; this.groupBox3.Text = "Blend"; // // BlendOk // this.BlendOk.Cursor = System.Windows.Forms.Cursors.Hand; this.BlendOk.ForeColor = System.Drawing.Color.Blue; this.BlendOk.Location = new System.Drawing.Point(93, 70); this.BlendOk.Name = "BlendOk"; this.BlendOk.Size = new System.Drawing.Size(45, 28); this.BlendOk.TabIndex = 17; this.BlendOk.Text = "确定"; this.BlendOk.UseVisualStyleBackColor = true; this.BlendOk.CheckedChanged += new System.EventHandler(this.BlendOk_CheckedChanged); // // PositionsStr // this.PositionsStr.Location = new System.Drawing.Point(144, 32); this.PositionsStr.Multiline = true; this.PositionsStr.Name = "PositionsStr"; this.PositionsStr.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.PositionsStr.Size = new System.Drawing.Size(74, 108); this.PositionsStr.TabIndex = 19; // // FactorsStr // this.FactorsStr.Location = new System.Drawing.Point(11, 32); this.FactorsStr.Multiline = true; this.FactorsStr.Name = "FactorsStr"; this.FactorsStr.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.FactorsStr.Size = new System.Drawing.Size(74, 108); this.FactorsStr.TabIndex = 17; // // label11 // this.label11.AutoSize = true; this.label11.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label11.ForeColor = System.Drawing.Color.DeepPink; this.label11.Location = new System.Drawing.Point(135, 17); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(93, 15); this.label11.TabIndex = 18; this.label11.Text = "Positions(float)"; // // label10 // this.label10.AutoSize = true; this.label10.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label10.ForeColor = System.Drawing.Color.DeepPink; this.label10.Location = new System.Drawing.Point(9, 17); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(83, 15); this.label10.TabIndex = 17; this.label10.Text = "Factors(float)"; // // groupBox4 // this.groupBox4.BackColor = System.Drawing.Color.Bisque; this.groupBox4.Controls.Add(this.label9); this.groupBox4.Controls.Add(this.comboBox1); this.groupBox4.Controls.Add(this.LabelCenterPos); this.groupBox4.Controls.Add(this.label3); this.groupBox4.Controls.Add(this.LabelCenterColor); this.groupBox4.Controls.Add(this.label1); this.groupBox4.Location = new System.Drawing.Point(351, 55); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(219, 114); this.groupBox4.TabIndex = 17; this.groupBox4.TabStop = false; this.groupBox4.Text = "Anothers"; // // label12 // this.label12.AutoSize = true; this.label12.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label12.ForeColor = System.Drawing.Color.DeepPink; this.label12.Location = new System.Drawing.Point(103, 9); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(72, 15); this.label12.TabIndex = 18; this.label12.Text = "用法演示区"; // // Form1 // this.AutoSize = true; this.BackColor = System.Drawing.SystemColors.InactiveCaptionText; this.ClientSize = new System.Drawing.Size(596, 354); this.Controls.Add(this.label12); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.GroupBoxScale); this.Controls.Add(this.groupBox1); this.Controls.Add(this.DrawingPad); this.Font = new System.Drawing.Font("隶书", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(604, 388); this.MinimumSize = new System.Drawing.Size(604, 388); this.Name = "Form1"; this.Text = "PathGradientBrush用法演示"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.FocusScaleX)).EndInit(); this.GroupBoxScale.ResumeLayout(false); this.GroupBoxScale.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.FocusScaleY)).EndInit(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } //Method //fdd2009 private void MyInitialize() { this.toolTip1.SetToolTip(this.LabelCenterPos, "单击我后,把鼠标移到演示区,再单击一下,就可以选择位置了!"); this.toolTip1.ToolTipTitle = "提示:"; this.toolTip1.AutomaticDelay = 500; this.toolTip1.IsBalloon = true; this.toolTip1.ShowAlways = true; } //Draw:给出矩形区域的填充图形 private void DrawUsingPathGradientBrush(Graphics e,Control obj) { //GraphicsPah GraphicsPath path = new GraphicsPath(); path.AddRectangle(obj.ClientRectangle); //PathGradientBrush PathGradientBrush gBrush = new PathGradientBrush(path); //setProperty-->PathGradientBrush //==CenterColor gBrush.CenterColor = this.LabelCenterColor.BackColor; //==CenterPoint #region if (this.LabelCenterPos.Tag != null) { //Tag必须可以转换为Point类 if (((Point)(this.LabelCenterPos.Tag) )!= null) { gBrush.CenterPoint = (Point)(this.LabelCenterPos.Tag); } } #endregion //==SurroundColors的值。它决定四角的颜色。 #region ArrayList ColorList = new ArrayList() ; if (LeftTopColor.Checked) { ColorList.Add(LeftTopColor.BackColor); } if (RightTopColor.Checked) { ColorList.Add(RightTopColor.BackColor); } if (RightBottonColor.Checked) { ColorList.Add(RightBottonColor.BackColor); } if (LeftBottonColor.Checked) { ColorList.Add(LeftBottonColor.BackColor); } if (ColorList.Count > 0) { Color[] colorArray=new Color[ColorList.Count]; for(int i=0;i<ColorList.Count;i++){ colorArray[i]=(Color)(ColorList[i]);//转换为Point[]。 } gBrush.SurroundColors = colorArray; } #endregion //==FocusScales,获取或设置渐变过渡的焦点。 //TranslateTransform //ScaleTransform #region PointF ptF = new PointF() ; if (this.RadioFocusScales.Tag != null) { ptF = (PointF)this.RadioFocusScales.Tag; gBrush.FocusScales= ptF; } if (this.RadioTranslateTransform.Tag != null) { ptF = (PointF)this.RadioTranslateTransform.Tag; gBrush.TranslateTransform(ptF.X, ptF.Y); } if (this.RadioScaleTransform.Tag != null) { ptF = (PointF)this.RadioScaleTransform.Tag; gBrush.ScaleTransform(ptF.X, ptF.Y); } if (this.RadioRotatTransform.Tag != null) { gBrush.RotateTransform(Convert.ToSingle(this.RadioRotatTransform.Tag)); } #endregion //==WrapMode #region if (this.comboBox1.Text.Length > 0) { gBrush.WrapMode = (WrapMode)(Enum.Parse(typeof(WrapMode), this.comboBox1.Text)); } #endregion //==Blend #region string[] s; string[] ss; if (this.BlendOk.Checked) { s = this.FactorsStr.Lines; ss = this.PositionsStr.Lines; if ((s.Length > 1) && (s.Length == ss.Length)) { #region Blend MyBlend = new Blend(); try { float[] f = new float[s.Length]; for (int i = 0; i < s.Length; i++) { f[i] = Convert.ToSingle(s[i].Replace('/n', '/0')); } MyBlend.Factors = f; float[] p = new float[ss.Length]; for (int i = 0; i < ss.Length; i++) { p[i] = Convert.ToSingle(ss[i].Replace('/n', '/0')); } if ((p[0] == 0f) && (p[p.Length - 1] == 1f)) { MyBlend.Positions = p; } gBrush.Blend = MyBlend; } catch { MessageBox.Show("出错原因:/n1、数字中含有非数字内容!/n2、两个数组给的元素个数不一样多!/n3、后个数组内第一和最后一个不是0和1。", "请检查:"); } #endregion } else { MessageBox.Show("出错:数组个数不一样多或个数少于2个!","请检查:"); } } #endregion //rotation //gBrush.RotateTransform (85); //PathGradientBrush-->Brush Brush brush = gBrush; //draw-->DrawingPad try { e.FillRectangle(brush,obj.ClientRectangle); } catch(Exception error) { MessageBox.Show(error.Message+"/n"+"你的数据输入可能有问题!","出错了:"); } //dispose brush.Dispose(); gBrush.Dispose(); path.Dispose(); } //setEvent private void setEvents(bool flag) { if (flag) { this.FocusScaleX.ValueChanged += new System.EventHandler(this.FocusScaleX_ValueChanged); this.FocusScaleY.ValueChanged += new System.EventHandler(this.FocusScaleY_ValueChanged); } else { this.FocusScaleX.ValueChanged -= new System.EventHandler(this.FocusScaleX_ValueChanged); this.FocusScaleY.ValueChanged -= new System.EventHandler(this.FocusScaleY_ValueChanged); } } //setscale: private void SetTag() { if (this.RadioFocusScales.Checked) { this.RadioFocusScales.Tag = new PointF((float)(this.FocusScaleX.Value), (float)(this.FocusScaleY.Value)); //this.DrawingPad.Invalidate(); } else if (RadioTranslateTransform.Checked) { this.RadioTranslateTransform.Tag= new PointF((float)(this.FocusScaleX.Value), (float)(this.FocusScaleY.Value)); //this.DrawingPad.Invalidate(); } else if (RadioScaleTransform.Checked) { this.RadioScaleTransform.Tag = new PointF((float)(this.FocusScaleX.Value), (float)(this.FocusScaleY.Value)); //this.DrawingPad.Invalidate(); } else if (RadioRotatTransform.Checked) { this.RadioRotatTransform.Tag = this.FocusScaleX.Value; } } //SetColor:给复选框或标签对象设置背景颜色。 private void SetColor(object button,bool flag) { if (flag) { ColorDialog colorDialog = new ColorDialog(); if (colorDialog.ShowDialog() == DialogResult.OK) { if ((button as Label) != null) { ((Label)button).BackColor = colorDialog.Color; } else if ((button as CheckBox) != null) { ((CheckBox)button).BackColor = colorDialog.Color; } } } } //LabelCenterColor:设置此Label的背景色,是为了 //将来根据它设置笔刷PathGradientBrush的中心颜色。 private void LabelCenterColor_Click(object sender, EventArgs e) { SetColor(sender,true); } //如果此Label的背景色改变了,让DrawingPad控件重绘。 //重绘时,调用DrawUsingPathGradientBrush方法实现。 private void LabelCenterColor_BackColorChanged(object sender, EventArgs e) { this.DrawingPad.Invalidate(); } //LabelCenterPos_Click:设置此Label,让它的Tag属性获取选择的点位置对象:Point。 //将来根据设置PathGradientBrush的CenterPos属性。 //位置选择方法运行后,鼠标在上面时有提示。 private void LabelCenterPos_Click(object sender, EventArgs e) { //开始允许获取鼠标位置值。 this.CanGetPos = true; } //DrawingPad:配合上面控件选择位置。 private void DrawingPad_MouseMove(object sender, MouseEventArgs e) { if (this.CanGetPos) { this.LabelCenterPos.Text = e.X.ToString() + "," + e.Y.ToString(); this.LabelCenterPos.Tag = e.Location; this.DrawingPad.Invalidate(); } } private void DrawingPad_MouseDown(object sender, MouseEventArgs e) { if (this.CanGetPos) { this.LabelCenterPos.Text = e.X.ToString() + "," + e.Y.ToString(); this.LabelCenterPos.Tag = e.Location; this.DrawingPad.Invalidate(); } this.CanGetPos = false; } private void DrawingPad_Paint(object sender, PaintEventArgs e) { DrawUsingPathGradientBrush(e.Graphics,(Control)(this.DrawingPad)); } //surroundcolor:设置此四个复选框的背景色, //将来根据它设置PathGradientBrush的Surroundcolor属性。 private void LeftTopColor_CheckedChanged(object sender, EventArgs e) { SetColor(sender,((CheckBox)sender).Checked); this.DrawingPad.Invalidate(); } private void LeftBottonColor_CheckedChanged(object sender, EventArgs e) { SetColor(sender, ((CheckBox)sender).Checked); this.DrawingPad.Invalidate(); } private void RightTopColor_CheckedChanged(object sender, EventArgs e) { SetColor(sender, ((CheckBox)sender).Checked); this.DrawingPad.Invalidate(); } private void RightBottonColor_CheckedChanged(object sender, EventArgs e) { SetColor(sender, ((CheckBox)sender).Checked); //this.DrawingPad.Invalidate(); this.DrawingPad.Invalidate(); } //FocusScale:设置此NumericUpDown的值, //将来根据它设置PathGradientBrush的FocusScale属性。 private void FocusScaleX_ValueChanged(object sender, EventArgs e) { SetTag(); this.DrawingPad.Invalidate(); } private void FocusScaleY_ValueChanged(object sender, EventArgs e) { SetTag(); this.DrawingPad.Invalidate(); } //WrapMode:选择此组合框中的值 //将来根据它设置PathGradientBrush的WrapMode属性。 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { this.DrawingPad.Invalidate(); } //Blend:设置此处两个文本框的值(必须个数相同,至少两个) //将来根据它设置PathGradientBrush的Blend属性。 //通过下面的BlendOk复选框的CheckedChanged来触发。 private void BlendOk_CheckedChanged(object sender, EventArgs e) { this.DrawingPad.Invalidate(); } //确认为:RadioFocusScales,对应设置:FocusScales private void RadioFocusScales_CheckedChanged(object sender, EventArgs e) { if (this.RadioFocusScales.Checked) { this.GroupBoxScale.Text = "FocusScales"; setEvents(false); if (!this.FocusScaleY.Visible) { this.FocusScaleY.Visible = true; } if (this.RadioFocusScales.Tag == null) { this.FocusScaleX.Value = 0m; this.FocusScaleY.Value = 0m; } else { this.FocusScaleX.Value = Convert.ToDecimal(((PointF)(this.RadioFocusScales.Tag)).X); this.FocusScaleY.Value =Convert.ToDecimal( ((PointF)(this.RadioFocusScales.Tag)).Y); } setEvents(true); SetTag(); this.DrawingPad.Invalidate(); } } //确认为:RadioTranslateTransform,对应设置:TranslateTransform private void RadioTranslateTransform_CheckedChanged(object sender, EventArgs e) { if (this.RadioTranslateTransform.Checked) { this.GroupBoxScale.Text = "TranslateTransform"; setEvents(false); if (!this.FocusScaleY.Visible) { this.FocusScaleY.Visible = true; } if (this.RadioTranslateTransform.Tag == null) { this.FocusScaleX.Value = 0m; this.FocusScaleY.Value = 0m; } else { this.FocusScaleX.Value = Convert.ToDecimal(((PointF)(this.RadioTranslateTransform.Tag)).X); this.FocusScaleY.Value = Convert.ToDecimal(((PointF)(this.RadioTranslateTransform.Tag)).Y); } setEvents(true); SetTag(); this.DrawingPad.Invalidate(); } } //确认为:RadioScaleTransform,对应设置:ScaleTransform private void RadioScaleTransform_CheckedChanged(object sender, EventArgs e) { if (this.RadioScaleTransform.Checked) { this.GroupBoxScale.Text = "ScaleTransform"; setEvents(false); if (!this.FocusScaleY.Visible) { this.FocusScaleY.Visible = true; } if (this.RadioScaleTransform.Tag == null) { this.FocusScaleX.Value = 1m; this.FocusScaleY.Value = 1m; } else { this.FocusScaleX.Value = Convert.ToDecimal(((PointF)(this.RadioScaleTransform.Tag)).X); this.FocusScaleY.Value = Convert.ToDecimal(((PointF)(this.RadioScaleTransform.Tag)).Y); } setEvents(true); SetTag(); this.DrawingPad.Invalidate(); } } //确认为:RadioRotatTransform,对应设置:RotatTransform private void RadioRotatTransform_CheckedChanged(object sender, EventArgs e) { setEvents(false); if (this.RadioRotatTransform.Checked) { this.GroupBoxScale.Text = "RotatTransform"; this.FocusScaleY.Visible = false; this.FocusScaleX.Maximum = 360; this.FocusScaleX.Increment = 0.5m; this.FocusScaleX.Minimum = 0; if (this.RadioRotatTransform.Tag == null) { this.FocusScaleX.Value = 0; } else { this.FocusScaleX.Value = (decimal)this.RadioRotatTransform.Tag; } setEvents(true); SetTag(); this.DrawingPad.Invalidate(); } else { this.FocusScaleY.Visible = true; this.FocusScaleX.Maximum = 100m; this.FocusScaleX.Minimum = -100m; this.FocusScaleX.Increment = 0.1m; setEvents(true); } } private void DrawingPad_DoubleClick(object sender, EventArgs e) { Form newForm = new Form(); newForm.Visible = true; newForm.TopLevel = true; newForm.MaximizeBox = false; newForm.MinimizeBox = false; newForm.WindowState = FormWindowState.Maximized; newForm.Paint += new PaintEventHandler(newForm_Paint); this.AddOwnedForm(newForm); } void newForm_Paint(object sender, PaintEventArgs e) { DrawUsingPathGradientBrush(e.Graphics, (Control)sender); } //Fields //GroupBox: private GroupBox groupBox1; private GroupBox GroupBoxScale; private GroupBox groupBox3; private GroupBox groupBox4; //Label: private Label LabelCenterColor; private Label DrawingPad; private Label LabelCenterPos; private Label label12; private Label label11; private Label label10; private Label label9; private Label label8; private Label label7; private Label label6; private Label label5; private Label label4; private Label label3; private Label label2; private Label label1; //CheckBox: private CheckBox LeftTopColor; private CheckBox LeftBottonColor; private CheckBox RightBottonColor; private CheckBox RightTopColor; private CheckBox BlendOk; //TextBox: private TextBox FactorsStr; private TextBox PositionsStr; //NumericUpDown: private NumericUpDown FocusScaleX; private NumericUpDown FocusScaleY; //ToolTip类的变量: private ToolTip toolTip1; //ComboBox: private ComboBox comboBox1; //bool变量: private bool CanGetPos = false; //Radio: private RadioButton RadioFocusScales; private RadioButton RadioScaleTransform; private RadioButton RadioTranslateTransform; private RadioButton RadioRotatTransform; } //程序入口: static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }