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

  • SEARCH
  • Home
  • 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 380597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:00:16+00:00 2026-05-12T15:00:16+00:00

Following code, credit: Guffa. Hello All, I’m trying to add controls to a Form

  • 0

Following code, credit: Guffa.


Hello All,

I’m trying to add controls to a Form at runtime based on the information found in a Plain Text File. The structure? of the text file is always the same, and will not change. Example:

File.txt:

Label
"This is a label"
320, 240

Explanation:

Control
Text
Location

The following code, provided to me by Guffa, doesn’t cause any errors or anything, but at the same time, nothing happens at all. And I’m not sure why… Can somebody please explain why the label doesn’t get created and added to the form with the right info attached to it?

MatchCollection lines = Regex.Matches(File.ReadAllText(fileName), @"(.+?)\r\n""([^""]+)""\r\n(\d+), (\d+)\r\n");
foreach (Match match in lines) {
   string control = match.Groups[1].Value;
   string text = match.Groups[2].Value;
   int x = Int32.Parse(match.Groups[3].Value);
   int y = Int32.Parse(match.Groups[4].Value);
   Console.WriteLine("{0}, \"{1}\", {2}, {3}", control, text, x, y);

   if(control == "Label")
   {
      Label label = new Label();
      label.Text = text;
      canvas.Controls.Add(label); // canvas is a Panel Control.
      label.Location = new Point(x, y);
   }

}

I hope that I have clearly explained my situation. Any help at all would be greatly appreciated.

Thanks for taking the time to read.
jase

  • 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-12T15:00:17+00:00Added an answer on May 12, 2026 at 3:00 pm

    Blind guess: I see the last \r\n in the regex is not optional. Possible that your input file is missing a return character after the last line?

    Additional note about sucking at regular expressions: there are some tools that will help you experiment with regular expressions, which might be useful, for example, to understand what’s going on in this particular case. I always use Expresso, which among other things analyzes the structure of the regular expression you provide and explains what it does.

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

Sidebar

Related Questions

following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666
I am trying to replace 1234567890123456 with ************3456 with the following code: Regex.Replace(xml,@\b\d{13,16}\b, string.Concat(new
I have the following code: var parentEls = $(root) .find(credit standard) .parents() .map(function ()
I found this PHP code credit to creator and want to implement it a
I trying out some problems in Google's Code Jam. For the question Store Credit
Code Taken From: Bytes to Binary in C Credit: BSchlinker The following code I
Please give me some suggestions, I was trying to run following code : <
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
Following code iterates through many data-rows, calcs some score per row and then sorts
Following code is from a sample of playframework-2.0: /** * Display the dashboard. */

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.