Amaliyot 8
C# da graphica
Har qanday GDI loyihasini yaratishda kuzatilishi kerak bo'lgan muhim fikrlarni ta'kidlaymiz:
– Graphics sinfining g xossasi aniqlanishi kerak;
– Paint-da hodisa ishlov beruvchisini yaratishingiz kerak, unda
Draw() usuli chaqiriladi.
Draw() usulida:
– CreateGraphics() usuli bilan g ob’ektni yaratish kerak;
– chizma yuzasini tozalash uchun Clear() usulidan foydalanish;
- biror narsani chizish;
– g obyektidan xotirani bo‘shatish.
Graphics klassi ko'plab xususiyatlarni o'z ichiga oladi.
namuna
namespace grd
{ public partial class MainForm : Form
{
Graphics g;
private void Draw()
{
g = CreateGraphics();
g.Clear(Color.White);
g.DrawEllipse(Pens.Black,10,10,200,100);
g.Dispose();
}
public MainForm()
{ InitializeComponent();
Draw(); //
}
void MainFormPaint(object sender, PaintEventArgs e)
{
Draw();
}
}
}
Koordinatalarni boshqarish
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace grd
{ public partial class MainForm : Form
{
Graphics g;
private void Draw()
{
g = CreateGraphics();
g.Clear(Color.White);
g.PageUnit = GraphicsUnit.Pixel;
g.DrawEllipse(Pens.Black, 10, 10, 200, 100);
g.PageUnit = GraphicsUnit.Display;
g.DrawEllipse(Pens.Black, 10, 10, 200, 100);
g.PageUnit = GraphicsUnit.Point;
g.DrawEllipse(Pens.Black, 10, 10, 200, 100);
g.PageUnit = GraphicsUnit.Millimeter;
g.DrawEllipse(Pens.Black, 10, 10, 20, 10);
g.PageUnit = GraphicsUnit.Document;
g.DrawEllipse(Pens.Black, 10, 10, 200, 100);
Pen myPen = new Pen(Color.Black,0.05F);
g.PageUnit = GraphicsUnit.Inch;
g.DrawEllipse(myPen, 1, 1, 2, 1);
g.Dispose();
}
public MainForm()
{ InitializeComponent();
Draw(); // }
void MainFormPaint(object sender, PaintEventArgs e)
{
Draw();
}
}
}
Sin(x) graphigi
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace sd
{ public partial class MainForm : Form
{
public MainForm()
{ InitializeComponent();
}
void MainFormPaint(object sender, PaintEventArgs e)
{
}
void Button1Click(object sender, EventArgs e)
{
int imax =100;
int t=2;
int amp=70;
int h = 40;
int x0=20;
int y0 = h+amp;
double[] f = new double [imax*t+10];
for (int i = 0; i < imax * t; i++)
{
f[i] = Math.Round(amp * Math.Sin(2 * Math.PI / imax * i));
}
Graphics g = Graphics.FromHwnd(this.Handle);
Pen pen = Pens.Black;
g.DrawString("График синусоидa", new Font("Arial", 14),
Brushes.Red, 0, 0);
g.DrawLine(pen , x0, y0, x0+imax*t, y0);
g.DrawLine(pen, x0, y0-amp, x0, y0+amp);
for (int i = 0; i < imax * t; i++)
{
int f1 = y0 - (int)f[i];
int f2 = y0 - (int)f[i + 1];
g.DrawLine(pen, x0+i, f1, x0+i+1, f2);
}
}
}
}
Topshiriqlar
C#da geometric shakllar graphigi
C#da algebraik funksiyalar graphigi
C#da trigonometric funksiyalar graphigi
C#da logorifmik funksiyalar graphigi
C#da teskari trigonometric funksiyalar graphigi
C#da ko’rsatkichli funksiyalar graphigi
C#da algebraik tenglamaning graphic echimi
C#da transident tenglamaning graphic echimi
Dostları ilə paylaş: |