私はTableLayoutPanel
コントロールを持つWinFormを持っています。私のコードでは、画面に添付されているモニタの数を検出し、モニタごとに列を作成し、TableLayoutControl
の個々の列内の各ディスプレイのボタンを追加するので、何台のモニタが接続されていてもボタンが表示されますフォーム全体を「中心に置いた」。 1/2モニターはうまくレンダリングされますが、3つのモニターの結果、エンド・コラムが均等に分散されません。ここでC#TableLayoutPanelで列を均等に自動サイズ調整できない
私のコードです:
int count = Screen.AllScreens.Count();
this.monitorLayoutPanel.ColumnCount = count;
ColumnStyle cs = new ColumnStyle(SizeType.Percent, 100/count);
this.monitorLayoutPanel.ColumnStyles.Add(cs);
this.monitorLayoutPanel.AutoSize = true;
var buttonSize = new Size(95, 75);
int z = 0;
foreach (var screen in Screen.AllScreens.OrderBy(i => i.Bounds.X))
{
Button monitor = new Button
{
Name = "Monitor" + screen,
AutoSize = true,
Size = buttonSize,
BackgroundImageLayout = ImageLayout.Stretch,
BackgroundImage = Properties.Resources.display_enabled,
TextAlign = ContentAlignment.MiddleCenter,
Font = new Font("Segoe UI", 10, FontStyle.Bold),
ForeColor = Color.White,
BackColor = Color.Transparent,
Text = screen.Bounds.Width + "x" + screen.Bounds.Height,
Anchor = System.Windows.Forms.AnchorStyles.None
};
this.monitorLayoutPanel.Controls.Add(monitor, z, 0);
z++;
monitor.MouseClick += new MouseEventHandler(monitor_Click);
}
私はボタンが小さく作ってみました、とフォームのサイズを増加させたが、最後の列は常に最初の2よりも小さくなってきました。私はそれを理解できません!
[Windowsフォームを使用して魔方陣を作成するには?](http://stackoverflow.com/q/33968993/3110834) –
[フォームのセンターでFlowLayoutPanel内容を設定する方法](HTTPS: //stackoverflow.com/questions/38824530/how-to-set-flow-out-content-out-center-of-form) –
ダイナミックコントロールをフォームの下部中央に揃えるには、リンクされた2番目のポストを見てください。アンカーが 'Top、Bottom'に設定され、単一列のドッキングボタンから' TableLayoutPanel'でホストされる自動サイズの 'FlowLayoutPanel'にボタンコントロールを追加することができます。 –