このコードを使用すると(listApplicationsはListViewコントロールです):
private void ShowApplicationPropertiesForm() {
String FullPath = String.Empty;
String Title = String.Empty;
String Description = String.Empty;
Boolean Legacy = false;
Boolean Production = false;
Boolean Beta = false;
MyCustomListViewItemDescendant lvi = (MyCustomListViewItemDescendant)listApplications.SelectedItems[0];
FullPath = lvi.ExePath;
Title = lvi.Text;
Description = lvi.ToolTipText;
ApplicationProperties ap = new ApplicationProperties(
FullPath,
Title,
Description,
Legacy,
Production,
Beta);
ap.Show();
}
//overloaded form constructor
public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta) {
this.Text = String.Format("{0} Properties", ATitle);
textBoxFullPath.Text = AFullPath;
textBoxTitle.Text = ATitle;
textBoxDescription.Text = ADescription;
checkBoxLegacy.Checked = ALegacy;
checkBoxProduction.Checked = AProduction;
checkBoxBeta.Checked = ABeta;
}
...「System.NullReferenceExceptionが未処理のMessage=オブジェクト参照がオブジェクトのインスタンスに設定されていませんでした」というメッセージが表示されます。
それを踏んで、爆撃する線は次のとおりです。
textBoxFullPath.Text = AFullPath;
textBoxFullPathは、フォーム上のテキストボックスです。AFullPathには、「Q:\ What \ AreYou \ Gonna \ Do\BabyBlue.exe」という種類の有効な値があります。
更新しました:
部分的に解決しました。
それは古い「時期尚早の割り当て」の問題でした。コンストラクターからLoad()イベントに割り当てを移動することで、爆弾が発生しなくなりました(以下のコード)。
ただし、実行時にフォームに何も表示されなくなりました... ???!?
public partial class ApplicationProperties : Form {
String _fullPath = String.Empty;
String _title = String.Empty;
String _description = String.Empty;
Boolean legacy = false;
Boolean production = false;
Boolean beta = false;
public ApplicationProperties() {
InitializeComponent();
}
public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta) {
_fullPath = AFullPath;
_title = ATitle;
_description = ADescription;
legacy = ALegacy;
production = AProduction;
beta = ABeta;
this.CenterToScreen();
}
private void ApplicationProperties_Load(object sender, EventArgs e) {
//this.Text = String.Format("{0} Properties", _title);
Text = String.Format("{0} Properties", _title);
textBoxFullPath.Text = _fullPath;
textBoxTitle.Text = _title;
textBoxDescription.Text = _description;
checkBoxLegacy.Checked = legacy;
checkBoxProduction.Checked = production;
checkBoxBeta.Checked = beta;
}
再度更新:
「InitializeComponent();」を追加します オーバーロードされたコンストラクターにトリックを実行しました-ありがとう、SW!