Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ProjetoImagem
- {
- public partial class Form1 : Form
- {
- string pasta_imagens = "";
- Image img_normal; //Imagem do botão
- Image img_high; // Quando o mouse passa por cima do botão
- Image img_disabled; //Quando o botão está inativo
- int largura;
- int altura;
- List<cl_bola> BOLAS = new List<cl_bola>();
- //=======================================
- public Form1()
- {
- InitializeComponent();
- pasta_imagens = Application.StartupPath + @"\img\";
- //=======================================
- //carregamento da imagem do fundo
- //img_fundo = Image.FromFile(pasta_imagens + "foto_1.jpg");
- //pic_teste.BackgroundImage = img_fundo;
- img_normal = Image.FromFile(pasta_imagens + "btn_normal.png");
- img_high = Image.FromFile(pasta_imagens + "btn_high.png");
- img_disabled = Image.FromFile(pasta_imagens + "btn_disabled.png");
- //Rectangle rect = pic_teste.Bounds;
- ////MessageBox.Show(rect.X.ToString() + " - " +
- // rect.Y.ToString() + " - " +
- // rect.Width.ToString() + " - " +
- // rect.Height.ToString() + " - ");
- //int largura = img_fundo.Width;
- //int altura = img_fundo.Height;
- //MessageBox.Show(string.Format("Largura: {0} | Altura : {1}", largura, altura));
- }
- //=======================================
- private void Form1_Load(object sender, EventArgs e)
- {
- btn_teste.BackgroundImage = img_normal;
- largura = pic_teste.Width;
- altura = pic_teste.Height;
- }
- private void pic_teste_Click(object sender, EventArgs e)
- {
- MessageBox.Show("PictureBox clicada");
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //ativa ou desativa o btn_teste
- if (btn_teste.Enabled)
- btn_teste.Enabled = false;
- else
- btn_teste.Enabled = true;
- ////pic_teste.Location = new Point(382, 220);
- //Rectangle r_pic = pic_teste.Bounds;
- //Rectangle r_but = button2.Bounds;
- //button2.Location = new Point(r_pic.X + r_pic.Width / 2 - r_but.Width / 2,
- // r_pic.Y + r_pic.Height / 2 - r_but.Height / 2);
- ////button2.Location = new Point(r.X, r.Y);
- ////button2.Location = new Point(r.X, r.Bottom);
- }
- private void btn_teste_MouseEnter(object sender, EventArgs e)
- {
- //altera a imagem para high
- btn_teste.BackgroundImage = img_high;
- }
- private void btn_teste_MouseLeave(object sender, EventArgs e)
- {
- //regressa ao aspeto noromal do botão
- btn_teste.BackgroundImage = img_normal;
- }
- private void btn_teste_Click(object sender, EventArgs e)
- {
- //criar a folha em branco
- //Bitmap imgback = new Bitmap(pic_teste.Width, pic_teste.Height);
- //Graphics desenhador = Graphics.FromImage(imgback);
- //Image bola = Image.FromFile(pasta_imagens + "bola_pequena.png");
- //Pen lapis = new Pen(Color.LightGray, 5);
- ////atribuir uma cor de fundo da imagem
- //desenhador.Clear(Color.Black);
- //desenhador.DrawImage(bola, new Rectangle(100, 100, 50, 50), new Rectangle(0, 0, 50, 50), GraphicsUnit.Pixel);
- ////cortar e colar uma porção de imagens
- //desenhador.DrawImage(original, new Rectangle(50, 50, 50, 50), new Rectangle(90, 100, 50, 50), GraphicsUnit.Pixel);
- //desenhador.DrawImage(original, new Rectangle(150, 50, 100, 100), new Rectangle(90, 100, 50, 50), GraphicsUnit.Pixel);
- //string texto = "Lorem Ipsum é simplesmente uma simulação de texto da indústria tipográfica e de impressos, e vem sendo utilizado desde o século XVI.";
- //Brush cor = new SolidBrush(Color.Black);
- //Font letra = new Font("Ariarl", 12, FontStyle.Regular, GraphicsUnit.Pixel);
- //Rectangle rect = new Rectangle(50, 50, 500, 100);
- //StringFormat alinhamento = new StringFormat();
- //alinhamento.Alignment = StringAlignment.Center;
- //alinhamento.LineAlignment = StringAlignment.Center;
- //desenhador.DrawRectangle(lapis, rect);
- //desenhador.DrawString(texto, letra, cor, rect, alinhamento);
- //string texto = "Ola mundo";
- //Font letra = new Font("Courrier", 40, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Pixel);
- //Brush cor_principal = new SolidBrush(Color.FromArgb(200, 180, 0));
- //Brush cor_sombra = new SolidBrush(Color.Black);
- //Point inicio = new Point(50, 50);
- //Point inicio_sombra = new Point(50, 55);
- //desenhador.DrawString(texto, letra, cor_sombra, inicio_sombra);
- //desenhador.DrawString(texto, letra, cor_principal, inicio);
- //Pen lapis = new Pen(Color.Black, 3);
- //Pen lapis_vermelho = new Pen(Color.Red);
- ////desenhar linha quebrada
- //Point[] pontos = new Point[]
- //{
- // new Point(50, 50),
- // new Point(100, 80),
- // new Point(100, 150)
- //};
- //desenhador.DrawLine(lapis, pontos);
- // //circuferência
- //desenhador.DrawEllipse(lapis, new Rectangle(100, 100, 200, 200));
- //desenhador.DrawRectangle(lapis_vermelho, new Rectangle(100, 100, 200, 200));
- //Brush pincel_1 = new SolidBrush(Color.Red);
- //Brush pincel_2 = new LinearGradientBrush(new Point(150, 50), new Point(250, 50), Color.Red, Color.Yellow);
- //Brush pincel_3 = new SolidBrush(Color.Yellow);
- //desenhador.FillRectangle(pincel_1, new Rectangle(50, 50, 100, 250));
- //desenhador.FillRectangle(pincel_2, new Rectangle(150, 50, 100, 250));
- //desenhador.FillRectangle(pincel_3, new Rectangle(250, 50, 100, 250));
- //desenhador.FillEllipse(pincel_1, new Rectangle(50, 50, 500, 200));
- //Rectangle rec = new Rectangle(50, 50, 300, 200);
- //desenhador.FillRectangle(pincel_3, rec);
- //desenhador.DrawRectangle(lapis, rec);
- //apresenta a imagem final
- // pic_teste.BackgroundImage = imgback;
- }
- private void Desenhar()
- {
- //criar a folha em branco
- Bitmap imgback = new Bitmap(pic_teste.Width, pic_teste.Height);
- Graphics desenhador = Graphics.FromImage(imgback);
- Image img_bola = Image.FromFile(pasta_imagens + "bola_pequena.png");
- Pen lapis = new Pen(Color.LightGray, 5);
- //atribuir uma cor de fundo da imagem
- desenhador.Clear(Color.Black);
- //ciclo que percorre todas as bolas percorrentes
- foreach (cl_bola bola in BOLAS)
- {
- bola.Mover(largura, altura);
- desenhador.DrawImage(img_bola, new Rectangle(bola.x, bola.y, 50, 50), new Rectangle(0, 0, 50, 50), GraphicsUnit.Pixel);
- }
- //apresenta a imagem final
- pic_teste.BackgroundImage = imgback;
- }
- private void btn_teste_EnabledChanged(object sender, EventArgs e)
- {
- //define a imagem ativa ou inativa do btn_teste
- if (btn_teste.Enabled)
- btn_teste.BackgroundImage = img_normal;
- else
- btn_teste.BackgroundImage = img_disabled;
- }
- public Pen lapis { get; set; }
- private void tempo_Tick(object sender, EventArgs e)
- {
- Desenhar();
- //x += velocidade_x;
- //y += velocidade_y;
- ////colisões
- ////detecta colisão do fundo
- //if (y + 50 >= pic_teste.Height)
- // velocidade_y = -velocidade_y;
- ////detecta colisão no top
- //if (y <= 0)
- // velocidade_y = -velocidade_y;
- ////detecta colisão a esquerda
- //if (x <= 0)
- // velocidade_x = -velocidade_x;
- ////detecta colisão da direita
- //if (x + 50 >= pic_teste.Width)
- // velocidade_x = -velocidade_x;
- //mover a imagem
- //x += 20;
- //Desenhar();
- //if (x >= 770)
- // tempo.Enabled = false;
- }
- private void button2_Click(object sender, EventArgs e)
- {
- cl_bola b = new cl_bola();
- BOLAS.Add(b);
- tempo.Enabled = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement