无法将类型“System.Windows.Point”隐式转换为“System.Drawing.Point”

endlessJuly 2010-09-07 05:21:12
看的 Head First C#这本书,
看到“赛狗日"程序了,
这个程序没有源码,提示里

Point p=MyPictureBox.Location;
###process###
MyPicture,Location=p;


两次的赋值都报错,第一个赋值报错 无法将类型“System.Drawing.Point”隐式转换为“System.Windows.Point”
第二个 无法将类型“System.Windows.Point”隐式转换为“System.Drawing.Point”

C#新手,不知道要如何解决。
...全文
2117 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
endlessJuly 2010-09-08
  • 打赏
  • 举报
回复
添加了一个 System.Drawing引用,
然后加了一个 using System.Drawing 好了。
dancingbit 2010-09-07
  • 打赏
  • 举报
回复
不用wpf的话,不要using System.Windows。
endlessJuly 2010-09-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 gomoku 的回复:]

System.Windows.Point是WPF底下的东西,跟System.Drawing.Point不一样。
要用System.Drawing.Point,你可以新建一个Winform程序,而不是WPF程序。
[/Quote]
我新建的却是是Winform,不是wpf
endlessJuly 2010-09-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 linux7985 的回复:]

你没有发现两个类型是不同的吗?

唯一的办法就是一个成员一个成员的赋值
[/Quote]
Point p = new Point();
p.X = MyPictureBox.Location.X;
以上两句可以,
MyPictureBox.Location.X = p.X;
这一句有以下错误:
无法修改“System.Windows.Forms.Control.Location”的返回值,因为它不是变量
新手,很多问题不明白~
ZXY900213 2010-09-07
  • 打赏
  • 举报
回复
两个同名的类,在不同的命名空间下,
  • 打赏
  • 举报
回复
WPF(System.Windows.Point)

System.Drawing.Point(坐标----绘制图时用到)
gomoku 2010-09-07
  • 打赏
  • 举报
回复
System.Windows.Point是WPF底下的东西,跟System.Drawing.Point不一样。
要用System.Drawing.Point,你可以新建一个Winform程序,而不是WPF程序。
yongyinmg 2010-09-07
  • 打赏
  • 举报
回复
Point p=new System.Drawing.Point(MyPictureBox.Location.X,MyPictureBox.Location.Y);
另一个也差不多
wulala789 2010-09-07
  • 打赏
  • 举报
回复
右键--》添加引用--》选择System.Drawing添加进来就可以
烈火蜓蜻 2010-09-07
  • 打赏
  • 举报
回复
你没有发现两个类型是不同的吗?

唯一的办法就是一个成员一个成员的赋值
一切为了你 2010-09-07
  • 打赏
  • 举报
回复
引入命名空间问题

111,129

社区成员

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

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

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