При нажатии на кнопку на pictureBox не рисуется прямоугольник. Может есть ошибка? Помогите!
Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace Курсовой_ОС
{
public partial class Form1 : Form
{
Page[] binaryvector; //структура данных хранящая иформацию о занятых и свободных страницах
int count;//вспомогательная переменная для задания идентификатора страницам
int APOPsize;//размер АП ОП
int size;//размер страниц
public Form1()
{
InitializeComponent();
size = 16;
binaryvector = new Page[APOPsize / size];
count = 0;
APOPsize = 256;
}
public class Page//класс страницы
{
string name;//идентификатор
int size;//размер
int adress;//адрес
bool busy;//занятость страницы
Rectangle rect;
public Page(int adress, int size, Rectangle rect)//конструктор
{
this.adress = adress;
this.size = size;
this.rect = rect;
}
public int Size
{
get { return size; }
set { size = value; }
}
public int Adress
{
get { return adress; }
set { adress = value; }
}
public Rectangle Rect
{
get { return rect; }
set { rect = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public bool Busy
{
get { return busy; }
set { busy = value; }
}
public void Draw(Graphics e)//отрисовка на форме
{
e.FillRectangle(new SolidBrush(Color.Orange), rect);
e.DrawRectangle(new Pen(Color.Black), rect);
e.DrawString(name + " Адрес " + adress + " Размер " + size, new Font("Arial", 9), new SolidBrush(Color.Black), rect.Location);
}
}
private void button3_Click(object sender, EventArgs e) // Размещение страницы
{
bool temp = false;
for (int i = 0; i < binaryvector.Length; i++)
{
if (binaryvector[i].Busy == false)
{
binaryvector[i].Name = "Страница " + count;
binaryvector[i].Busy = true;
listBox1.Items.Add(binaryvector[i].Adress);
temp = true;
break;
}
}
if (temp == false)
{
Random rnd = new Random();
int r = rnd.Next(0, binaryvector.Length);
binaryvector[r].Name = "Страница " + count;
}
count++;
pictureBox1.Refresh();
button4.Enabled = true;
listBox1.Enabled = true; ;
}
private void button4_Click(object sender, EventArgs e) // удаление (освобождение) страницы
{
for (int i = 0; i < binaryvector.Length; i++)
{
if (Convert.ToInt32(listBox1.SelectedItem) == Convert.ToInt32(binaryvector[i].Adress))
{
listBox1.Items.Remove(Convert.ToInt32(binaryvector[i].Adress));
binaryvector[i].Busy = false;
pictureBox1.Refresh();
}
}
bool temp = false;
for (int i = 0; i < binaryvector.Length; i++)
{
if (binaryvector[i].Busy == true)
{
temp = true;
}
}
if (temp == false)
{
button4.Enabled = false;
listBox1.Enabled = false;
}
}
private void Form1_Paint(object sender, PaintEventArgs e) //Отображение АП ПО
{
e.Graphics.DrawString("0", new Font("Arial", 9), new SolidBrush(Color.Black), pictureBox1.Location.X - 10, pictureBox1.Location.Y - 10);
e.Graphics.DrawString(Convert.ToString(APOPsize), new Font("Arial", 9), new SolidBrush(Color.Black), pictureBox1.Location.X - 25, pictureBox1.Location.Y + pictureBox1.Height);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)//отображение страниц
{
if (binaryvector.Length != 0)
{
for (int i = 0; i < binaryvector.Length; i++)
{
if (binaryvector[i].Busy == true)
{
binaryvector[i].Draw(e.Graphics);
}
}
}
}
private void button5_Click(object sender, EventArgs e) //Освобождение АП
{
button3.Enabled = false;
button2.Enabled = false;
comboBox2.Enabled = false;
button1.Enabled = true;
comboBox1.Enabled = true;
button4.Enabled = false;
listBox1.Enabled = false;
listBox1.Items.Clear();
for (int i = 0; i < binaryvector.Length; i++)
{
binaryvector[i].Busy = false;
}
count = 0;
pictureBox1.Refresh();
}
private void button2_Click(object sender, EventArgs e) // задать размер страницы
{
size = Convert.ToInt32(comboBox2.Text);
if (size <= APOPsize)
{
binaryvector = new Page[APOPsize / size];
for (int i = 0; i < binaryvector.Length; i++)
{
binaryvector[i] = new Page(i * size, size, new Rectangle(new Point(0, i * pictureBox1.Height / binaryvector.Length), new Size(pictureBox1.Width, pictureBox1.Height / binaryvector.Length)));
}
button2.Enabled = false;
comboBox2.Enabled = false;
button3.Enabled = true;
}
else MessageBox.Show("Размер страницы должен быть меньше размера адресного пространства");
}
private void button1_Click(object sender, EventArgs e)
{
APOPsize = Convert.ToInt32(comboBox1.Text);
this.Refresh();
button1.Enabled = false;
comboBox1.Enabled = false;
button2.Enabled = true;
comboBox2.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
button2.Enabled = false;
comboBox2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
listBox1.Enabled = false;
}
}
}
Пожалуйста, оформляйте программный код по правилам. Модератор.