在设计时无法在某些属性中“设置" [英] do not work “set” in some of property in design time
本文介绍了在设计时无法在某些属性中“设置"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么在设计时设置了"dataGrid"属性在我的代码中不起作用,但是属性字体正常工作.
我在表格上使用了这个组件. (我通过设计时调试对其进行了测试)
Why, in design time, does set "dataGrid" Property not work in my code, but property font is working correctly.
I used of this componet on the a Form. (I test it with design time debuging)
namespace Example
{
public partial class Component1 : System.Windows.Forms.DataGridView
{
public Component1()
{
}
private DataGridViewColumn _gridcolumn;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[TypeConverter(typeof ( ExpandableObjectConverter))]
public DataGridViewColumn gridcolumn
{
get
{
if (_gridcolumn == null)
_gridcolumn = new DataGridViewColumn();
return _gridcolumn;
}
set //Do not Work Set in designTime
{
_gridcolumn = value;
}
}
private System.Drawing.Font _MyFont;
public System.Drawing.Font MyFont
{
get
{
if (_MyFont == null)
_MyFont = new System.Drawing.Font("tahoma", 8);
return _MyFont;
}
set
{
_MyFont = value; //Work correctly in design time
}
}
int _with;
public int withcustom
{
get
{
return _with;
}
set
{
_with = value; //Work correctly in design time
}
}
}
}
推荐答案
原因是设计人员希望设置自定义控件的所有可访问属性.这样做是由于设计器中Visual Studio中的属性"窗口.
尝试使用属性的instat函数;
Cause the designer wants to set all accesseble properties of your custom control. This is done because of the Properties-Window in Visual Studio in the Designer.
Try using functions instat of properties;
public DataGridViewColumn GetGridcolumn()
{
// ...
}
public void SetGridcolumn(DataGridViewColumn column)
{
// ...
}
这篇关于在设计时无法在某些属性中“设置"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文