IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası
  sohbet

 Kayıt ol  Topluluk
Yeni Konu aç Cevapla
 
LinkBack Seçenekler Stil
Alt 19 Temmuz 2008, 15:55   #1
Çevrimiçi
Yardımcı Admin
Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
IF Ticaret Sayısı: (0)
IF Ticaret Yüzdesi:(%)
Ekrana rastgele daireler çizmek




Uygulama üzerinde rastgele renk, açı ve merkeze sahip daireler çizmenizi sağlayan kod örneği. Ayrıca uygulama ile çizimi *.jpg olarak kaydedebilirsiniz

PHP Kod:   Kodu kopyalamak için üzerine çift tıklayın!
/*
 * Created using SharpDevelop free C# IDE from
 * 
Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir.
style="color: #0000BB">using System
;
using System.Drawing;  // GDI+ stuff
using System.Drawing.Imaging;  // ImageFormat
using System.Windows.Forms;
 
namespace 
DrawLineCircle
{
  
// Summary description for Form1
  // a window with five buttons
  
public class Form1 System.Windows.Forms.Form
  
{
    private 
System.Windows.Forms.Button btnLine;
    private 
System.Windows.Forms.Button btnCircle;
    private 
System.Windows.Forms.Button btnFill;
    private 
System.Windows.Forms.Button btnSave;
    private 
System.Windows.Forms.Button btnClear;
 
    private 
Bitmap DrawArea;  // make a persistent drawing area
 
    // Required designer variable
    
private System.ComponentModel.Container components null;
 
    private 
Random rnd;
    private 
Pen myPen;
 
    public 
Form1()
    {
      
InitializeComponent();
      
rnd = new Random((int)DateTime.Now.Ticks); // seeded with ticks
      
myPen = new Pen(Color.Red);
    }
 
    
// Clean up any resources being used
    
protected override void Dispose(bool disposing)
    {
      if (
disposing)
      {
        if (
components != null)
        {
          
components.Dispose();
        }
      }
      
base.Dispose(disposing);
    }
 
    
#region Windows Form Designer generated code
    
private void InitializeComponent()
    {
      
this.btnCircle = new System.Windows.Forms.Button();
      
this.btnSave = new System.Windows.Forms.Button();
      
this.btnLine = new System.Windows.Forms.Button();
      
this.btnFill = new System.Windows.Forms.Button();
      
this.btnClear = new System.Windows.Forms.Button();
      
this.SuspendLayout();
      
// 
      // btnCircle
      // 
      
this.btnCircle.Location = new System.Drawing.Point(136296);
      
this.btnCircle.Name "btnCircle";
      
this.btnCircle.Size = new System.Drawing.Size(5620);
      
this.btnCircle.TabIndex 0;
      
this.btnCircle.Text "Circle";
      
this.btnCircle.Click += new System.EventHandler(this.btnCircle_Click);
      
// 
      // btnSave
      // 
      
this.btnSave.Location = new System.Drawing.Point(328296);
      
this.btnSave.Name "btnSave";
      
this.btnSave.Size = new System.Drawing.Size(4820);
      
this.btnSave.TabIndex 0;
      
this.btnSave.Text "Save";
      
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
      
// 
      // btnLine
      // 
      
this.btnLine.Location = new System.Drawing.Point(264296);
      
this.btnLine.Name "btnLine";
      
this.btnLine.Size = new System.Drawing.Size(5420);
      
this.btnLine.TabIndex 1;
      
this.btnLine.Text "Line";
      
this.btnLine.Click += new System.EventHandler(this.btnLine_Click);
      
// 
      // btnFill
      // 
      
this.btnFill.Location = new System.Drawing.Point(200296);
      
this.btnFill.Name "btnFill";
      
this.btnFill.Size = new System.Drawing.Size(5620);
      
this.btnFill.TabIndex 2;
      
this.btnFill.Text "FCircle";
      
this.btnFill.Click += new System.EventHandler(this.btnFill_Click);
      
// 
      // btnClear
      // 
      
this.btnClear.Location = new System.Drawing.Point(8296);
      
this.btnClear.Name "btnClear";
      
this.btnClear.Size = new System.Drawing.Size(5620);
      
this.btnClear.TabIndex 3;
      
this.btnClear.Text "Clear";
      
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
      
// 
      // Form1
      // 
      
this.AutoScaleBaseSize = new System.Drawing.Size(615);
      
this.ClientSize = new System.Drawing.Size(380325);
      
this.Controls.Add(this.btnClear);
      
this.Controls.Add(this.btnFill);
      
this.Controls.Add(this.btnSave);
      
this.Controls.Add(this.btnLine);
      
this.Controls.Add(this.btnCircle);
      
this.Name "Form1";
      
this.Text "Draw a few circles ...";
      
this.Load += new System.EventHandler(this.Form1_Load);
      
this.Closed += new System.EventHandler(this.Form1_Closed);
      
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
      
this.ResumeLayout(false);
 
    }
    
#endregion
 
    //
    // This is the main entry point for the application.
    //
    
public static void Main()
    {
      
Application.Run(new Form1());
    }
 
    
// Line button click event
    
private void btnLine_Click(object senderSystem.EventArgs e)
    {
      
Graphics xGraph;
      
int k;
 
      
xGraph Graphics.FromImage(DrawArea);
 
      for(
140k++)
      {
        
myPen.Color Color.FromArgb(
          (
rnd.Next(0,255)),
          (
rnd.Next(0,255)),
          (
rnd.Next(0,255)));
 
        
xGraph.DrawLine(
          
myPen,
          (int) 
rnd.Next(0this.Width),
          (int) 
rnd.Next(0this.Height),
          (int) 
rnd.Next(0this.Width),
          (int) 
rnd.Next(0this.Height));
      }
      
xGraph.Dispose();
      
this.Invalidate();
    }
 
    
// Circle button click event
    
private void btnCircle_Click(object senderSystem.EventArgs e)
    {
      
Graphics xGraph;
      
int k;
      
int r;     // radius of circle
      
int xy;  // center coordinates of circle
 
      
xGraph Graphics.FromImage(DrawArea);
 
      for(
140k++)
      {
        
// radius for circle, max 1/2 the width of the form
        
rnd.Next(0, (this.Width 2));
        
rnd.Next(0this.Width);
        
rnd.Next(0this.Height);
 
        
myPen.Color Color.FromArgb(
          (
rnd.Next(0,255)),
          (
rnd.Next(0,255)),
          (
rnd.Next(0,255)));
        
// convert centerX, centerY, radius to bounding rectangle
        
xGraph.DrawEllipsemyPenx-ry-rr);
      }
      
xGraph.Dispose();
      
this.Invalidate();
    }
 
    
// FCircle (solid circle) button click event
    
private void btnFill_Click(object senderSystem.EventArgs e)
    {
      
Graphics xGraph;
      
int k;
      
int r;     // radius of circle
      
int xy;  // center coordinates of circle
 
      
xGraph Graphics.FromImage(DrawArea);
 
      
// Create solid brush.
      
SolidBrush Brush = new SolidBrush(Color.Red);
      for(
140k++)
      {
        
// radius for circle, max 1/2 the width of the form
        
rnd.Next(0, (this.Width 2));
        
rnd.Next(0this.Width);
        
rnd.Next(0this.Height);
 
        
Brush.Color Color.FromArgb(
          (
rnd.Next(0,255)),
          (
rnd.Next(0,255)),
          (
rnd.Next(0,255)));
        
// convert centerX, centerY, radius to bounding rectangle
        
xGraph.FillEllipseBrushx-ry-rr);
      }
      
xGraph.Dispose();
      
this.Invalidate();
    }
 
    
// form load event
    
private void Form1_Load(object senderSystem.EventArgs e)
    {
      
DrawArea = new Bitmap(this.ClientRectangle.Width,
        
this.ClientRectangle.Height,
        
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
      
InitializeDrawArea();
    }
 
    private 
void InitializeDrawArea()
    {
      
Graphics xGraph;
 
      
xGraph Graphics.FromImage(DrawArea);
      
// clear the drawing area to background color
      
xGraph.Clear(Color.LightYellow);
    }
 
    
// free up resources on program exit
    
private void Form1_Closed(object senderSystem.EventArgs e)
    {
      
DrawArea.Dispose();
    }
 
    
// paint event
    
private void Form1_Paint(object sender,
      
System.Windows.Forms.PaintEventArgs e)
    {
      
Graphics xGraph;
 
      
xGraph e.Graphics;
      
xGraph.DrawImage(DrawArea,0,0,DrawArea.Width,DrawArea.Height);
      
xGraph.Dispose();
    }
 
    
// save drawing in bitmap DrawArea as a jpeg file
    
private void btnSave_Click(object senderSystem.EventArgs e)
    {
      
ImageFormat format ImageFormat.Jpeg;
      
SaveFileDialog sfd = new SaveFileDialog();
      
sfd.Filter "JPEG Files(*.jpg)|*.jpg";
 
      if (
sfd.ShowDialog()  == DialogResult.OK)
      {
        
// now save the image in the DrawArea
        
DrawArea.Savesfd.FileNameformat );
      }
    }
 
    
// clear the DrawArea
    
private void btnClear_Click(object senderSystem.EventArgs e)
    {
      
Graphics xGraph;
 
      
xGraph Graphics.FromImage(DrawArea);
      
// clear the drawing area to bg color
      
xGraph.Clear(Color.LightYellow);
      
// free up resource
      
xGraph.Dispose();
      
// update
      
this.Invalidate();
    }
  }


Alıntıdır

__________________
[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]

[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]
 
Alıntı ile Cevapla

IRCForumlari.NET Reklamlar
sohbet odaları sohbet odaları Benimmekan Mobil Sohbet
Cevapla

Etiketler
cizmek, daireler, ekrana, rastgele


Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir)
 

Yetkileriniz
Konu Acma Yetkiniz Yok
Cevap Yazma Yetkiniz Yok
Eklenti Yükleme Yetkiniz Yok
Mesajınızı Değiştirme Yetkiniz Yok

BB code is Açık
Smileler Açık
[IMG] Kodları Açık
HTML-Kodu Kapalı
Trackbacks are Kapalı
Pingbacks are Açık
Refbacks are Açık


Benzer Konular
Konu Konuyu Başlatan Forum Cevaplar Son Mesaj
bilgisayar donunca mouse ile daireler çizmek Heavenly IF Sözlük 2 24 Aralık 2018 23:42
Rüyada Birşey Çizmek Amelia Rüya Tabirleri 0 07 Haziran 2014 21:06
Paint ile Resim Çizmek Satuk Windows 0 03 Eylül 2012 17:09
Çarpık Daireler Ezgi Zeka Küpü 2 16 Aralık 2011 16:09
Putpixel Fonksiyonu ile Köşegen Çizmek Dilaold C ve C++ 0 16 Nisan 2010 13:29