惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - 露雨城市.NET2.0和Sql Server 2005开发研究

关于asp.net将动态页直接生成静态页的随笔(乱码) 我的神龙卡KTV点播软件只有一个遗憾了 关于清除Sql Server Express版本的数据库日志文件 关于微软2008技术预览大会南京站和Vista 也许是转折-放弃了5,6K的月薪 关于vs2005中ajax控件暴露模板中控件,请高手进来聊聊. - 露雨城市.NET2.0和Sql Server 2005开发研究 这个基础题,你能做对吗? 好久没有来发文章了,今天来秀一下。 在.NET2.0中如何更简单的使用委托将方法加载到事件中去 关于如何在子窗口中选择后,在父窗口赋值并让输入框设为只读。 - 露雨城市.NET2.0和Sql Server 2005开发研究 我的新资源网站开张了,韩国模版,韩国设计资源等。 关于在插入的模版中如何为已绑定了Text属性的TextBox设置默认值 今天好高兴,通过了微软的Sql Server 2005的70-31的考试。 赠送一张微软免费考试券 关于GridView中选择当前行的问题。 VS2005中的一个小BUG:关于Dropdownlist无法Datadinding的解决方法。 如何动态设置全局theme,及在web.config中读取pages节点的内容。 讲故事谈.NET委托:一个C#睡前故事 关于的MasterPage和Theme的问题。
Visual C#中父窗口和子窗口之间实现控件互操作
露雨城市.NET2.0和Sql Server 2005开发研究 · 2006-10-20 · via 博客园 - 露雨城市.NET2.0和Sql Server 2005开发研究

在.NET 1.0和1.1的版本中,我们要实现父窗口和子窗口之间的互操作,有两种简单的方法。
第一种,在主窗体类中定义一个静态成员,来保存当前主窗体对象,例如:

public static yourMainWindow pCurrentWin = null;  

   然后在主窗体构造函数中,给静态成员初始化,如下:

pCurrentWin = this;  

   那么在子窗体中调用父窗体,可以通过“主窗体类名. pCurrentWin”来操作当前的主窗体。 

   第二种,是在子窗体中定义一个私有成员,来保存当前主窗体对象,例如:

private yourMainWindow pParentWin = null;  

   然后在子窗体构造函数中,加一参数,如下:

public yourChildWindow( yourMainWindow WinMain )  
{  
  pParentWin 
= WinMain;  
  
//Other code  
}

   在主窗体创建子窗体的时候,要把this作为参数来构造子窗体,这样在子窗体中调用父窗体,可以直接用“this.pParentWin”就可以了 

   不过以上所作的,只是让你能够访问当前主窗体对象,那么如何操作控件,很多人直接修改控件的成员访问符,即把“private”改为“public”,我觉得这样破坏了本身类的封装,所以我比较喜欢的做法是增加公有属性或方法来供调用,例如: 

public string ButtonText  
{  
  
getreturn btn.Text;}  
  
set{ btn.Text = value;}  
}
  

public void Button_Click()  
{  
  
this.btnDConvert.PerformClick();//Execute button click  
}
 

虽然简单,不过略显得麻烦,在.NET 2.0版本中,也就是Visual C# 2005的版本中,我们可以直接使用Application.OpenForm["formname"].Controls("ControlName")来控制控件,可以说是非常的方便。

posted on 2006-10-20 07:10  露雨城市.NET2.0和Sql Server 2005开发研究  阅读(7949)  评论()    收藏  举报