InkPicture 控件使用_01

private System.ComponentModel.Container components = null;
  private Microsoft.Ink.InkOverlay m_InkOverlay;
  private System.Windows.Forms.GroupBox groupBox1;
  private System.Windows.Forms.RadioButton InkIt;
  private System.Windows.Forms.RadioButton DelIt;
  private System.Windows.Forms.RadioButton SelectIt;
  private System.Windows.Forms.RadioButton PointErase;
  private enum InkDrawStateEnum {Ink,Select,Delete,PointErase};
  private int InkDrawState = (int) InkDrawStateEnum.Ink;
        private Button btnSave;
        private PictureBox pictureBox1;
        Microsoft.Ink.InkCollector theInkCollector;

public Form1()
  {

InitializeComponent();    // Instantiate the InkOverlay.

m_InkOverlay = new Microsoft.Ink.InkOverlay(this.Handle);

m_InkOverlay.Enabled = true;

// Hook up the InkOverlay object's Stroke event handler.

m_InkOverlay.Stroke += new InkCollectorStrokeEventHandler( InkStrokeAdded );                    // Hook up to the InkOverlay object's Painted event handler.    m_InkOverlay.Painted += new InkOverlayPaintedEventHandler(InkPainted);

}

private void InkStrokeAdded( object sender, InkCollectorStrokeEventArgs e)
  {
   // Invalidate the form so we can force a repaint.
   this.Invalidate();
  }

private void InkPainted( object sender, PaintEventArgs e)
  {
   // Call the helper function which will redraw the form.
   RendererEx.DrawStrokeIds(e.Graphics, Font, m_InkOverlay.Ink);
  }

protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

private void InitializeComponent()
  {

this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.btnSave = new System.Windows.Forms.Button();
            this.PointErase = new System.Windows.Forms.RadioButton();
            this.SelectIt = new System.Windows.Forms.RadioButton();
            this.DelIt = new System.Windows.Forms.RadioButton();
            this.InkIt = new System.Windows.Forms.RadioButton();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();

     this.groupBox1.Controls.Add(this.btnSave);
            this.groupBox1.Controls.Add(this.PointErase);
            this.groupBox1.Controls.Add(this.SelectIt);
            this.groupBox1.Controls.Add(this.DelIt);
            this.groupBox1.Controls.Add(this.InkIt);
            this.groupBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.groupBox1.Location = new System.Drawing.Point(0, 278);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(458, 45);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;

     this.btnSave.Location = new System.Drawing.Point(371, 16);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(75, 23);
            this.btnSave.TabIndex = 4;
            this.btnSave.Text = "Save";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);

    this.PointErase.Location = new System.Drawing.Point(272, 15);
            this.PointErase.Name = "PointErase";
            this.PointErase.Size = new System.Drawing.Size(96, 22);
            this.PointErase.TabIndex = 3;
            this.PointErase.Text = "Point Erase";
            this.PointErase.CheckedChanged += new System.EventHandler(this.PointErase_CheckedChanged);

    this.SelectIt.Location = new System.Drawing.Point(80, 15);
            this.SelectIt.Name = "SelectIt";
            this.SelectIt.Size = new System.Drawing.Size(80, 22);
            this.SelectIt.TabIndex = 2;
            this.SelectIt.Text = "Select";
            this.SelectIt.CheckedChanged += new System.EventHandler(this.SelectIt_CheckedChanged);

    this.DelIt.Location = new System.Drawing.Point(184, 15);
            this.DelIt.Name = "DelIt";
            this.DelIt.Size = new System.Drawing.Size(64, 22);
            this.DelIt.TabIndex = 1;
            this.DelIt.Text = "Delete";
            this.DelIt.CheckedChanged += new System.EventHandler(this.DelIt_CheckedChanged);

    this.InkIt.Checked = true;
            this.InkIt.Location = new System.Drawing.Point(8, 15);
            this.InkIt.Name = "InkIt";
            this.InkIt.Size = new System.Drawing.Size(56, 22);
            this.InkIt.TabIndex = 0;
            this.InkIt.TabStop = true;
            this.InkIt.Text = "Ink";
            this.InkIt.CheckedChanged += new System.EventHandler(this.InkIt_CheckedChanged);

     this.pictureBox1.Location = new System.Drawing.Point(248, 26);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(198, 246);
            this.pictureBox1.TabIndex = 1;
            this.pictureBox1.TabStop = false;

     this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(458, 323);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.groupBox1);
            this.Name = "Form1";
            this.Text = "StrokeViewer";
            this.groupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

}

[STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

private void InkIt_CheckedChanged(object sender, System.EventArgs e)
  {
   InkDrawState = (int) InkDrawStateEnum.Ink;
   m_InkOverlay.EditingMode = InkOverlayEditingMode.Ink;
  }

private void SelectIt_CheckedChanged(object sender, System.EventArgs e)
  {
   InkDrawState = (int) InkDrawStateEnum.Select;
   m_InkOverlay.EditingMode = InkOverlayEditingMode.Select;
  }

private void DelIt_CheckedChanged(object sender, System.EventArgs e)
  {
   InkDrawState = (int) InkDrawStateEnum.Delete;
   m_InkOverlay.EditingMode = InkOverlayEditingMode.Delete;
   m_InkOverlay.EraserMode = InkOverlayEraserMode.StrokeErase;
  }

private void PointErase_CheckedChanged(object sender, System.EventArgs e)
  {
   InkDrawState = (int) InkDrawStateEnum.PointErase;
   m_InkOverlay.EditingMode = InkOverlayEditingMode.Delete;
   m_InkOverlay.EraserMode = InkOverlayEraserMode.PointErase;
  }

private void btnSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "(*.*)|*.gif";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                FileStream gifFile;
                byte[] fortifiedGif = null;
                gifFile = File.OpenWrite(sfd.FileName);
                fortifiedGif = m_InkOverlay.Ink.Save(PersistenceFormat.Gif);
                gifFile.Write(fortifiedGif, 0, fortifiedGif.Length);
                gifFile.Close();
            }
        }

上一篇:面向对象第四单元(UML)总结


下一篇:iScroll 下拉刷新