GDI+基礎知識——畫筆的對齊

來源:互聯網
上載者:User

效果:

 

代碼:

  private void Pen_Align_Click(object sender, System.EventArgs e)
  {
   Graphics graphics = this.CreateGraphics();
   graphics.Clear(Color.White);
   graphics.SmoothingMode = SmoothingMode.HighQuality;
   
   Pen pen = new Pen(Color.Gray, 1.0f);

   Pen pen1  =  new Pen(Color.FromArgb(255,Color.Green),12);
   Pen pen2 = new Pen(Color.FromArgb(155,Color.Red),20);
   
   for(int i = 0; i<5;i++)
   {
    pen1.Alignment = (PenAlignment)i;
    for(int j = 0;j<5;j++)
    {
     pen2.Alignment = (PenAlignment)j;
     graphics.TranslateTransform(20,0);
     //graphics.DrawLine(pen2, new Point(0,30), new Point(60,30));
     //graphics.DrawLine(pen1, new Point(0,30), new Point(60,30));
     graphics.DrawEllipse(pen1,0,30,80,80);
     graphics.DrawEllipse(pen2,0,30,80,80);

     graphics.DrawString("綠色:"+pen1.Alignment.ToString() + "\n紅色:" + pen2.Alignment.ToString(),new Font("Arial",12,FontStyle.Bold),new SolidBrush(Color.Yellow),0f,30f);
     graphics.DrawString("綠色:"+pen1.Alignment.ToString() + "\n紅色:" + pen2.Alignment.ToString(),new Font("Arial",12),new SolidBrush(Color.Black),0f,30f);

     graphics.TranslateTransform(110,0);
    }
    graphics.ResetTransform();
    graphics.TranslateTransform(0,100*(i+1));
   }
  
   graphics.ResetTransform();
   //graphics.DrawLine(pen,0,30,600,30);
   graphics.Dispose();
  }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.