直接的な方法はありませんが、回避策があります ( Visual Studio 2010 - 2019 ):
という名前のフォームがForm1.csあり、そこに linkLabel、checkBoxes、radioButtons、progressBar などのコントロールが既にあるとします。
*.Designer.csトリックは、コントロールを移動するのではなく、ファイルを編集することです。以下をせよ:
- 新しいパネル (
panel1)Form1を通常どおり (ツールボックスを使用して) 配置し、他のコントロールを覆うようにサイズを指定します。
- フォーム (およびすべての関連ファイル) を閉じてから、ソリューション エクスプローラーの [すべてのファイルを表示] でアクティブにします。
Form1.Designer.cs見えるようになりました。それを開く。
次のコードを見つけます。フォームに登録されているコントロールが含まれています。
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.linkLabel1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.btnOk);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
次に、パネルを作成するコードを探します。
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(12, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(260, 198);
this.panel1.TabIndex = 7;
コントロールをフォームのControlsコレクション ( this.Controls) からパネルのControlsコレクション ( this.panel1.Controls) に移動するだけです。ソース コード内のある場所から別の場所に移動してから、+ ( Visual Studio のエディターのブロック編集モード- 選択を開始する前にキーを押したままにし、ブロック全体を選択した後にキーを放します) を使用して、次のように置き換えます。 AltShift this.Controlsthis.panel1.Controls
フォームに追加される残りのコントロールはpanel1、[OK] ボタンのみbtnOkです。
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.panel1);
this.Controls.Add(this.btnOk);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
最後に、Form1.Designer.csをダブルクリックして、フォームを閉じてから再度開きForm1.csます。これで、パネル内にコントロールが表示されるはずです。ポジションは以前と同じです。
注:この説明は Visual Studio 用に作成されたものです。代わりにVisual Studio Codeを使用している場合は、マルチ カーソル選択で同じことを実現できます。キーボード ショートカットは Strg+ Alt+Arrow Up または Strg+ Alt+Arrow Down です。Ctrlまたは、選択してから+ Shift+を押し L て、現在の選択のすべてのオカレンスに複数のカーソルを追加することもできます。複数のカーソルを使用すると、入力した内容がすべてのカーソル位置に挿入/上書きされます。