C#隐式转换显式求教

snaki1111 2013-05-07 06:18:56
1


2

小白求教大神该如何去解决这个问题
...全文
131 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
u010610277 2013-05-08
好难得东西 开始接触
回复
vo__ov 2013-05-07
那两个东西都不一样的,你试下强制转换呗,反正不行的话也报错的
回复
snaki1111 2013-05-07
引用 5 楼 devmiao 的回复:
private SelectedShape currentShape; => private shiyan04.SelectedShape currentShape;
多谢大神 请问第二个问题该怎么解决 在赶实验报告
回复
u010604670 2013-05-07
新手
回复
devmiao 2013-05-07
private SelectedShape currentShape; => private shiyan04.SelectedShape currentShape;
回复
duanzhi1984 2013-05-07
ShapeData类的定义 SelectShape类的定义
回复
duanzhi1984 2013-05-07
请将各类之间的关系贴出来,否则,无法判断是否能转换。 如currentshape s.shapetype
回复
snaki1111 2013-05-07
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(); } } } } } }
回复
devmiao 2013-05-07
贴完整代码。 你的程序中有2个SelectedShape的定义。
回复
相关推荐
发帖
C#
创建于2007-09-28

10.6w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2013-05-07 06:18
社区公告

让您成为最强悍的C#开发者