//当有多个窗体时,对顶层的窗口进行操作,例如:我们开发具有录入功能的界面的时候,为了防止提交后的二次(重复)录入,希望点击提交按钮并提示成功后,界面的所有文本框内容能够自动清空
.NET Framework 类库
Form.ActiveMdiChild 属性
获取当前活动的多文档界面 (MDI) 子窗口。 命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中) 语法:public Form ActiveMdiChild { get; }
当窗体中不包含GroupBox控件时示例:
        public void ClearAllChildFormText()
{
// 获取当前激活的窗口
Form tempChild = this.ActiveMdiChild;
if (tempChild != null)
{
//遍历所有控件
foreach (Control control in tempChild.Controls)
{
if (control is TextBox)
{
//清掉含有TexBox控件上的内容
control.Text = "";
}
/* //以下方法同上也能实现
TextBox textbox= control as TextBox;
if (textbox!= null)
{
//清掉含有TexBox控件上的内容
textbox.Text = "";
}
*/
}
}
}
当窗体中包含GroupBox控件时,需要再次遍历GroupBox中的控件,示例:
            foreach (Control control in this.Controls)
{
if ((control as GroupBox) != null)
{
foreach (Control tempcontrol in control.Controls)
{
if (tempcontrol is TextBox)
{
//清掉含有TexBox控件上的内容
tempcontrol.Text = "";
}
/* //以下方法同上也能实现
TextBox textbox= tempcontrol as TextBox;
if (textbox!= null)
{
//清掉含有TexBox控件上的内容
textbox.Text = "";
}
*/
}
}
}
												

C# 清除当前窗体中TextBox控件中的内容的更多相关文章

  1. [转载]ASP.NET中TextBox控件设立ReadOnly="true"后台取不到值

    原文地址:http://www.cnblogs.com/yxyht/archive/2013/03/02/2939883.html ASP.NET中TextBox控件设置ReadOnly=" ...

  2. ASP.NET中TextBox控件设立ReadOnly="true"后台取不到值

    SP.NET中TextBox控件设置ReadOnly="true"H或Enabled=false后台取不到值 当TextBox设置了ReadOnly="true" ...

  3. .net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】

    1.首先在前台dataGridview属性中增加onRowDataBound属性事件 2.然后在后台Observing_RowDataBound事件中增加代码 protected void Obser ...

  4. c# winform 在一个窗体中使用另一个窗体中TextBox控件的值——解决办法

    [前提]一个winform应用程序项目中,窗体B,需要使用 窗体A 中一个TextBox控件的值,进行计算等操作. [解决方案] 1.在窗体A中定义:public static double a;// ...

  5. Winform中TextBox控件开启自动提示补全功能

    问题:Winform开发中,有一个TextBox控件用以输入姓名,现希望在输入名字时能够自动提示所有可能的名字. 解答:winform中的TextBox控件含有如下三个属性:   ① AutoComp ...

  6. C#中设置TextBox控件中仅可以输入数字且设置上限

    首先设置只可以输入数字: 首先设置TextBox控件的KeyPress事件:当用户按下的键盘的键不在数字位的话,就禁止输入 private void textBox1_KeyPress(object ...

  7. 在TextBox控件中禁用鼠标右键

    实现效果: 知识运用: MouseEventArgs类的Button属性     TextBox控件的ContextMenu属性 实现代码: private void textBox1_MouseDo ...

  8. MFC中listbox控件中各种属性的详解

     ListBox控件是Windows 窗体的一个空间,ListBox 控件显示一个项列表,用户可从中选择一项或多项.      如果项总数超出可以显示的项数,则自动向 ListBox 控件添加滚动条. ...

  9. 【VC版】如何获取其他进程中ListView控件中的内容

    如果需要C#版的,可以看下我之前写的:C#如何获取其他程序ListView控件中的内容 获取其他进程的数据需要使用到以下几个函数: VirtualAllocEx() VirtualFreeEx() W ...

随机推荐

  1. iOS开发-在表单元中添加子视图

    #import <UIKit/UIKit.h> @interface NameAndColorCellTableViewCell : UITableViewCell @property(c ...

  2. TFS上使用Beyond Compare来比较源码

    In Visual Studio, go to the Tools menu, select Options, expand Source Control, (In a TFS environment ...

  3. 一个方便的shell命令,查看软件安装目录

    查看软件安装路径:whereis phpfind / -name nginx.configfind 查找 / 从根目录 -name 文件查找

  4. Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心

    E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  5. hdu 4104

    先排序,再动态规划.须要优化 #include<iostream> #include<cstdio> #include<cstring> #include<s ...

  6. main()函数的输入参数 main(int argc, char** argv)

    一般简单的C++程序,main函数的写法都是 int main() {... ; return 0;},但是,如果在运行程序时需要有参数输入,可以是使用将主函数写成int main(int argv, ...

  7. [MODx] 8. Snippet get data, chunk display

    Simple Example: Lets process this chunk and output its value. We have this Chunk, called "Welco ...

  8. [Effective C++ --024]若所有参数皆需类型转换,请为此采用non-member函数

    引言 假设我们有这样的类: class A{ public: A(, ) {}; int num() const; int den() const; const A operator* (const ...

  9. mysql事务回滚

    首先条件是表要设置为 InnoDB  类型. 当在一个库连接中,通过调用另一个 库名称.表名称,可以回滚: 当用USE dbName后,在两个或多个库操作时,一次只能回滚一个库中的东西: 当在多个数据 ...

  10. mvc_ajax_for form

    在上一篇介绍MVC中的Ajax实现方法的时候,曾经提到了除了使用Ajax HTML Helper方式来实现之外,Jquery也是实现Ajax的另外一种方案. 通过get方法实现AJax请求 View ...