2013-01-09 26 views
0

是否有可能在c#中製作心形圖案盒? 我已經看到了矩形和橢圓的代碼,但我對製作心形區域沒有任何想法。心形圖案盒

有什麼想法?

+0

這是一個WPF /的WinForms/ASP/XNA問題?請用您使用的相關框架標記它:)如果您有任何問題,請發佈一些代碼。 – Codeman

+0

'心形區域' - 用[bezier曲線](http://www.google.com/search?q=bezier+heart)製作一個。 – GSerg

+0

它在一個winform,可悲的是,我沒有任何想法如何使心臟形狀, –

回答

3

這似乎工作:從這裏

public class HeartPictureBox : PictureBox { 
    protected override void OnPaint(PaintEventArgs pe) { 
     using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath()) { 
      path.AddBezier(this.Width >> 1, 
          this.Height >> 2, 
          this.Width * 1.25f, 0f, 
          this.Width, 
          this.Height * 0.75f, 
          this.Width >> 1, 
          this.Height); 
      path.AddBezier(this.Width >> 1, 
          this.Height >> 2, 
          -this.Width * .25f, 0f, 
          0f, 
          this.Height * 0.75f, 
          this.Width >> 1, 
          this.Height); 

      this.Region = new Region(path); 
     } 
    } 
} 

貝塞爾東西:http://www.codeproject.com/Tips/177794/Heart-shaped-Form-in-C-2-0

+0

非常感謝! –

+0

爲什麼我有一個錯誤'System.Windows.Forms.Control.Region'是一個'屬性',但像'type'\t錯誤一樣使用? –

+1

哦,我想通了:) –

0
using System; 
namespace ConsoleApplication6 
{ 
    class Program 
    { 
     static void Main() 
     { 
      Console.WriteLine(" o o.o o "); 
      Console.WriteLine(" o   o  "); 
      Console.WriteLine(" o   o  "); 
      Console.WriteLine(" o  o   "); 
      Console.WriteLine("  o o  "); 
      Console.WriteLine("  o   "); 
      Console.ReadKey(); 
     } 
    }} 
+1

不知道你打算如何將它顯示爲一個PictureBox控件。 – LarsTech