1-Amaliy mashg’ulot.
1-topshiriq. Mexanik mukammal kalkulyator yarating.
/*
* Created by SharpDevelop.
* User: User
* Date: 20.04.2022
* Time: 13:48
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace kalkulyator
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
double a=0;
string s="";
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void MainFormLoad(object sender, EventArgs e)
{
}
void Button3Click(object sender, EventArgs e)
{
if(Hisob.Text=="0")
Hisob.Clear();
Button q=(Button)sender;
Hisob.Text=Hisob.Text+q.Text;
}
void Button4Click(object sender, EventArgs e)
{
Hisob.Text="0";
}
void Button13Click(object sender, EventArgs e)
{
a=Double.Parse(Hisob.Text);
Hisob.Text="0";
s="/";
}
void Button14Click(object sender, EventArgs e)
{
a=Double.Parse(Hisob.Text);
Hisob.Text="0";
s="*";
}
void Button15Click(object sender, EventArgs e)
{
a=Double.Parse(Hisob.Text);
Hisob.Text="0";
s="-";
}
void Button16Click(object sender, EventArgs e)
{
a=Double.Parse(Hisob.Text);
Hisob.Text="0";
s="+";
}
void Button12Click(object sender, EventArgs e)
{
switch(s)
{
case "/":
Hisob.Text=(a / Double.Parse(Hisob.Text)).ToString();
break ;
case "*":
Hisob.Text=(a * Double.Parse(Hisob.Text)).ToString();
break ;
case "-":
Hisob.Text=(a - Double.Parse(Hisob.Text)).ToString();
break ;
case "+":
Hisob.Text=(a + Double.Parse(Hisob.Text)).ToString();
break ;
default:
break;
}
}
}
Natija:
3-topshiriq.Bolalar qo’shish va ayirish amalini avtomatik tekshiruvchi dastur.
class Program
{
public static void Main(string[] args)
{
int A,B,C,D,E,F;
Console.Write("Birinchi sonni kiriting A=");
A=int.Parse(Console.ReadLine());
Console.Write("Ikkinchi sonni kiriting B=");
B=int.Parse(Console.ReadLine());
Console.Write("Yig'indini kiriting:");
C=A+B; D=A+B;
C=int.Parse(Console.ReadLine());
Console.Write("Ayirmani kiriting:");
E=A-B; F=A-B;
E=int.Parse(Console.ReadLine());
if (C==D)
Console.WriteLine("Yig'indi to'g'ri");
else
Console.WriteLine("Yig'indi noto'g'ri . To'g'ri javob" +D);
if (E==F)
Console.WriteLine("Ayirma to'g'ri");
else
Console.WriteLine("Ayirma noto'g'ri . To'g'ri javob" +F);
Console.ReadKey(true);
}
}
Natija:
5-Amaliy mashg’ulot
1-topshiriq. Graphics kutubxonasi operatorlaridan foydalanib, “mening uyim” nomli uy tasvirini chizish.
void Button1Click(object sender, EventArgs e)
{
Graphics rasm=pictureBox1.CreateGraphics();
Pen qalam=new Pen(Color.Gray,5);
Pen qora_qalam=new Pen(Color.Chocolate,5);
rasm.DrawLine(qalam,50,10,250,10);
rasm.DrawLine(qalam,50,10,10,100);
rasm.DrawLine(qalam,50,10,100,100);
rasm.DrawLine(qalam,250,10,300,100);
rasm.DrawLine(qalam,100,100,300,100); // uyni tom qismini chizish
rasm.DrawLine(qalam,10,100,100,100);
rasm.DrawRectangle(qalam,10,100,90,100);
rasm.DrawRectangle(qalam,100,100,200,100);
Brush b=new SolidBrush(Color.Orange);
Brush c=new SolidBrush(Color.Pink);
rasm.FillRectangle(b,10,100,90,100);
rasm.FillRectangle(c,100,100,200,100); // uyni chizish
Rectangle rec1=new Rectangle(37,55,30,30);
rasm.DrawEllipse(qalam,rec1);
rasm.FillEllipse(c,rec1);
rasm.DrawRectangle(qora_qalam,30,120,55,77); //eshik
rasm.DrawLine(qora_qalam,30,135,88,135);
rasm.DrawLine(qora_qalam,55,120,55,135);
Brush d=new SolidBrush(Color.Chocolate);
rasm.FillRectangle(d,30,138,55,65);
rasm.DrawRectangle(qora_qalam,150,120,90,60);
rasm.DrawLine(qora_qalam,195,120,195,180);
rasm.DrawLine(qora_qalam,150,150,240,150); //deraza
}
Natija:
6-Amaliy mashg’ulot
1-topshiriq.”Svetafor” animatsiyasini yarating.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Svetafor
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
Random rnd=new Random();
public MainForm()
{
InitializeComponent();
}
void Timer1Tick(object sender, EventArgs e)
{
Graphics anim=pictureBox2.CreateGraphics();
Pen qalam = new Pen(Color.DarkGray,4);
Pen Qalam1 = new Pen(Color.DarkGray,4);
Pen Qalam2 = new Pen(Color.DarkGray,4);
Pen Qalam3 = new Pen(Color.DarkGray,4);
Brush myBrush =new SolidBrush(Color.Black);
Brush Brush1 =new SolidBrush(Color.Green);
Brush Brush2 =new SolidBrush(Color.Orange);
Brush Brush3 =new SolidBrush(Color.DarkRed);
anim.DrawRectangle(qalam,50,70,400,240);
anim.FillRectangle(myBrush,50,70,660,240);
anim.FillEllipse(Brush3, 70, 90, 200, 200);
anim.DrawEllipse(Qalam3, 70, 90, 200, 200);
anim.FillEllipse(Brush2, 280, 90, 200, 200);
anim.DrawEllipse(Qalam2, 280, 90, 200, 200);
anim.FillEllipse(Brush1, 490, 90, 200, 200);
anim.DrawEllipse(Qalam1, 490, 90, 200, 200);
Graphics yashil=pictureBox2.CreateGraphics();
Graphics sariq=pictureBox2.CreateGraphics();
Graphics qizil=pictureBox2.CreateGraphics();
for (int i=0; i<=10; i+=10)
{
Color qorar=Color.White;
Color qizilr=Color.Red;
Pen q=new Pen(qorar,5);
Brush sfq = new SolidBrush(qizilr);
anim.FillEllipse(Brush2, 280, 90, 200, 200);
anim.DrawEllipse(Qalam2, 280, 90, 200, 200);
anim.FillEllipse(Brush1, 490, 90, 200, 200);
anim.DrawEllipse(Qalam1, 490, 90, 200, 200);
Thread.Sleep(50);
anim.DrawEllipse(q, 70, 90, 200, 200);
anim.FillEllipse(sfq, 70, 90, 200, 200);
Thread.Sleep(500);
}
for (int j=0; j<=10; j+=10)
{
Color sariqr=Color.Yellow;
Pen s=new Pen(sariqr,5);
Brush sfs = new SolidBrush(sariqr);
anim.FillEllipse(Brush3, 70, 90, 200, 200);
anim.DrawEllipse(Qalam3, 70, 90, 200, 200);
anim.FillEllipse(Brush1, 490, 90, 200, 200);
anim.DrawEllipse(Qalam1, 490, 90, 200, 200);
Thread.Sleep(50);
anim.DrawEllipse(s, 280, 90, 200, 200);
anim.FillEllipse(sfs, 280, 90, 200, 200);
Thread.Sleep(500);
}
for (int k=0; k<=10; k+=10)
{
Color yashilr=Color.LightGreen;
Pen y=new Pen(yashilr,5);
Brush sfy = new SolidBrush(yashilr);
anim.FillEllipse(Brush3, 70, 90, 200, 200);
anim.DrawEllipse(Qalam3, 70, 90, 200, 200);
anim.FillEllipse(Brush2, 280, 90, 200, 200);
anim.DrawEllipse(Qalam2, 280, 90, 200, 200);
Thread.Sleep(50);
anim.DrawEllipse(y, 490, 90, 200, 200);
anim.FillEllipse(sfy, 490, 90, 200, 200);
Thread.Sleep(500);
}
}
void Button1Click(object sender, EventArgs e)
{
timer1.Enabled=true;
}
void Button3Click(object sender, EventArgs e)
{
this.Close();
}
void Button2Click(object sender, EventArgs e)
{
timer1.Enabled=false;
}
void Button4Click(object sender, EventArgs e)
{
Graphics anim=pictureBox2.CreateGraphics();
Pen qalam = new Pen(Color.DarkGray,4);
Pen Qalam1 = new Pen(Color.DarkGray,4);
Pen Qalam2 = new Pen(Color.DarkGray,4);
Pen Qalam3 = new Pen(Color.DarkGray,4);
Brush myBrush =new SolidBrush(Color.Black);
Brush Brush1 =new SolidBrush(Color.LightGreen);
Brush Brush2 =new SolidBrush(Color.Yellow);
Brush Brush3 =new SolidBrush(Color.DarkRed);
anim.DrawRectangle(qalam,50,70,400,240);
anim.FillRectangle(myBrush,50,70,660,240);
anim.FillEllipse(Brush3, 70, 90, 200, 200);
anim.DrawEllipse(Qalam3, 70, 90, 200, 200);
anim.FillEllipse(Brush2, 280, 90, 200, 200);
anim.DrawEllipse(Qalam2, 280, 90, 200, 200);
anim.FillEllipse(Brush1, 490, 90, 200, 200);
anim.DrawEllipse(Qalam1, 490, 90, 200, 200);
}
void PictureBox2Click(object sender, EventArgs e)
{
}
}
}
Natija:
Blaknot.
namespace daftar
{
public partial class Form1 : Form
{
// dastur boshlanishi
string filePath = "";
public Form1()
{
InitializeComponent();
}
private void fileToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
filePath = "";
richTextBox1.Text = "";
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
//Code for open a txt file
Do'stlaringiz bilan baham: |