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 8046551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:49:17+00:00 2026-06-05T05:49:17+00:00

I’ve created a pseudo dialog (form with FormBorderStyle property set to FixedDialog) that contains

  • 0

I’ve created a pseudo dialog (form with FormBorderStyle property set to FixedDialog) that contains a label, a DatetimePicker, and an OK button. The OK button’s DialogResult property is “OK”

Adapted from this post: How to return a value from a Form in C#?, I’m trying to create a way to prompt the user to select a date when my app can’t suss out the date by the filename (sometimes it can, sometimes it can’t, depending on whether the filename is “well formed.”

The code is below.

The problem is that the form does not display its controls when it is invoked; AND, it does not display in the center of the screen, although its StartPosition = CenterScreen…???

public partial class ReturnDate : Form {

public DateTime ReturnVal { get; set; }
private String _lblCaption;

public ReturnDate() {
    InitializeComponent();
}

public ReturnDate(String lblCaption) {
    _lblCaption = lblCaption; // "Object not set to an instance of an object" if I try to set the Label here directly
}

private void buttonOK_Click(object sender, EventArgs e)
{
    this.ReturnVal = dateTimePicker1.Value.Date;
    this.Close(); 
}

private void ReturnDate_Shown(object sender, EventArgs e) {
    labelCaption.Text = _lblCaption;
}

}

…and I conditionally invoke it like so:

public static DateTime getDateTimeFromFileName(String SelectedFileName) {
    // Expecting selected files to be valid pilsner files, which are expected
    // to be of the format "duckbilledPlatypus.YYYY-MM-DD.pil" such as:
    // "duckbilledPlatypus.2011-06-11.pil"
    const int DATE_BEGIN_POS = 19;
    const int DATE_LENGTH = 10;

String substr = string.Empty;
if (SelectedFileName.Length >= DATE_BEGIN_POS + DATE_LENGTH) {
    substr = SelectedFileName.Substring(DATE_BEGIN_POS, DATE_LENGTH);
}
DateTime dt = DateTime.Now;
if (!(DateTime.TryParse(substr, out dt))) {
    using (var dtpDlgForm = new ReturnDate("Please select the Date that the file was created:")) {
        DialogResult dr = dtpDlgForm.ShowDialog();
        if (dr == DialogResult.OK) {
            dt = dtpDlgForm.ReturnVal;
        } 
    }
}
return dt;

}

  • 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-06-05T05:49:19+00:00Added an answer on June 5, 2026 at 5:49 am

    If you add a new constructor overload to a Form (or any derived Control), you need to make sure that the designer-generated code in InitializeComponent() gets called.

    Make your new constructor call the default constructor first via : this():

    public ReturnDate(String lblCaption) : this()
    {
        _lblCaption = lblCaption; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT

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.