窗体控件开发

yangyugw 2007-06-08 06:08:26
button,listView的属性被修改后,无法保存,编译就属性内容就消失了


using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

namespace SDDev.Forms
{
/// <summary>
/// ButtonListview 的摘要说明。
/// </summary>
public class ButtonListview:Panel
{
private System.Windows.Forms.Button mbutton;
private System.Windows.Forms.ListView mlistView;
private System.ComponentModel.Container components = null;

public ButtonListview()
{
///
/// Windows.Forms 类撰写设计器支持所必需的
///

InitializeComponent();
this.Controls.Add(this.mbutton);
this.Controls.Add(this.mlistView);

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

[
Category("listView"),
Description("listView"),
Browsable(true),
NotifyParentProperty(true),
Bindable(true)
]
public ListView listView
{
get {return mlistView;}
set {mlistView=value;}
}
[
Category("button"),
Description("button"),
Browsable(true),
NotifyParentProperty(true),
]
public Button button
{
get {return mbutton;}
set {mbutton=value;}
}

#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mbutton = new System.Windows.Forms.Button();
this.mlistView = new System.Windows.Forms.ListView();
//
// mbutton
//
this.mbutton.Location = new System.Drawing.Point(0, 0);
this.mbutton.Name = "mbutton";
this.mbutton.TabIndex = 0;
this.mbutton.Text = "mbutton";
//
// mlistView
//
this.mlistView.Location = new System.Drawing.Point(0, 0);
this.mlistView.Name = "mlistView";
this.mlistView.TabIndex = 0;

}
#endregion
}
}
...全文
232 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangyugw 2007-06-10
  • 打赏
  • 举报
回复
各位大侠,关键这到底要怎么写呢
coolpc 2007-06-08
  • 打赏
  • 举报
回复
顶……
bote_china 2007-06-08
  • 打赏
  • 举报
回复
另外,listView属性应该为只读属性,在这里,你要提供对listView属性设置的代码生成器,否则所有对该属性的设置都将被看做是运行时,而没有在窗体生成代码中保存该属性的设置.
shxmh 2007-06-08
  • 打赏
  • 举报
回复
同意LS的说法,
设计时修改的属性在下次打开时是可以看到的,但运行时并不是设计时的属性了。
创建Form时,InitializeComponent()中
this.mbutton = new System.Windows.Forms.Button();
this.mbutton.Location = new System.Drawing.Point(0, 0);
this.mbutton.Name = "mbutton";
this.mbutton.TabIndex = 0;
this.mbutton.Text = "mbutton";
新建了mbutton并设置了一些属性,所以设计时修改的属性并不能反映到运行时的实例中。
aSalt 2007-06-08
  • 打赏
  • 举报
回复
jf
bote_china 2007-06-08
  • 打赏
  • 举报
回复
原因在private void InitializeComponent()这个函数你,在这个函数中this.mlistView = new System.Windows.Forms.ListView();每次加载时,控件都被重新实例化,因而设计时设置的数据是不无法保存的
jetxia 2007-06-08
  • 打赏
  • 举报
回复
mark
randb 2007-06-08
  • 打赏
  • 举报
回复
有这等怪事??

--------------------------------------------------------------------------------
专注于自动提交、发贴机、资源采集器等网络营销软件的开发及相关领域如验证码识别技术。
QQ群号:24733057

110,535

社区成员

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

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

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