Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 827083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:31:04+00:00 2026-05-15T03:31:04+00:00

I need to generate windows form fields based off of a text file that

  • 0

I need to generate windows form fields based off of a text file that I am parsing. I also want to automatically generate validation event handlers which all will be basically the same only the form field and the regular expression which is used to validate the field will change.

I’m having a difficult time figuring out the quickest and easiest method to go about doing this.

Any pointers in the right direction would really be great, maybe even some keywords that I’m missing. I can only imagine this type of question has been covered before, I just don’t know what I’m searching for really.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:31:05+00:00Added an answer on May 15, 2026 at 3:31 am

    I have done something similar using XML to generate controls at runtime

    The easiest way i found was to create custom controls to allow easy validation.

    I also collect details regarding the controls to be able to return the value of the fields to the webservice

    Here is how i achive this

      public bool IsFieldValid()
        {
                 Error.SetError(label, "");
            if (_Validate.Length == 0)
            {
             return true;
            }
    
            else 
            {
                switch (_Validate)
                { 
                    case "General":
                        return ValidateText();
                    case "Int":
                        return ValidateInt();
                    case "Decimal":
                        return ValidateDecimal();
                    case "Length":
                        return ValidateTextLength();
                    default:
                        return true;
                }
    
    
            }
    
    
        }
    
    
        public bool ValidateText()
        {
    
                this.shapeContainer1.BackColor = this.BackColor;
                if (_CanBeNull == true & this.textBox.Text.Trim() == "")
                {
    
                    return true;
                }
                else
                {
                    if (this.textBox.Text.Trim().Length > 0)
                    {
    
                        return true;
                    }
                    else
                    { 
                        Error.SetError(label, CustomError);
                        return false;
                    }
    
            }
        }
    
        public bool ValidateDecimal()
        {
    
            if (_CanBeNull == true & this.textBox.Text.Trim() == "")
            {
                return true;
            }
            else
            {
                try
                {
                    this.textBox.Text = this.textBox.Text.Replace("£", "");
                    Decimal Val = System.Convert.ToDecimal(this.textBox.Text);
                    if (_MaxValue == 0)
                    {
                        return true;
                    }
    
                    if ((Val >= _MinValue) && (Val <= _MaxValue))
                    {
                        return true;
                    }
                    else
                    {
    
                        this.Error.SetError(this.label, "Value must be between " + _MinValue.ToString() + " and " + _MaxValue);
                        return false;
    
                    }
    
    
                }
                catch
                {
                    this.Error.SetError(this.label, "Error converting value to a decimal value");
                    return false;
                }
    
    
    
            }
    
        }
    
        public bool ValidateInt()
        {
            if (_CanBeNull == true & this.textBox.Text.Trim() == "")
            {
                return true;
            }
            else
            {
                try
                {
                    int Val = System.Convert.ToInt32(this.textBox.Text);
                    if (_MaxValue == 0)
                    {
                        return true;
                    }
    
                    if ((Val >= _MinValue) && (Val <= _MaxValue))
                    {
    
                        return true;
                    }
                    else
                    {
    
                        this.Error.SetError(label,"Value must be between " + _MinValue.ToString() + " and " + _MaxValue);
                        return false;
    
                    }
    
    
                }
                catch
                {
                    this.Error.SetError(label,"Error converting value to a numeric value");
                    return false;
                }
    
    
    
            }
        }
    
        public bool ValidateTextLength()
        {
            if (_CanBeNull == true & this.textBox.Text.Trim() == "")
            {
                return true;
            }
            else
            {
    
                int Val = this.textBox.Text.Length;
                if ((Val >= _MinValue) && (Val <= _MaxValue))
                {
                    return true;
                }
                else
                {
    
                    this.Error.SetError(label,"Length of text must be between " + _MinValue.ToString() + " and " + _MaxValue);
                    return false;
    
                }
    
    
    
    
    
            }
        }
    
    
        public String TxtReturnXML
        { 
            get {
                string S;
                XmlDocument doc = new XmlDocument();
                XmlNode Xe = doc.CreateNode(XmlNodeType.Element,"Value",null);
                Xe.InnerText = this.textBox.Text.ToString();
                S = Xe.OuterXml;
                doc = null;
                Xe = null;
                return S;
    
    
            }
    
    
    
        }
    
        public bool LoadedXml(XmlNode X)
        {
            try
            {
                _Validate = X.Attributes["Validate"].Value;
    
                this.textBox.Text = X.Attributes["DefaultValue"].Value.ToString();
                this.label.Text = X.Attributes["LabelText"].Value.ToString();
    
                if (System.Convert.ToInt32(X.Attributes["Height"].Value) > 0)
                {
                    this.Height = System.Convert.ToInt32(X.Attributes["Height"].Value) + 10;
                    textBox.Multiline = true;
                    this.textBox.Height = System.Convert.ToInt32(X.Attributes["Height"].Value);
                }
                if (System.Convert.ToInt32(X.Attributes["Width"].Value) > 0)
                {
                    this.textBox.Width = System.Convert.ToInt32(X.Attributes["Width"].Value);
                    this.textBox.Left = (this.Width - 20) - System.Convert.ToInt32(X.Attributes["Width"].Value);
                }
                _CanBeNull = System.Convert.ToBoolean(X.Attributes["CanBeNull"].Value);
                _PassBack = System.Convert.ToBoolean(X.Attributes["PassBack"].Value);
    
                CustomError = X.Attributes["CustomError"].Value.ToString();
                CustomWarning = X.Attributes["CustomWarning"].Value.ToString();
                if (CustomWarning.Length > 0)
                {
                    Error.SetError(label, CustomWarning);
    
                }
    
    
                _MinValue = System.Convert.ToInt32(X.Attributes["MinValue"].Value);
                _MaxValue = System.Convert.ToInt32(X.Attributes["MaxValue"].Value);
    
    
    
            }
            catch {
                return false;
            }
    
                _LoadedXml = X;
                return true;
    
    
    
    }
    

    You could also add event handles to validate at a specific event(i.e blur)

    Hope this helps

    Sp

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate an editable xml file to supply content to a flash
I need to generate multiple databases to SQL, so I need script/program to automatically
I need to generate a file for Excel, some of the values in this
I need to connect to a provider's web service with a Windows Form application.
I have a class which inherits System.Windows.Forms.Form. I need to make the form available
I created my ClickOnce application witch will install a small windows form application that
I'm working on a windows form application and I want to have a rich
Need a regex here that will take a file line by line and output
I want to make the most simplest application that can communicate via windows send
I have a windows service application that runs as Local System, and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.