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 grafika_oszlopdiagram
- {
- public partial class Form1 : Form
- {
- Random rand;
- Graphics g;
- int[] ertekek;
- GraphicsContainer container;
- LinearGradientBrush linearBrush;
- Rectangle area;
- int height;
- int width;
- int distance;
- int bar_width;
- int bar_height;
- public Form1()
- {
- InitializeComponent();
- rand = new Random();
- g = CreateGraphics();
- ertekek = new int[5];
- g.SmoothingMode = SmoothingMode.AntiAlias;
- for (int i = 0; i < ertekek.Length; i++)
- {
- ertekek[i] = rand.Next(2, 10);
- }
- container = g.BeginContainer();
- }
- private void trackBar1_Scroll(object sender, EventArgs e)
- {
- Invalidate();
- Update();
- // Trackbar maximum = 300;
- height = trackBar1.Value;
- width = trackBar1.Value;
- distance = 10;
- bar_height = ((area.Height / ertekek.Length - 1) - distance) < 50 ?
- ((area.Height / ertekek.Length - 1) - distance) : 50;
- area = new Rectangle(20, 20, width, height);
- // Area
- g.DrawRectangle(new Pen(Color.Chocolate, 4), area);
- for (int i = 0; i < ertekek.Length; i++)
- {
- float sum = ertekek.Sum();
- bar_width = (int)((ertekek[i] / sum) * area.Width) * ertekek.Length / 2;
- if (bar_height == 0)
- {
- bar_height = 1;
- }
- if (bar_width == 0)
- {
- bar_width = 1;
- }
- Rectangle rect = new Rectangle(area.X + 10, area.Y + (int)distance, bar_width, bar_height);
- linearBrush = new LinearGradientBrush(rect, Color.Tan, Color.Peru, LinearGradientMode.ForwardDiagonal);
- distance += bar_height + 8;
- g.FillRectangle(linearBrush, rect);
- g.DrawRectangle(Pens.Brown, rect);
- }
- g.EndContainer(container);
- }
- private void trackBar2_Scroll(object sender, EventArgs e)
- {
- Invalidate();
- Update();
- g.RotateTransform(trackBar2.Value);
- g.Save();
- trackBar1_Scroll(this, e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement