2

C# Web ブラウザー用のプラグイン パーサーを作成しています。

プラグインのボタンを作成するときは、ToolStripButton を ToolStrip に追加する必要があります。

これが私のコードです:

ToolStripButton pluginButton = new ToolStripButton();
pluginButton.Parent = toolStrip1;
pluginButton.Image = Simple_Browse.Properties.Resources.plugin;
pluginButton.Alignment = ToolStripItemAlignment.Left;
pluginButton.ToolTipText = TitlePlugin;

2 行目にエラーが表示されます:
System.Windows.ToolStripItem.Parent is inaccessible due to its permission level.

マイクロソフトで設定方法を調べました。どこかに.NET Protectionと書かれています。私はそれを勉強しましたが、意味がありません。

4

2 に答える 2

2

msdn を見ると、Parent プロパティの定義は次のとおりです。

[BrowsableAttribute(false)]
protected internal ToolStrip Parent { get; set; }

内部としてマークされているため、アセンブリ System.Windows.Forms 内でのみ使用できます。これは、アセンブリでこのプロパティを使用できないことを意味します。ただし、メソッド GetCurrentParent() を公開するため、現在の親を取得できます。セッター メソッドは公開されませんが、このオブジェクトについては、親のアイテム コレクションに追加する必要があります。だから何か

ToolStripButton pluginButton = new ToolStripButton();

toolStrip1.Items.Add(pluginButton);

しましょう。

于 2015-07-05T23:10:23.940 に答える
1

を設定するのではなく、代わりpluginButton.Parent = toolStrip1に使用toolStrip1.Items.Add( pluginButton )します。

于 2015-07-05T23:06:07.210 に答える