子窗体,主窗体,互相传值,组策略,子窗体文本选择,select,length,反射系列<二>
2008-05-27 09:23 Virus-BeautyCode 阅读(2300) 评论(2) 编辑 收藏 举报在昨天的教程
窗体传值,子窗体,父窗体,反射,reflection,windows,组策略,gpedit.msc,动态创建窗体,谢谢
中我写到了,传值遇到的问题,主要是因为子窗体是反射出来的,所以子窗体的属性也应该反射才可以得到,可以看我的上面的教程,但是早上来了,觉得还不完美,因为windows组策略是可以从子窗体传值过去的,我又做了 一些小的修改,但是组策略子窗体打开的时候,里面的文本是被选择的,如果是textbox的话,可以使用selectall方法,但是numericnubmber没有selectall,它的select有一个重载,参数是start,length倒是可以实现,但是这个length又不知道怎么获得了,希望大家给点提示,谢谢!
下面是修改之后的代码,主窗体:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace PersonalUdisk
{
public partial class frmModifyConfig : Form
{
private TreeNode _selectedNode;
public frmModifyConfig()
{
InitializeComponent();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
_selectedNode = e.Node;
lvConfig.Items.Clear();
Fill_lvConfig(_selectedNode);
}
private void Fill_lvConfig( TreeNode treeNode)
{
if (treeNode.Text ==Convert.ToString( PolicyType.PIN码策略))
{
ListViewItem lvItem1 = new ListViewItem();
lvItem1.SubItems.Clear();
lvItem1.SubItems[0].Text = "PIN码长度最小值";
lvItem1.SubItems.Add("5 个字符");
lvItem1.SubItems.Add("frmPasswordLength");
lvConfig.Items.Add(lvItem1);
}
}
private int iReturnValue;
public int IReturnValue
{
get { return this.iReturnValue; }
set{this.iReturnValue=value;}
}
private void lvConfig_DoubleClick(object sender, EventArgs e)
{
Type type = Type.GetType("PersonalUdisk." + lvConfig.SelectedItems[0].SubItems[2].Text);
this.iReturnValue =Convert.ToInt32( lvConfig.SelectedItems[0].SubItems[1].Text.Substring(0, lvConfig.SelectedItems[0].SubItems[1].Text.IndexOf(" ")));
object obj = Activator.CreateInstance(type);
Form form = (Form)obj;
form.Owner = this;
form.ShowDialog();
if (form.DialogResult == DialogResult.OK)
{
this.iReturnValue = Convert.ToInt32(type.GetProperty("PINLength").GetValue(form, null));
this.lvConfig.SelectedItems[0].SubItems[1].Text = this.iReturnValue.ToString() + " 个字符";
}
}
}
public enum PolicyType
{
PIN码策略
}
}
子窗体:using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace PersonalUdisk
{
public partial class frmModifyConfig : Form
{
private TreeNode _selectedNode;
public frmModifyConfig()
{
InitializeComponent();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
_selectedNode = e.Node;
lvConfig.Items.Clear();
Fill_lvConfig(_selectedNode);
}
private void Fill_lvConfig( TreeNode treeNode)
{
if (treeNode.Text ==Convert.ToString( PolicyType.PIN码策略))
{
ListViewItem lvItem1 = new ListViewItem();
lvItem1.SubItems.Clear();
lvItem1.SubItems[0].Text = "PIN码长度最小值";
lvItem1.SubItems.Add("5 个字符");
lvItem1.SubItems.Add("frmPasswordLength");
lvConfig.Items.Add(lvItem1);
}
}
private int iReturnValue;
public int IReturnValue
{
get { return this.iReturnValue; }
set{this.iReturnValue=value;}
}
private void lvConfig_DoubleClick(object sender, EventArgs e)
{
Type type = Type.GetType("PersonalUdisk." + lvConfig.SelectedItems[0].SubItems[2].Text);
this.iReturnValue =Convert.ToInt32( lvConfig.SelectedItems[0].SubItems[1].Text.Substring(0, lvConfig.SelectedItems[0].SubItems[1].Text.IndexOf(" ")));
object obj = Activator.CreateInstance(type);
Form form = (Form)obj;
form.Owner = this;
form.ShowDialog();
if (form.DialogResult == DialogResult.OK)
{
this.iReturnValue = Convert.ToInt32(type.GetProperty("PINLength").GetValue(form, null));
this.lvConfig.SelectedItems[0].SubItems[1].Text = this.iReturnValue.ToString() + " 个字符";
}
}
}
public enum PolicyType
{
PIN码策略
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PersonalUdisk
{
public partial class frmPasswordLength : Form
{
private frmModifyConfig frmParent;
public frmPasswordLength()
{
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
}
public int PINLength
{
get { return Convert.ToInt32( this.numericPINLength.Value); }
set { this.numericPINLength.Value = value; ;}
}
private void numericPINLength_ValueChanged(object sender, EventArgs e)
{
if (this.numericPINLength.Value == 0)
{
this.lblPINLengthInfo.Text = "不要求PIN码。";
}
else
{
this.lblPINLengthInfo.Text = "PIN码必须至少是:";
}
}
private void frmPasswordLength_Load(object sender, EventArgs e)
{
frmParent = (frmModifyConfig)this.Owner;
this.numericPINLength.Value = frmParent.IReturnValue;
//this.numericPINLength.Value = 0;
//this.lblPINLengthInfo.Text = "不要求PIN码。";
}
private void btnOK_Click(object sender, EventArgs e)
{
this.PINLength = Convert.ToInt32( this.numericPINLength.Value);
}
}
}
谢谢!using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PersonalUdisk
{
public partial class frmPasswordLength : Form
{
private frmModifyConfig frmParent;
public frmPasswordLength()
{
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
}
public int PINLength
{
get { return Convert.ToInt32( this.numericPINLength.Value); }
set { this.numericPINLength.Value = value; ;}
}
private void numericPINLength_ValueChanged(object sender, EventArgs e)
{
if (this.numericPINLength.Value == 0)
{
this.lblPINLengthInfo.Text = "不要求PIN码。";
}
else
{
this.lblPINLengthInfo.Text = "PIN码必须至少是:";
}
}
private void frmPasswordLength_Load(object sender, EventArgs e)
{
frmParent = (frmModifyConfig)this.Owner;
this.numericPINLength.Value = frmParent.IReturnValue;
//this.numericPINLength.Value = 0;
//this.lblPINLengthInfo.Text = "不要求PIN码。";
}
private void btnOK_Click(object sender, EventArgs e)
{
this.PINLength = Convert.ToInt32( this.numericPINLength.Value);
}
}
}