我现在做个小的管理软件,父窗口上面有很多功能按钮,比如说新增、修改,我现在想实现winform中,当点击新增打开新增子窗口,当点击修改的时候,需要打开修改的子窗体同时关闭新增的子窗口,该如何实现呢?
解决方案 »
- asp.net 开发的视频播放过程中巨卡的问题,期盼高手帮忙解决
- Dll产生的信息如何回传给主程序?
- c#引用excel <Microsoft Excel Object Library>的問題
- 在做安装文件的时候,怎么让安装项目在安装完成后执行一段数据库还原脚本(注:安装文件中包含一个数据库备份文件,只有在安装程序拷贝文
- 在C#的控件中有没有象word中输入特殊符号的控件,DataGrid能实现吗?
- 有用vs2005的进来问一下如何增加用户自定义控件??
- 关于DataSet的并发问题...异常处理...
- 我该学什么
- 在sql server中多条sql命令可以用分号隔开,access怎么做?
- 怎样从一个窗口设置主窗口的控件属性?
- 求高手解C#对字符串的遍历
- 请问如何把treeview1的所有节点赋给treeview2并显示?
foreach (Form ff in f)
ff.Close();
Form2 fm = new Form2();
fm.Show(this);
//AddForm新增窗口
public partial class AddForm : Form
{
private static object lockHelper = new object();
private static UpdateForm instance = null;
private AddForm()
{
InitializeComponent();
} public static AddForm CreateInstance()
{
if (instance == null)
{
lock (lockHelper)
{
if (instance == null)
{
instance = new AddForm();
//加上实例关闭事件,窗体就会自动回收,即instance=null;
instance.FormClosed += new FormClosedEventHandler(DestroyForm); }
return instance;
}
}
else
{
return instance;
}
} /// <summary>
/// 当窗体关闭时将Instance置空
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void DestroyForm(object sender, FormClosedEventArgs e)
{
instance = null;
} }修改窗口调用
public partial class UpdateForm : Form
{
AddForm addForm = null;
public UpdateForm()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
addForm = AddForm.CreateInstance();
if(addForm!=null)
addForm.Show();
} private void button2_Click(object sender, EventArgs e)
{
addForm.Close();
}
}
当点击Listbox里的B,就弹出A窗体.点B窗体的"返回",就返回到E窗体,
......这是俺这驴以前写的一个示例,里边可能有一些没多关要的东西;
代码如下:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;//实现窗体效果的命名空间
using System.Collections;
using System.IO;
using System.Data.OracleClient;
using System.Text.RegularExpressions;
namespace webcam
{
public partial class NewLogin : Form
{
public NewLogin()
{
InitializeComponent();
}
[DllImport("user32.dll")]
private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
private const int AW_HOR_POSITIVE = 0x0001;//从左到右打开窗口
private const int AW_HOR_NEGATIVE = 0x0002;//从右到左打开窗口
private const int AW_VER_POSITIVE = 0x0004;//从上到下打开窗口
private const int AW_VER_NEGATIVE = 0x0008;//从下到上打开窗口
private const int AW_CENTER = 0x0010;//从中央打开
private const int AW_HIDE = 0x10000;//隐藏窗体
private const int AW_ACTIVATE = 0x20000;//显示窗体
private const int AW_SLIDE = 0x40000;
private const int AW_BLEND = 0x80000;//淡入淡出效果 private void button2_Click(object sender, EventArgs e)
{
this.Close();
} private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
{
Application.ExitThread();
AnimateWindow(this.Handle, 200, AW_HIDE | AW_VER_NEGATIVE);
} private void button1_Click(object sender, System.EventArgs e)
{ if (listBox1.SelectedIndex == 0)
{ this.Hide(); new webcam.AConsoleForm().ShowDialog(); }
if (listBox1.SelectedIndex == 1)
{ this.Hide(); new webcam.BConsoleForm().ShowDialog(); }
if (listBox1.SelectedIndex == 2)
{ this.Hide(); new webcam.CConsoleForm().ShowDialog(); }
if (listBox1.SelectedIndex == 3)
{ this.Hide(); new webcam.DConsoleForm().ShowDialog(); }
listBox1.Focus();
}
private void listBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (listBox1.SelectedIndex == 0)
{ this.Hide(); new webcam.AConsoleForm().ShowDialog(); }
if (listBox1.SelectedIndex == 1)
{ this.Hide(); new webcam.BConsoleForm().ShowDialog(); }
if (listBox1.SelectedIndex == 2)
{ this.Hide(); new webcam.CConsoleForm().ShowDialog(); }
if (listBox1.SelectedIndex == 3)
{ this.Hide(); new webcam.DConsoleForm().ShowDialog(); }
}
} private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Application.ExitThread();
AnimateWindow(this.Handle, 200, AW_HIDE | AW_VER_NEGATIVE);
} private void Form1_Load(object sender, EventArgs e)
{
AnimateWindow(this.Handle, 200, AW_ACTIVATE | AW_VER_POSITIVE);//200指明动画持续的时间(以微秒计),完成一个动画的标准时间为200微秒。 } }
}