不能修改表达式,因为它不是一个可变 [英] Cannot modify expression because it is not a variable

查看:111
本文介绍了不能修改表达式,因为它不是一个可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一个用户控件(其上有一个网格)在Windows窗体上调整大小。
下面的代码是我在表单中。我得到的行为是,当我让它大调整控件大小。不过,这并不缩水。什么我做错了(或)我缺少什么?



 私人无效AdjustGrid()
{
ZoomControl.Location =新点(5,5);
ZoomControl.Size =新的大小(this.Width - 15,this.Height - 75);
}

无效zoomform_Resize(对象发件人,EventArgs五)
{
AdjustGrid();
}

现在用户控件具有下面的代码:

  //调整该用户控件上有
私人无效NameValuePropertyBag_Resize电网(对象发件人,EventArgs五)
{
grdNameValueProperties.Location =新的点(4,4);
grdNameValueProperties.Size =新的大小(this.Width - 8,this.Height - 8);
}



<击>
我试过

  grdNameValueProperties.Size.Width = this.Width  -  8; 
grdNameValueProperties.Size.Height = this.Height -8;



它给我的错误,因为它不是一个变量不能修改表情......我是什么失踪?



附加信息:



我使用的setparent()调用的Windows移动/缩放一个用户控件为另一种形式(ZoomForm)。
<击>
锚似乎并不为控制工作与移动的setParent()......更准确地说,它可工作,但我有重画的问题。



我得到了锚/码头对,工作不重画的问题[我删除调整大小事件wireup和调整停靠到填充]



ZoomForm initally没有控制。用户控件添加到动态地ParentForm。



目前,我能够使变焦形式更大的<击>与上面的代码而不是更小。


解决方案

  grdNameValueProperties.Size.Width = this.Width  -  8; 
grdNameValueProperties.Size.Height = this.Height -8;

这代码给出了错误,因为大小是值类型,不是引用类型。读这 http://www.yoda.arachsys.com/csharp/parameters.html 可能有助于解释值类型和引用类型之间的差异。


I'm trying to get an UserControl (which has a grid on it) on a Windows Form to resize. The below code is what I have in the Form. The behavior I'm getting is that the control is resized when I make it big. But it does not shrink. What am I doing wrong (or) What am I missing?

private void AdjustGrid()
{
    ZoomControl.Location = new Point(5, 5);
    ZoomControl.Size = new Size(this.Width - 15, this.Height - 75);
}

void zoomform_Resize(object sender, EventArgs e)
{
    AdjustGrid();
}

Now the user control has the following code:

//Resize the grid that the UserControl has on it
private void NameValuePropertyBag_Resize(object sender, EventArgs e)
{
    grdNameValueProperties.Location = new Point(4,4);
    grdNameValueProperties.Size = new Size(this.Width - 8, this.Height - 8);
}

I tried

grdNameValueProperties.Size.Width = this.Width - 8;
grdNameValueProperties.Size.Height = this.Height -8;

It gives me "Cannot modify expression because it is not a variable" error... What am I missing?

Additional Info:

I'm using SetParent() Windows call to move/zoom an UserControl to another Form (ZoomForm). Anchor doesn't seem to work for controls moved with SetParent()... More precisely, it may be working but I have repainting problems.

I got Anchor/Dock pair to working without repaint issues [I removed the resize event wireup and adjusted Dock to Fill]

The ZoomForm initally has no controls. The Usercontrol is added to the ParentForm dynamically.

Currently, I'm able to make the zoom form bigger with the above code but not smaller.

解决方案

grdNameValueProperties.Size.Width = this.Width - 8;
grdNameValueProperties.Size.Height = this.Height -8;

That code gives the error because Size is a value type, not a reference type. Reading this http://www.yoda.arachsys.com/csharp/parameters.html may help explain the difference between value types and reference types.

这篇关于不能修改表达式,因为它不是一个可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆