0

コード:

private void loadViewTemplates(string path)
{
    foreach (string file in Directory.GetFiles(path, "*.txt"))
    {
        ToolStripItem subItem = new ToolStripMenuItem();
        viewTemplatesToolStripMenuItem.DropDownItems.Add(subItem);
    }
}

ソース ディレクトリに 3 つのファイルがあり、メニュー サブアイテムとして表示されるようですが、ファイル名が表示されません。

メニュー小項目

ファイル名を非表示にする代わりに表示する方法はありますか? どうぞよろしくお願いいたします。ありがとうございました!

4

2 に答える 2

1

行方不明

subItem.Text = Path.GetFileNameWithoutExtension(file);

MSDN から

ToolStripItem.Text - Gets or sets the text that is to be displayed on the item.

したがって、コードは次のようになります

private void loadViewTemplates(string path)  
{  
    foreach (string file in Directory.GetFiles(path, "*.txt"))  
    {  
        ToolStripItem subItem = new ToolStripMenuItem();  
        subItem.Text = Path.GetFileNameWithoutExtension(file);
        viewTemplatesToolStripMenuItem.DropDownItems.Add(subItem);  
    }  
}  
于 2012-08-20T22:44:22.880 に答える
1

私は以下のように自分で解決策を見つけました:

private void loadViewTemplates(string path)
{
    foreach (string file in Directory.GetFiles(path, "*.txt"))
    {
        viewTemplatesToolStripMenuItem.DropDownItems.Add(Path.GetFileNameWithoutExtension(file));
    }
}

ありがとうございました。

于 2012-08-20T22:45:30.103 に答える