c# - Why is my pseudo dialog form hiding its "charms" and ignoring its own properties? -


i've created pseudo dialog (form formborderstyle property set fixeddialog) contains label, datetimepicker, , ok button. ok button's dialogresult property "ok"

adapted post: how return value form in c#?, i'm trying create way prompt user select date when app can't suss out date filename (sometimes can, can't, depending on whether filename "well formed."

the code below.

the problem form not display controls when invoked; and, not display in center of screen, although 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 instance of object" if try set 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 conditionally invoke so:

public static datetime getdatetimefromfilename(string selectedfilename) {     // expecting selected files valid pilsner files, expected     // of 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 date file created:")) {         dialogresult dr = dtpdlgform.showdialog();         if (dr == dialogresult.ok) {             dt = dtpdlgform.returnval;         }      } } return dt; 

}

if add new constructor overload form (or derived control), need make sure designer-generated code in initializecomponent() gets called.

make new constructor call default constructor first via : this():

public returndate(string lblcaption) : this() {     _lblcaption = lblcaption;  } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -