无法将类型“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#新手,不知道要如何解决。
...全文
1495 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
  • 打赏
  • 举报
回复
引入命名空间问题
C#.net实现学生成绩管理系统 namespace 学生成绩管理系统 { partial class Formlogin { /// /// 必需的设计器变量。 /// private System.ComponentModel.IContainer components = null; /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { this.labeluser = new System.Windows.Forms.Label(); this.textBoxuser = new System.Windows.Forms.TextBox(); this.labelcode = new System.Windows.Forms.Label(); this.textBoxcode = new System.Windows.Forms.TextBox(); this.buttonin = new System.Windows.Forms.Button(); this.buttonout = new System.Windows.Forms.Button(); this.SuspendLayout(); // // labeluser // this.labeluser.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.labeluser.Location = new System.Drawing.Point(31, 50); this.labeluser.Name = "labeluser"; this.labeluser.Size = new System.Drawing.Size(55, 26); this.labeluser.TabIndex = 0; this.labeluser.Text = "用户名"; this.labeluser.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // textBoxuser // this.textBoxuser.Location = new System.Drawing.Point(126, 55); this.textBoxuser.Name = "textBoxuser"; this.textBoxuser.Size = new System.Drawing.Size(112, 21); this.textBoxuser.TabIndex = 1; // // labelcode // this.labelcode.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.labelcode.Location = new System.Drawing.Point(31, 124); this.labelcode.Name = "labelcode"; this.labelcode.Size = new System.Drawing.Size(55, 23); this.labelcode.TabIndex = 2; this.labelcode.Text = "密码"; this.labelcode.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // textBoxcode // this.textBoxcode.Location = new System.Drawing.Point(126, 124); this.textBoxcode.Name = "textBoxcode"; this.textBoxcode.PasswordChar = '*'; this.textBoxcode.Size = new System.Drawing.Size(112, 21); this.textBoxcode.TabIndex = 3; // // buttonin // this.buttonin.Location = new System.Drawing.Point(34, 200); this.buttonin.Name = "buttonin"; this.buttonin.Size = new System.Drawing.Size(75, 23); this.buttonin.TabIndex = 4; this.buttonin.Text = "登陆"; this.buttonin.UseVisualStyleBackColor = true; this.buttonin.Click += new System.EventHandler(this.buttonin_Click); // // buttonout // this.buttonout.Location = new System.Drawing.Point(163, 200); this.buttonout.Name = "buttonout"; this.buttonout.Size = new

110,534

社区成员

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

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

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