ForumAlem
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Yeni bir forum kurmak | ©phpBB | Bedava yardımlaşma forumu | Suistimalı göstermek | Son tartışmalar
ForumAlem

ForumAlem
 
AnasayfaAnasayfa  Latest imagesLatest images  AramaArama  Kayıt OlKayıt Ol  Giriş yapGiriş yap  

 

 C++ Klasik Duvar Saati

Aşağa gitmek 
YazarMesaj
KaoS
Admin
Admin
KaoS


Mesaj Sayısı : 170
Kayıt tarihi : 02/08/08
Yaş : 35
Nerden : KONYA

C++ Klasik Duvar Saati Empty
MesajKonu: C++ Klasik Duvar Saati   C++ Klasik Duvar Saati Icon_minitimePerş. Ağus. 14, 2008 10:17 pm

using System;
using System.Windows.Forms;
using System.Drawing;
Kod:

class MyForm : Form
{
MyForm ()
{
Text = "Clock";
SetStyle (ControlStyles.ResizeRedraw, true);
}

protected override void OnPaint (PaintEventArgs e)
{
SolidBrush red = new SolidBrush (Color.Red);
SolidBrush white = new SolidBrush (Color.White);
SolidBrush blue = new SolidBrush (Color.Blue);

// Initialize the transformation matrix
InitializeTransform (e.Graphics);

// Draw squares denoting hours on the clock face
for (int i=0; i<12; i++) {
e.Graphics.RotateTransform (30.0f);
e.Graphics.FillRectangle (white, 85, -5, 10, 10);
}

// Get the current time
DateTime now = DateTime.Now;
int minute = now.Minute;
int hour = now.Hour % 12;

// Reinitialize the transformation matrix
InitializeTransform (e.Graphics);

// Draw the hour hand
e.Graphics.RotateTransform ((hour * 30) + (minute / 2));
DrawHand (e.Graphics, blue, 40);

// Reinitialize the transformation matrix
InitializeTransform (e.Graphics);

// Draw the minute hand
e.Graphics.RotateTransform (minute * 6);
DrawHand (e.Graphics, red, 80);

// Dispose of the brushes
red.Dispose ();
white.Dispose ();
blue.Dispose ();
}

void DrawHand (Graphics g, Brush brush, int length)
{
// Draw a hand that points straight up, and let
// RotateTransform put it in the proper orientation
Point[] points = new Point[4];
points[0].X = 0;
points[0].Y = -length;
points[1].X = -12;
points[1].Y = 0;
points[2].X = 0;
points[2].Y = 12;
points[3].X = 12;
points[3].Y = 0;

g.FillPolygon (brush, points);
}

void InitializeTransform (Graphics g)
{
// Apply transforms that move the origin to the center
// of the form and scale all output to fit the form's width
// or height
g.ResetTransform ();
g.TranslateTransform (ClientSize.Width / 2,
ClientSize.Height / 2);
float scale = System.Math.Min (ClientSize.Width,
ClientSize.Height) / 200.0f;
g.ScaleTransform (scale, scale);
}

static void Main ()
{
Application.Run (new MyForm ());
}
Sayfa başına dön Aşağa gitmek
https://forumalem.hareketforum.net
 
C++ Klasik Duvar Saati
Sayfa başına dön 
1 sayfadaki 1 sayfası
 Similar topics
-

Bu forumun müsaadesi var:Bu forumdaki mesajlara cevap veremezsiniz
ForumAlem :: Programlama Dilleri :: C / C++ / C#-
Buraya geçin: