1
2小白求教大神该如何去解决这个问题
2小白求教大神该如何去解决这个问题
解决方案 »
- Winform.net如何实现摄像头拍一寸或二寸规格的照片并保存
- 怎么实现将外部内容(如外部的某个文档或文字内容)拖拉到某个form界面上时候触发某个事件
- 填充Dataset sql语句中条件语句含参数
- (100分) 请问C#中窗体的close ,dispose,以及application.exit(),他们有什么区别呀`~谢啦~~
- 怎么会有值
- 求助?变量作用域问题?
- 如何用c#得到“Win32_ProcessStartup”对象?情指教。。。。
- 关于接口的问题, 急!!!
- 在winform的textbox里面,回车换行是哪个?
- 请问大家用c#开发都用什么工具呢?.net吗?
- 如何对数据库连接字符串加密,防止开发人员了解
- C#调用输出结构体数组的C++的dll
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// For the binary formatter.
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace shiyan04
{
public partial class MyPaintProgram : Form
{
public MyPaintProgram()
{
InitializeComponent();
} private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
} // 需要呈现的当前形状/颜色。
private SelectedShape currentShape;
private Color currentColor = Color.DarkBlue; // 维护每个ShapeData
private List<ShapeData> shapes = new List<ShapeData>(); private void MainWindow_Paint(object sender, PaintEventArgs e)
{
// Get the Graphics type for this window.
Graphics g = e.Graphics; // Render each shape in the selected color.
foreach (ShapeData s in shapes)
{
// Render a rectangle or circle 20 x 20 pixels in size
// using the correct color.
if (s.ShapeType == SelectedShape.Rectangle)
g.FillRectangle(new SolidBrush(s.Color), s.UpperLeftPoint.X, s.UpperLeftPoint.Y, 20, 20);
else
g.FillEllipse(new SolidBrush(s.Color), s.UpperLeftPoint.X, s.UpperLeftPoint.Y, 20, 20);
} } private void MainWindow_MouseClick(object sender, MouseEventArgs e)
{
// Make a ShapeData type based on current user
// selections.
ShapeData sd = new ShapeData();
sd.ShapeType = currentShape;
sd.Color = currentColor;
sd.UpperLeftPoint = new Point(e.X, e.Y); // Add to the List<T> and forse the form to repaint itself.
shapes.Add(sd);
Invalidate(); } private void pickShapeToolStripMenuItem_Click(object sender, EventArgs e)
{
ShapePickerDialog dlg = new ShapePickerDialog();
if (DialogResult.OK == dlg.ShowDialog())
{
currentShape = dlg.SelectedShape;
} } private void pickColorToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog(); if (dlg.ShowDialog() == DialogResult.OK)
{
currentColor = dlg.Color;
} } private void clearSurfaceToolStripMenuItem_Click(object sender, EventArgs e)
{
shapes.Clear(); // This will fire the paint event.
Invalidate(); } private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SaveFileDialog saveDlg = new SaveFileDialog())
{
// 配置Save对话框的外观
saveDlg.InitialDirectory = ".";
saveDlg.Filter = "Shape files (*.shapes)|*.shapes";
saveDlg.RestoreDirectory = true;
saveDlg.FileName = "MyShapes"; // 如果点击了OK按钮,就会打开新的文件并且序列化List<T>
if (saveDlg.ShowDialog() == DialogResult.OK)
{
Stream myStream = saveDlg.OpenFile();
if ((myStream != null))
{
// 保存所有的形状!
BinaryFormatter myBinaryFormat = new BinaryFormatter();
myBinaryFormat.Serialize(myStream, shapes);
myStream.Close();
}
}
} } private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
using (OpenFileDialog openDlg = new OpenFileDialog())
{
openDlg.InitialDirectory = ".";
openDlg.Filter = "Shape files (*.shapes)|*.shapes";
openDlg.RestoreDirectory = true;
openDlg.FileName = "MyShapes"; if (openDlg.ShowDialog() == DialogResult.OK)
{
Stream myStream = openDlg.OpenFile();
if ((myStream != null))
{
// 获取所有形状!
BinaryFormatter myBinaryFormat = new BinaryFormatter();
shapes = (List<ShapeData>)myBinaryFormat.Deserialize(myStream);
myStream.Close();
Invalidate();
}
}
} }
}
}
如currentshape
s.shapetype
SelectShape类的定义