本文介绍了不允许空文本框值进入安装程序安装程序VS2013中的用户界面对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Hi Team, 我正在为窗口服务生成设置。 我想让用户选择在安装安装时提及UI上的所有配置级别数据。 通过引用没有我能够实现预期的网站输出,但有一些moification。 我能够显示标签和文本框并通过引用下面的链接来绑定该值。 自定义用户界面并将用户输入传递给安装程序类 [ ^ ] ScottGu的博客 - 提示/技巧:使用VS 2005创建打包的ASP.NET安装程序 [ ^ ] 预计是: 1)我想做验证手段用户将无法通过保留空文本框来点击下一个按钮。 2)现在用户通常将数据提到文本框中,而不是我想给浏览按钮选择路径和填充文本盒子。 我尝试了什么: 这是代码我用于显示和绑定文本框值。 Hi Team,I am generating setup for window service. I want to give option to user to mention all config level data on UI at the time of setup installation.By referring no of sites I am able to achieve that expected output, but there are some moification.I am able to show label and text box and bind that value by referring some below link.Customize User Interfaces and Pass User Input to Installer Classes[^]ScottGu's Blog - Tip/Trick: Creating Packaged ASP.NET Setup Programs with VS 2005[^]Expection is:1)I want to do validation means user will be not able to click on next button by keeping empty text box.2)Now user mentioning data into text box normally, instead of that I want to give browse button to select path and fill text box.What I have tried:This is code that I am using for showing and binding text box value. [RunInstaller(true)] public partial class ProjectInstaller : System.Configuration.Install.Installer { public ProjectInstaller() { InitializeComponent(); } public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver); } public override void Commit(IDictionary savedState) { base.Commit(savedState); try { AddConfigurationFileDetails(); } catch (Exception e) { base.Rollback(savedState); } } private void showParameters() { StringBuilder sb = new StringBuilder(); StringDictionary myStringDictionary = this.Context.Parameters; if (this.Context.Parameters.Count > 0) { foreach (string myString in this.Context.Parameters.Keys) { sb.AppendFormat("String={0} Value= {1}\n", myString, this.Context.Parameters[myString]); } } } private void AddConfigurationFileDetails() { try { string LogFilePath = Context.Parameters["LogFilePath"]; string Customer_Input_Filepath = Context.Parameters["Customer_InputFilePath"]; string ServerPublicKeyPath = Context.Parameters["ServerPublicKeyPath"]; string ClientPrivateKeyPath = Context.Parameters["ClientPrivateKeyPath"]; string ClientPrivateKeyPassword = Context.Parameters["ClientPrivateKeyPassword"]; string SFTP_IN_PATH = Context.Parameters["SFTP_IN_PATH"]; string SFTP_OUT_PATH = Context.Parameters["SFTP_OUT_PATH"]; string HostName = Context.Parameters["HostName"]; string PortNo = Context.Parameters["PortNo"]; string UserName = Context.Parameters["UserName"]; string CertificateKeyFilePath = Context.Parameters["CertificateKeyFilePath"]; string PassPhrase = Context.Parameters["PassPhrase"]; // Get the path to the executable file that is being installed on the target computer string assemblypath = Context.Parameters["assemblypath"]; string appConfigPath = assemblypath + ".config"; // Write the path to the app.config file XmlDocument doc = new XmlDocument(); doc.Load(appConfigPath); XmlNode configuration = null; foreach (XmlNode node in doc.ChildNodes) if (node.Name == "configuration") configuration = node; if (configuration != null) { //MessageBox.Show("configuration != null"); // Get the ‘appSettings’ node XmlNode settingNode = null; foreach (XmlNode node in configuration.ChildNodes) { if (node.Name == "appSettings") settingNode = node; } if (settingNode != null) { //MessageBox.Show("settingNode != null"); //Reassign values in the config file foreach (XmlNode node in settingNode.ChildNodes) { //MessageBox.Show("node.Value = " + node.Value); if (node.Attributes == null) continue; XmlAttribute attribute = node.Attributes["value"]; //MessageBox.Show("attribute != null "); //MessageBox.Show("node.Attributes['value'] = " + node.Attributes["value"].Value); if (node.Attributes["key"] != null) { //MessageBox.Show("node.Attributes['key'] != null "); //MessageBox.Show("node.Attributes['key'] = " + node.Attributes["key"].Value); switch (node.Attributes["key"].Value) { case "Test": attribute.Value = Convert.ToString(LogFilePath.Replace("\\", @"\")); break; case "LogFilePath": attribute.Value = Convert.ToString(LogFilePath.Replace("\\", @"\")); break; case "Customer_InputFilePath": attribute.Value = Convert.ToString(Customer_Input_Filepath.Replace("\\", @"\"));// + "\\"; break; case "ServerPublicKeyPath": attribute.Value = ServerPublicKeyPath; break; case "ClientPrivateKeyPath": attribute.Value = ClientPrivateKeyPath; break; case "ClientPrivateKeyPassword": attribute.Value = ClientPrivateKeyPassword; break; case "SFTP_IN_PATH": attribute.Value = SFTP_IN_PATH; break; case "SFTP_OUT_PATH": attribute.Value = SFTP_OUT_PATH; break; case "HostName": attribute.Value = HostName; break; case "PortNo": attribute.Value = PortNo; break; case "UserName": attribute.Value = UserName; break; case "CertificateKeyFilePath": attribute.Value = CertificateKeyFilePath; break; case "PassPhrase": attribute.Value = PassPhrase; break; } } } } if (!string.IsNullOrEmpty(CertificateKeyFilePath)) { doc.Save(appConfigPath); } else { } } } catch { throw; } } }Please give me solution for validation and browse buttonPlease reply as soon as possible. 请给我验证和浏览按钮的解决方案 请尽快回复。Please give me solution for validation and browse buttonPlease reply as soon as possible.推荐答案 在文本框中使用LostFocus。 Use the LostFocus on your textbox. private void textbox_LostFocus(object sender, EventArgs e){ //do something to validated the textbox value if (textbox.text = "") { btncancel.Enabled = false; //if not filled you can directly setfocus on box again so the user can't leave it. this.ActiveControl = textbox } //or do whatever you want...} 这篇关于不允许空文本框值进入安装程序安装程序VS2013中的用户界面对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-22 06:26