Thursday, November 21, 2019

C# - How combine path with file name without problem

..function care about suitable separator:
string sFileName = Path.Combine( PIFiles.GetExePath(), "file.dat" );

MessageBox.Show( sFileName );
Output:

C# - List.AddRange() - how copy one List object to another in one row

I have two List:
List<ObjectCoordinateBase> AllObjects;

List<InfoStar> Rows;
When I want copy objects from InfoStar class to ObjectCoordinate class, I can use List.AddRange() method.
Node: Import is class, that contains Rows.
Map.AllObjects.AddRange( import.GetAsObjectCoordinateBase() );
And here:
public IEnumerable<ObjectCoordinateBase> GetAsObjectCoordinateBase() {
      
  List<ObjectCoordinateBase> list = new List<ObjectCoordinateBase>();

  this.Rows.ForEach( item => { 
      
    list.Add( new ObjectCoordinateBase( item ) );
      
  } );
      
  return list;
}

Tuesday, November 12, 2019

C# - How to create yes-no question

..last parameter is default button (=second button in dialog).
if ( MessageBox.Show( this, "All data will be deleted. Continue ?",
     "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question, 
     MessageBoxDefaultButton.Button2 ) == DialogResult.No ) return;
Output: