2013-03-25 17 views
12

FlowLayoutPanelに問題があり、解決方法がわかりません。FlowLayoutPanel.AutoSizeをFlowBreakと連携させる方法

2つのFlowLayoutPanelsを別のものに配置します。 2番目の内側のflpには3つのボタンがあります。

enter image description here

FlowLayoutPanelの子供からのプロパティは次のとおりです。

FlowDirection = LeftToRight; 
AutoSize = true; 
AutoSizeMode = GrowAndShrink; 
WrapContents = true; 

は今、私がtrueにFlowBreakプロパティは、しかし、私が見振る舞いは私が欲しいものではありません各ボタンに設定され、私が欲しいです変更、ボタンの幅に

enter image description here

を縮小するFlowLayoutPanel FlowDirectionUpToDownはオプションではありません。

誰かがAutoSizeが機能しない理由を知っていますか?

これはコードです。

// 
//FlowLayoutPanel1 
// 
this.FlowLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 
this.FlowLayoutPanel1.Controls.Add(this.FlowLayoutPanel3); 
this.FlowLayoutPanel1.Location = new System.Drawing.Point(84, 77); 
this.FlowLayoutPanel1.MinimumSize = new System.Drawing.Size(10, 10); 
this.FlowLayoutPanel1.Name = "FlowLayoutPanel1"; 
this.FlowLayoutPanel1.Size = new System.Drawing.Size(308, 265); 
this.FlowLayoutPanel1.TabIndex = 0; 
// 
//FlowLayoutPanel3 
// 
this.FlowLayoutPanel3.AutoSize = true; 
this.FlowLayoutPanel3.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 
this.FlowLayoutPanel3.Controls.Add(this.Button1); 
this.FlowLayoutPanel3.Controls.Add(this.Button2); 
this.FlowLayoutPanel3.Controls.Add(this.Button3); 
this.FlowLayoutPanel3.Location = new System.Drawing.Point(127, 3); 
this.FlowLayoutPanel3.MinimumSize = new System.Drawing.Size(10, 10); 
this.FlowLayoutPanel3.Name = "FlowLayoutPanel3"; 
this.FlowLayoutPanel3.Size = new System.Drawing.Size(162, 87); 
this.FlowLayoutPanel3.TabIndex = 1; 
// 
//Button1 
// 
this.FlowLayoutPanel3.SetFlowBreak(this.Button1, true); 
this.Button1.Location = new System.Drawing.Point(3, 3); 
this.Button1.Name = "Button1"; 
this.Button1.Size = new System.Drawing.Size(75, 23); 
this.Button1.TabIndex = 0; 
this.Button1.Text = "Button1"; 
this.Button1.UseVisualStyleBackColor = true; 
// 
//Button2 
// 
this.FlowLayoutPanel3.SetFlowBreak(this.Button2, true); 
this.Button2.Location = new System.Drawing.Point(3, 32); 
this.Button2.Name = "Button2"; 
this.Button2.Size = new System.Drawing.Size(75, 23); 
this.Button2.TabIndex = 1; 
this.Button2.Text = "Button2"; 
this.Button2.UseVisualStyleBackColor = true; 
// 
//Button3 
// 
this.Button3.Location = new System.Drawing.Point(3, 61); 
this.Button3.Name = "Button3"; 
this.Button3.Size = new System.Drawing.Size(75, 23); 
this.Button3.TabIndex = 2; 
this.Button3.Text = "Button3"; 
this.Button3.UseVisualStyleBackColor = true; 
+0

これは私のGUIで問題となっ 一つの制御私はFlowBrakeを2つのコントロールを配置し、設定 https://docs.google.com/document/d/1I6OtboresNk-gfOR3sEM8gyYHVX9sGohdNtX6heeQwI/edit?usp=sharing True https://docs.google.com/document/d/17C02PoL8LCyymfXNtEP8N6kkzZETxkiOCb6mPTbzGf0/edit?usp = sharing コントロールを元のままにしたいが、幅の変更が収まりません。 – Natalia

+0

あなたはあなたが持っているものとあなたが達成しようとしているものと一緒に二つの画像を追加してください。テキストの説明から、あなたが直面している問題は明確ではない –

+0

結果が新しい画像を追加しました。私の以前のコメントでは、GUI上で2つのリンクが表示されました。 – Natalia

答えて

13

これはバグです。非常に長い間起こっています。問題は、FlowLayoutPanelのレイアウトエンジンが、2番目の行にラップされていても、2番目のコントロールの幅を含め、最初の行の幅が正しくないことを計算することです。

回避策は愚かですが効果的ですが、最初のコントロールの後に幅が0のダミーパネルを追加してください。デザイナーでこれを行う場合は、最初にドロップし、正しい場所、1番目のコントロールの右側にドラッグします。次に、プロパティウィンドウでマージンを(0、0、0、0)とサイズを(0、0)に設定します。

+0

保存された私の日..ありがとうございました! – vendettamit

2

解決策ではありませんが、回避策です。 FlowLayoutPanelでフローブレイクを使用して、TableLayoutPanelの動作をシミュレートしようとしているようです。代わりにTableLayoutPanelをお試しになりましたか?コメントのあなたのスクリーンショットによると、それはあなたのニーズに完全に動作するはずです。

+0

私のGUIでは、ユーザーは任意のボタンの順序と位置を調整できます。ユーザはまた、コンテナの内外にボタンをドラッグアンドドロップすることもできる。私がテーブルレイアウトパネルを作成した場合、ユーザがコントロールをドロップすると、テーブルの動作は簡単ではありません。なぜなら、コントロールの列や行やテーブルを持つことができるからです。 – Natalia

+0

@Natalia:[this](http://www.devexpress.com/Products/NET/Controls/WinForms/Layout/)を実装しようとしていますか? – Neolisk

6

私はFlowLayoutPanelがあなたがやろうとしていることをするように設計されているとは思いません。 TableLayoutPanelがおそらくより適しています。単一の列を持つTableLayoutPanelを追加し、各ボタンを行に追加します。

を編集しました。私はハックな作業を見つけました。最初のボタンの後に、パネルを作成します。サイズは0,0、余白は0,0です。 FlowBreakがfalseに設定されていることを確認してください。

enter image description here

編集:あなたが唯一の最初のボタンではなく、それぞれに1つの後に、1枚のパネルを作成する必要があります。

+1

同じ考え、同じ時間。 Upvoting ... :) – Neolisk

+0

@Michael G私はこれを試し、いくつかの分を待ちます... – Natalia

+1

あなたの 'hackish work around'は素晴らしいです。私もそれを見つけようとしましたが、パネルコントロールは私の心には向いていませんでした。私はあなたにもう一度それをアップアップしてもらいたい。 – Neolisk

関連する問題