
10.11.2008, 00:30
|
|
Новичок
Регистрация: 09.11.2008
Сообщений: 1
С нами:
9211410
Репутация:
0
|
|
вывод матрицы на форму
помогите пожалуйста с выводом матрицы на форму...
вот код самой программы: (это вывод просто на консольку)
Код:
/* Сформировать квадратную матрицу A(15,15) следующего вида:
* 0 0 0 ... 0 1
* 0 0 0 ... 1 0
* .............
* 0 1 0 ... 0 0
* 1 0 0 ... 0 0
*/
using System;
namespace Task2
{
class ArrayDemo
{
public static void Main(string[] args)
{
Console.Title = "";
Console.BackgroundColor = ConsoleColor.White;//цвет формы
Console.ForegroundColor = ConsoleColor.Black;//цвет текста формы
do
{
const uint N = 15;
int[,] A = new int[N, N];
Console.Clear();
solution(A, N);
write(A, N);
Console.WriteLine();
Console.WriteLine("Нажмите Esc для выхода!");
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
}
static void solution(int[,] arr, uint l)
{
for (int i = 0; i < l; i++)
for (int j = 0; j < l; j++)
if (i + j == l - 1)
arr[i, j] = 1;
}
static void write(int[,] arr, uint l)
{
for (int i = 0; i < l; i++,Console.WriteLine())
for (int j=0;j<l;j++)
Console.Write(arr[i,j] + " ");
}
}
}
а вот программка,где я создаю формочку...
Код:
using System;
using System.Windows.Forms;
using System.Drawing;
class ButtonForm : Form
{
Button MyButton;
Button StopButton;
Label lblOutput;
public ButtonForm()
{
Text = "Кнопочки";
lblOutput =new Label();
MyButton = new Button();
MyButton.Text = "Start";
MyButton.Location = new Point(100, 200);
StopButton = new Button();
StopButton.Text = "Exit";
StopButton.Location = new Point(200, 200);
//добавляем в список обработчик событий кнопки.
MyButton.Click += new EventHandler(MyButtonClick);
Controls.Add(MyButton);
StopButton.Click += new EventHandler(StopButtonClick);
Controls.Add(StopButton);
}
[STAThread]
public static void Main()
{
ButtonForm skel = new ButtonForm();
Application.Run(skel);
}
//обработчик для кнопки MyButton.
protected void MyButtonClick(object who, EventArgs e)
{
lblOutput.Location = new Point(20, 40);
lblOutput.Size = new Size(216, 24);
lblOutput.Text = "1 2 3 4 5\n1 2 3 4 5\n";
lblOutput.Location = new Point(40, 40);
Controls.Add(lblOutput);
}
//обработчик событий для кнопки StopButton.
protected void StopButtonClick(object who, EventArgs e)
{
//если пользователь ответит щелчком на кнопке Yes,
//программа будет завершена.
DialogResult result = MessageBox.Show("Остановить программу?",
"Завершение",
MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
Application.Exit();
}
}
вопрос в том,как вывести матрицу из первого кода на форму из второго??? с помощью Label.Text не получается=((помогите пожалуйста..
П.С.прога делается в C#
|
|
|