Har qanday gdi loyihasini yaratishda kuzatilishi kerak bo'lgan muhim fikrlarni ta'kidlaymiz



Yüklə 36,34 Kb.
tarix10.06.2023
ölçüsü36,34 Kb.
#128260
Amaliyot 8


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



  1. C#da geometric shakllar graphigi

  2. C#da algebraik funksiyalar graphigi

  3. C#da trigonometric funksiyalar graphigi

  4. C#da logorifmik funksiyalar graphigi

  5. C#da teskari trigonometric funksiyalar graphigi

  6. C#da ko’rsatkichli funksiyalar graphigi

  7. C#da algebraik tenglamaning graphic echimi

  8. C#da transident tenglamaning graphic echimi

Yüklə 36,34 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin