C#隐式转换显式求教 12小白求教大神该如何去解决这个问题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 贴完整代码。你的程序中有2个SelectedShape的定义。 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;// 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 ShapeData类的定义SelectShape类的定义 private SelectedShape currentShape;=>private shiyan04.SelectedShape currentShape; 怎么通过串口读取硬件上的值。 熟悉RDLC报表的进来 这个情况下,是用接口还是用类? 怎样等某个方法或是函数执行完后再执行后面的语句 Winform程序如何输出曲线图,急!!! 一段动态加载的代码 无法引发自定义事件 visual studio 2008初学者求帮助,万分感谢,找了好久不知道什么原因?情况如下 在调代码的时候,自动窗体里发现有的变量颜色是"红"的,怎么回事? 如何将一个字符串转换成整型???C#txtImageID.Text的内容是一个数字!!! 如何屏蔽键盘上的所有按键? 如何对数据库连接字符串加密,防止开发人员了解 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类的定义