?? form1.cs
字號:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace olsvm
{
public partial class Gsvm : Form
{
private int color;
private Point[][] point;
private int[] count;
private int ker;
private int kind;
Bitmap bmp;
public Gsvm()
{
InitializeComponent();
color = 0;
point = new Point[5][];
count = new int[5];
ker = 0;
kind = 0;
bmp = new Bitmap(500, 500);
}
private void red_Click(object sender, EventArgs e)
{
color = 1;
red.Checked = true;
green.Checked = false;
blue.Checked = false;
yellow.Checked = false;
pink.Checked = false;
}
private void green_Click(object sender, EventArgs e)
{
color = 2;
red.Checked = false;
green.Checked = true;
blue.Checked = false;
yellow.Checked = false;
pink.Checked = false;
}
private void blue_Click(object sender, EventArgs e)
{
color = 3;
red.Checked = false;
green.Checked = false;
blue.Checked = true;
yellow.Checked = false;
pink.Checked = false;
}
private void yellow_Click(object sender, EventArgs e)
{
color = 4;
red.Checked = false;
green.Checked = false;
blue.Checked = false;
yellow.Checked = true;
pink.Checked = false;
}
private void pink_Click(object sender, EventArgs e)
{
color = 5;
red.Checked = false;
green.Checked = false;
blue.Checked = false;
yellow.Checked = false;
pink.Checked = true;
}
private void draw_MouseDown(object sender, MouseEventArgs e)
{
Graphics g = draw.CreateGraphics();
switch (color)
{
case 1:
if (count[0] != 0)
{
Point[] temp = new Point[count[0] + 1];
for (int i = 0; i < count[0]; i++)
temp[i] = point[0][i];
temp[count[0]].X = e.X;
temp[count[0]].Y = e.Y;
point[0] = temp;
count[0]++;
}
else
{
point[0] = new Point[1];
point[0][0].X = e.X;
point[0][0].Y = e.Y;
count[0] = 1;
}
g.FillRectangle(new SolidBrush(Color.Red), e.X - 1, e.Y - 1, 2, 2);
break;
case 2:
if (count[1] != 0)
{
Point[] temp = new Point[count[1] + 1];
for (int i = 0; i < count[1]; i++)
temp[i] = point[1][i];
temp[count[1]].X = e.X;
temp[count[1]].Y = e.Y;
point[1] = temp;
count[1]++;
}
else
{
point[1] = new Point[1];
point[1][0].X = e.X;
point[1][0].Y = e.Y;
count[1] = 1;
}
g.FillRectangle(new SolidBrush(Color.YellowGreen), e.X - 1, e.Y - 1, 2, 2);
break;
case 3:
if (count[2] != 0)
{
Point[] temp = new Point[count[2] + 1];
for (int i = 0; i < count[2]; i++)
temp[i] = point[2][i];
temp[count[2]].X = e.X;
temp[count[2]].Y = e.Y;
point[2] = temp;
count[2]++;
}
else
{
point[2] = new Point[1];
point[2][0].X = e.X;
point[2][0].Y = e.Y;
count[2] = 1;
}
g.FillRectangle(new SolidBrush(Color.Blue), e.X - 1, e.Y - 1, 2, 2);
break;
case 4:
if (count[3] != 0)
{
Point[] temp = new Point[count[3] + 1];
for (int i = 0; i < count[3]; i++)
temp[i] = point[3][i];
temp[count[3]].X = e.X;
temp[count[3]].Y = e.Y;
point[3] = temp;
count[3]++;
}
else
{
point[3] = new Point[1];
point[3][0].X = e.X;
point[3][0].Y = e.Y;
count[3] = 1;
}
g.FillRectangle(new SolidBrush(Color.Yellow), e.X - 1, e.Y - 1, 2, 2);
break;
case 5:
if (count[4] != 0)
{
Point[] temp = new Point[count[4] + 1];
for (int i = 0; i < count[4]; i++)
temp[i] = point[4][i];
temp[count[4]].X = e.X;
temp[count[4]].Y = e.Y;
point[4] = temp;
count[4]++;
}
else
{
point[4] = new Point[1];
point[4][0].X = e.X;
point[4][0].Y = e.Y;
count[4] = 1;
}
g.FillRectangle(new SolidBrush(Color.Purple), e.X - 1, e.Y - 1, 2, 2);
break;
}
}
private void draw_Paint(object sender, PaintEventArgs e)
{
Brush pen = new SolidBrush(Color.Black);
Graphics g = e.Graphics;
g.DrawImage(bmp, 0, 0);
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < count[i]; j++)
{
switch (i+1)
{
case 1: pen = new SolidBrush(Color.Red); break;
case 2: pen = new SolidBrush(Color.YellowGreen); break;
case 3: pen = new SolidBrush(Color.Blue); break;
case 4: pen = new SolidBrush(Color.Yellow); break;
case 5: pen = new SolidBrush(Color.Purple); break;
}
g.FillRectangle(pen, point[i][j].X - 1, point[i][j].Y - 1, 2, 2);
}
}
}
private void run_Click(object sender, EventArgs e)
{
Brush pen = new SolidBrush(Color.Black);
Graphics g = draw.CreateGraphics();
Graphics vg = Graphics.FromImage(bmp);
for (int i = 0; i < 5; i++)
{
if ( count[i] != 0)
kind++;
}
if (kind == 1)
{
int i = 0;
for (i = 0; i < 5; i++)
if (count[i] != 0)
break;
for (int j = 0; j < 500; j+=2)
for (int r = 0; r < 500; r+=2)
{
switch (i + 1)
{
case 1: pen = new SolidBrush(Color.Pink); break;
case 2: pen = new SolidBrush(Color.Green); break;
case 3: pen = new SolidBrush(Color.SkyBlue); break;
case 4: pen = new SolidBrush(Color.Peru); break;
case 5: pen = new SolidBrush(Color.Plum); break;
}
g.FillRectangle(pen, j - 1, r - 1, 2, 2);
vg.FillRectangle(pen, j - 1, r - 1, 2, 2);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -