Yurijnd.com
Пятница, 10.05.2024, 20:17
Меню сайта

Вход на сайт

Поиск

Календарь
«  Май 2013  »
ПнВтСрЧтПтСбВс
  12345
6789101112
13141516171819
20212223242526
2728293031

Архив записей

Друзья сайта
  • Официальный блог
  • Сообщество uCoz
  • FAQ по системе
  • Инструкции для uCoz

  • Статистика

    Онлайн всего: 1
    Гостей: 1
    Пользователей: 0

    Главная » 2013 » Май » 15 » C# вращение фигуры
    16:32
    C# вращение фигуры

    Программа вращения фигуры вокруг заданной точки


    Файл Form1.cs


    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;

    namespace WindowsFormsApplication8
    {
    public partial class Form1 : Form
    {

    ObjectCreater objectCreater = new ObjectCreater();
    ObjectTransform objectTransform = new ObjectTransform();
    Graphics graphics;
    float angle;
    PointF pointf;
    float x;
    float y;
    int offsetx;
    int offsety;
    int dx;
    int dy;

    //Image image;

    public Form1()
    {
    InitializeComponent();
    angle = 0;
    x = 150;
    y = 150;
    pointf = new PointF(x, y);
    offsetx = 0;
    offsety = 0;
    dx = 1;
    dy = 1;
    }

    private void button1_Click(object sender, EventArgs e)
    {

    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
    timer1.Enabled = true;
    timer1.Interval = 30;
    objectTransform.ObjectRotate(angle, pointf, offsetx, offsety, e);
    angle += 1;
    if (angle >= 360)
    {
    angle = 0;
    }
    offsetx += dx;
    offsety += dy;
    if (offsetx >= pictureBox1.ClientSize.Width)
    {
    dx = -1;
    }
    else if (offsetx <= 50)
    {
    dx = 1;
    }
    if (offsety >= pictureBox1.ClientSize.Height)
    {
    dy = -1;
    }
    else if (offsety <= 50)
    {
    dy = 1;
    }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
    pictureBox1.Refresh();
    }


    }
    }


    Файл ObjectTransform.cs


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;
    using System.ComponentModel;


    namespace WindowsFormsApplication8
    {
    public class ObjectTransform
    {
    Pen pen;

    public ObjectTransform()
    {
    pen = new Pen(Color.Black, 1);
    }

    public Graphics ObjectRotate(float angle,PointF pointf, int offsetX, int offsetY, PaintEventArgs e)
    {
    SolidBrush brush = new SolidBrush(Color.Blue);
    Matrix matrix = new Matrix();
    //matrix.Translate(offsetX, offsetY);
    matrix.RotateAt(angle, pointf, MatrixOrder.Append);
    //matrix.Translate(offsetX, offsetY);
    e.Graphics.Transform = matrix;
    e.Graphics.FillRectangle(brush, 100, 100, 20, 20);
    return e.Graphics;
    }
    }
    }

    Просмотров: 3841 | Добавил: yurijnd | Рейтинг: 3.0/2
    Всего комментариев: 0
    Имя *:
    Email *:
    Код *:
    Copyright MyCorp © 2024
    Сделать бесплатный сайт с uCoz