Neler yeni
Türkiye'nin En Güncel Forum Sitesi

Forum içeriğine ve tüm hizmetlerimize erişim sağlamak için foruma kayıt olmalı yada giriş yapmalısınız. Forum üye olmak tamamen ücretsizdir.

Graphics Nesnesini Kullanarak Rastgele Şekiller Çizdirme

ByOnur58

Kayıtlı Üye
MFC Üyesi
  • Üyelik Tarihi
    7 Ocak 2015
  • Mesajlar
    2,113
  • MFC Puanı
    10
  • MFC Seviyesi

Kod:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace C_Sharp_GDI_Kullanımı
{

    public partial class Form1 : Form
    {
        List< Pen >  pens;
        List< Brush > brushes;
        Random random;

        public Form1()
        {
            InitializeComponent();
        }

        private **** Form1_Load(object sender, EventArgs e)
        {
            pens = new List< Pen >();
            brushes = new List< Brush >();
            random = new Random();

            pens.Add(new Pen(Color.Blue));
            pens.Add(new Pen(Color.Red));
            pens.Add(new Pen(Color.Green));
            pens.Add(new Pen(Color.Black));
            pens.Add(new Pen(Color.White));

            brushes.Add(Brushes.Blue);
            brushes.Add(Brushes.Red);
            brushes.Add(Brushes.Green);
            brushes.Add(Brushes.Black);
            brushes.Add(Brushes.White);

        }



        private **** drawEllipse(Graphics graphic)
        {
            graphic.DrawEllipse(pens[random.Next(0, 5)], random.Next(0, 100), random.Next(0, 100), random.Next(0, 100), random.Next(0, 100));
            bmp = new Bitmap(panel1.Width, panel1.Height, graphic);
        }

        private **** drawPie(Graphics graphic)
        {
            try
            {
                graphic.DrawPie(pens[random.Next(0, 5)], random.Next(0, 100), random.Next(0, 100), random.Next(0, 100), random.Next(0, 100), 0, 60);
            }
            catch (Exception)
            {
            }
            
        }

        private **** DrawRandomFigure(Graphics graphic)
        {
            Point[] ps = {
                                 new Point(0,random.Next(0, 100)),
                                 new Point(100,random.Next(0, 100)),
                                 new Point(100,random.Next(100, 200)),
                                 new Point(0,random.Next(100, 200))
                               };

            graphic.FillClosedCurve(brushes[random.Next(0, 5)], ps);
        }

        private **** DrawFillPie(Graphics graphic)
        {
            int width = random.Next(100, 100);
            int height = width;
            graphic.FillPie(brushes[random.Next(0, 5)], random.Next(0, 100), random.Next(0, 100), width, height, random.Next(0, 360), random.Next(0, 360));
        }


        private **** btnElippseDraw_Click(object sender, EventArgs e)
        {
            drawEllipse(panel1.CreateGraphics());
        }

        private **** btnPieDraw_Click(object sender, EventArgs e)
        {
            drawPie(panel1.CreateGraphics());
        }

        private **** btnSquareDraw_Click(object sender, EventArgs e)
        {
            int width = random.Next(10, panel1.Width-10);
            int height =random.Next(10, panel1.Height-10);

            Bitmap bitMap = new Bitmap(width, height);
            Rectangle rec = new Rectangle(5, 5, width, height);

            Graphics g = panel1.CreateGraphics();
            g.DrawRectangle(pens[random.Next(0, 5)], rec);

        }

        private **** btnDrawFigure_Click(object sender, EventArgs e)
        {
            DrawRandomFigure(panel1.CreateGraphics());
        }

        private **** btnFillPie_Click(object sender, EventArgs e)
        {
            DrawFillPie(panel1.CreateGraphics());
        }
    }
}
 
Üst Alt