GDI+中我想要用 Pen 绘制自定义的线条,比如:-*-*-*像这种格式的虚线;
虚线中的线条样式能够自己设计,请各位老师帮忙下! 

解决方案 »

  1.   


     private void button1_Click(object sender, EventArgs e)
            {
                string strLine = "-*-*-*";
                Graphics g = Graphics.FromHwnd(this.Handle);
                g.DrawString(strLine,new Font(this.Font, FontStyle.Regular),Brushes.Red,new PointF(10,10));
                
            }
      

  2.   

    Image mm = new Bitmap(10, 10);
                Graphics g = Graphics.FromImage(mm);
                g.DrawString("*-", this.Font, Brushes.Black, 0,5);
                TextureBrush b = new TextureBrush(mm);
                Pen p = new Pen(b,10);
               
                g = this.CreateGraphics();
               
                
                g.DrawLine(p, new Point(0, 50), new Point(200, 50));
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Drawing2D;namespace WindowsApplication130
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            this.Paint += new PaintEventHandler(Form1_Paint);
            }        void Form1_Paint(object sender, PaintEventArgs e)
            {
                Pen P = new Pen(Brushes.Red);
                P.DashPattern = new float[] { 5, 3, 1, 3 };
                e.Graphics.DrawLine(P, new Point(0, 0), new Point(100, 100));
            }
        }
    }