C#隐式转换显式求教

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


2

小白求教大神该如何去解决这个问题
...全文
161 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
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的定义。

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧