• Web sitemizin içeriğine ve tüm hizmetlerimize erişim sağlamak için Web sitemize kayıt olmalı ya da giriş yapmalısınız. Web sitemize üye olmak tamamen ücretsizdir.
  • Sohbetokey.com ile canlı okey oynamaya ne dersin? Hem sohbet et, hem mobil okey oyna!
  • Soru mu? Sorun mu? ''Bir Sorum Var?'' sistemimiz aktiftir. Paylaşın beraber çözüm üretelim.

Graphics Nesnesini Kullanarak Rastgele Şekiller Çizdirme

Üyelik Tarihi
7 Ocak 2015
Konular
4,091
Mesajlar
4,274
MFC Puanı
40
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