pborawski

C# rysowanie w oknie , panele wlasne

Mar 26th, 2012
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication2
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         private MojPanel mp1, mp2;
  15.            
  16.         private void rysuj_Click(object sender, EventArgs e)
  17.         {
  18.             Graphics g = CreateGraphics();
  19.             try
  20.             {
  21.                 int szer = ClientRectangle.Width;
  22.                 int wys = ClientRectangle.Height;
  23.                 int r = 40;
  24.                 g.DrawEllipse(Pens.Red, szer / 2 - r, wys / 2 - r, 2 * r, 2 * r);
  25.                
  26.             }
  27.             finally
  28.             {
  29.                 g.Dispose();
  30.             }
  31.         }
  32.         public Form1()
  33.         {
  34.             //OnClick += new EventHandler(rysuj_Click);
  35.             mp1 = new MojPanel(this, 50, 50, 100, 100, Color.Blue);
  36.             mp2 = new MojPanel(this, 400, 400, 200, 200, Color.LightGray);
  37.            
  38.  
  39.             InitializeComponent();
  40.         }
  41.  
  42.         private void Form1_Load(object sender, EventArgs e)
  43.         {
  44.  
  45.         }
  46.  
  47.         private void rysuj2_Click(object sender, EventArgs e)
  48.         {
  49.             using (Graphics g = CreateGraphics())
  50.             {
  51.                 int szer = ClientRectangle.Width;
  52.                 int wys = ClientRectangle.Height;
  53.                 int bok = 50;
  54.                 g.DrawRectangle(Pens.Blue, szer / 2, wys / 2, bok, bok);
  55.             }
  56.         }
  57.  
  58.         private void Form1_Paint(object sender, PaintEventArgs e)
  59.         {
  60.             Graphics g = e.Graphics;
  61.             int szer = ClientRectangle.Width;
  62.             int wys = ClientRectangle.Height;
  63.             int oczko = 10;
  64.             int marg = 20;
  65.  
  66.             for (int i = marg; i <= wys - marg; i += 10)
  67.             {
  68.                 for (int j = marg; j <= szer - marg; j += 10)
  69.                 {
  70.                     SolidBrush b = new SolidBrush(Color.FromArgb(i % 256, j % 256, 200));
  71.                     g.DrawRectangle(Pens.Black, j, i, oczko, oczko);
  72.                     g.FillRectangle(b, j, i, oczko, oczko);
  73.                 }
  74.             }
  75.         }
  76.        
  77.  
  78.         private void Form1_Resize(object sender, EventArgs e)
  79.         {
  80.             Invalidate();
  81.         }        
  82.     }
  83.     public class MojPanel : Panel
  84.     {
  85.         public MojPanel(Form aparent, int x, int y, int szer, int wys, Color k)
  86.         {
  87.  
  88.             Parent = aparent;
  89.             Left = x;
  90.             Top = y;
  91.             Width = szer;
  92.             Height = wys;
  93.             BackColor = k;
  94.         }
  95.         protected override void OnPaint(PaintEventArgs e)
  96.         {
  97.             int szer = ClientRectangle.Width;
  98.             int wys = ClientRectangle.Height;
  99.             Graphics g = e.Graphics;
  100.             g.DrawLine(Pens.Azure, 0, wys, szer, 0);
  101.  
  102.         }
  103.     }
  104. }
  105. /* =================
  106. http://www9.zippyshare.com/v/18094249/file.html
  107.    ================= */
Advertisement
Add Comment
Please, Sign In to add comment