質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Q&A

解決済

1回答

8773閲覧

C#のTableLayoutPanelに、任意の位置にPanelをコードで追加したいです。

退会済みユーザー

退会済みユーザー

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

0グッド

0クリップ

投稿2016/01/22 01:36

いつもおせわになります。
Windows7, Visual Studio 2013, .NET4.5, WindowsFormの組み合わせで開発しています。

TableLayoutPanelにPanelをコードで追加したいです。

図1がデザイン。
図2が実行した状態です。

実行すると、元のlabel0(Panel0)のすぐ下でなく、なぞの空間の下にPanelを追加します。

図2の希望の位置にPalelをコードで追加するには、どうすればよいでしょう。

お知恵をお貸しください。

イメージ説明
図1デザイン。

イメージ説明
図2実行した状態。

Form1.cs
using System.Windows.Forms;

namespace tabletest {
public partial class Form1 : Form {
int counter = 0;
int lineheight = 100;
public Form1() {
InitializeComponent();

Panel panel = new Panel(); panel.Width = 598; panel.BackColor = System.Drawing.SystemColors.ButtonShadow; Label label = new Label(); label.Text = "label"; label.Location = new System.Drawing.Point(0, 0); label.Width = 500; panel.Controls.Add(label); table.Controls.Add(panel, 0, counter); table.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, lineheight)); } }

}

Form1.Designer.cs
namespace tabletest {
partial class Form1 {
/// <summary>
/// 必要なデザイナー変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary> /// 使用中のリソースをすべてクリーンアップします。 /// </summary> /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows フォーム デザイナーで生成されたコード /// <summary> /// デザイナー サポートに必要なメソッドです。このメソッドの内容を /// コード エディターで変更しないでください。 /// </summary> private void InitializeComponent() { this.table = new System.Windows.Forms.TableLayoutPanel(); this.panel0 = new System.Windows.Forms.Panel(); this.label0 = new System.Windows.Forms.Label(); this.table.SuspendLayout(); this.panel0.SuspendLayout(); this.SuspendLayout(); // // table // this.table.AutoScroll = true; this.table.BackColor = System.Drawing.SystemColors.ActiveCaption; this.table.ColumnCount = 1; this.table.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.table.Controls.Add(this.panel0, 0, 0); this.table.Location = new System.Drawing.Point(93, 12); this.table.Name = "table"; this.table.RowCount = 1; this.table.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 435F)); this.table.Size = new System.Drawing.Size(596, 612); this.table.TabIndex = 0; // // panel0 // this.panel0.BackColor = System.Drawing.SystemColors.ButtonShadow; this.panel0.Controls.Add(this.label0); this.panel0.Location = new System.Drawing.Point(3, 3); this.panel0.Name = "panel0"; this.panel0.Size = new System.Drawing.Size(383, 103); this.panel0.TabIndex = 0; // // label0 // this.label0.AutoSize = true; this.label0.Location = new System.Drawing.Point(32, 18); this.label0.Name = "label0"; this.label0.Size = new System.Drawing.Size(35, 12); this.label0.TabIndex = 0; this.label0.Text = "label0"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(813, 636); this.Controls.Add(this.table); this.Name = "Form1"; this.Text = "Form1"; this.table.ResumeLayout(false); this.panel0.ResumeLayout(false); this.panel0.PerformLayout(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.TableLayoutPanel table; private System.Windows.Forms.Panel panel0; private System.Windows.Forms.Label label0; }

}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

デザイナ側で指定している以下の部分で余白ができてしまっています。

csharp

1this.table.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 435F));

すぐ下に配置したいようであれば以下のようにサイズの型を自動調整にしてみてください。
property

投稿2016/01/22 02:17

sho_cs

総合スコア3541

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2016/01/22 02:23

ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問