Resizing of an AutoScroll Panel affects scrolled position - winforms

When I resize the following form with the right resize handle, the contained TableLayoutPanel gets decorated with scroll bars (as intended, panel1.AutoScroll = true) for smaller form sizes, but the TableLayoutPanel also gets displaced from its original position. See images below: after resizing the form with right resize handle only, the second one has its scroll bars not leftmost and the left border of the content is cut off.
It seems somehow that this behavior is tied to the existence of the nested RadioButtons because if I remove them (or replace them by another TextBox for example), the "normal" behavior is restored (TableLayoutPanel stays in place during resize).
What properties do I have to set in order to keep the content always stationary relative to the (top)left borders?
BTW: When I replace the panel1 by a TabControl + one TabPage, the "normal" behavior is also restored.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Test
{
/// <summary>
/// Description of Form3.
/// </summary>
public partial class Form3 : Form
{
const int textBoxNameWidth = 500;
TableLayoutPanel testControl1;
Panel panel1;
TextBox textBoxName;
RadioButton radioButtonNo;
RadioButton radioButtonYes;
TableLayoutPanel tableLayoutPanelDecision;
public Form3()
{
testControl1 = new TableLayoutPanel();
panel1 = new Panel();
textBoxName = new TextBox();
radioButtonNo = new RadioButton();
radioButtonYes = new RadioButton();
tableLayoutPanelDecision = new TableLayoutPanel();
testControl1.AutoSize = true;
testControl1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
testControl1.Location = new Point(0, 0);
testControl1.Dock = DockStyle.None;
testControl1.ColumnCount = 2;
testControl1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
testControl1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
testControl1.RowCount = 2;
testControl1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
testControl1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
testControl1.Controls.Add(textBoxName, 1, 0);
testControl1.Controls.Add(tableLayoutPanelDecision, 1, 1);
textBoxName.Text = "New Boolean";
textBoxName.TextAlign = HorizontalAlignment.Center;
textBoxName.Anchor = (AnchorStyles.Left | AnchorStyles.Right);
textBoxName.TabStop = false;
textBoxName.Width = textBoxNameWidth;
tableLayoutPanelDecision.AutoSize = true;
tableLayoutPanelDecision.ColumnCount = 2;
tableLayoutPanelDecision.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50f));
tableLayoutPanelDecision.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50f));
tableLayoutPanelDecision.RowCount = 1;
tableLayoutPanelDecision.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tableLayoutPanelDecision.Controls.Add(radioButtonYes, 0, 0);
tableLayoutPanelDecision.Controls.Add(radioButtonNo, 1, 0);
tableLayoutPanelDecision.Dock = DockStyle.Fill;
radioButtonNo.Checked = true;
radioButtonNo.AutoSize = true;
radioButtonNo.TabIndex = 1;
radioButtonNo.TabStop = true;
radioButtonNo.Text = "False";
radioButtonNo.UseVisualStyleBackColor = true;
radioButtonNo.Anchor = AnchorStyles.None;
radioButtonYes.AutoSize = true;
radioButtonYes.TabIndex = 0;
radioButtonYes.Text = "True";
radioButtonYes.UseVisualStyleBackColor = true;
radioButtonYes.Anchor = AnchorStyles.None;
panel1.AutoScroll = true;
panel1.Controls.Add(testControl1);
panel1.Dock = System.Windows.Forms.DockStyle.Fill;
panel1.Location = new System.Drawing.Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new System.Drawing.Size(560, 219);
panel1.TabIndex = 1;
AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(560, 219);
Controls.Add(panel1);
Name = "Form3";
Text = "Form3";
}
}
}

The panel is trying to keep focusable controls within view for the user. To change that, you would have to use your own panel:
public class PanelEx : Panel {
protected override Point ScrollToControl(Control activeControl) {
return this.DisplayRectangle.Location;
}
}

Related

Remove control from Form: space is still occupied

I have a Form and want to toggle show and hide the RichTextBox.
If I hide the control, the control should give up the space reservation, but actually it doesn't.
it is Removed, but the original space reserved by rtbcontrol is still visible as empty grey space.
It seems, it affects only the Controls, which are anchored to the bottom.
I made a small sample for demonstrating my problem:
Desinger:
namespace HideShowTest
{
partial class Form1
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.richTextBox1.Location = new System.Drawing.Point(13, 126);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(289, 80);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(92, 23);
this.button1.TabIndex = 3;
this.button1.Text = "top anchor";
this.button1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button2.Location = new System.Drawing.Point(13, 75);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(92, 23);
this.button2.TabIndex = 2;
this.button2.Text = "bottom anchor";
this.button2.UseVisualStyleBackColor = true;
//
// button3
//
this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button3.Location = new System.Drawing.Point(227, 75);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 1;
this.button3.Text = "Hide Rtb";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(314, 226);
this.Controls.Add(this.button1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button3);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
}
}
and Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace HideShowTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
if (richTextBox1.Visible)
{
richTextBox1.Hide();
this.Height -= richTextBox1.Height;
}
else
{
richTextBox1.Show();
this.Height += richTextBox1.Height;
}
button3.Text = richTextBox1.Visible ? "Hide Rtb" : "Show Rtb";
}
}
}
If I click "Hide Rtb", the bottom anchor button wanders up (it should stay at the same place).
Edit: since you edited the question and asked about a totally different thing:
You have the Anchor property of button2 set to Left and Bottom, so it's clearly going to move when you resize the form in order to maintain the same distance between the button and the bottom of the form.
To avoid that, you can either set the Anchor property to Top or change the location of the button accordingly when changing the size of the form. For example:
int t = button2.Top;
ToggleRtbVisibility();
button2.Top = t;
Original answer:
1) If you want to toggle "show and hide", do hide and show the control, do not remove it.
2) I suspect that you checked the Size property of the form instead of the ClientSize property, but you're changing the value of the ClientSize. Also, don't use fixed numbers for changing the size, calculate them instead.
Try something like this:
private void ToggleRtbVisibility(bool hide)
{
rtbLog.Visible = !hide;
int preservedHeight = rtbLog.Height + rtbLog.Margin.Top + rtbLog.Margin.Bottom;
if (hide)
{
this.Height -= preservedHeight;
}
else
{
this.Height += preservedHeight;
}
}
And if you don't want use a parameter to explicitly specify whether to show or hide the control, you can change the above method to something like:
private void ToggleRtbVisibility()
{
rtbLog.Visible = !rtbLog.Visible;
int preservedHeight = rtbLog.Height + rtbLog.Margin.Top + rtbLog.Margin.Bottom;
if (rtbLog.Visible == false)
this.Height -= preservedHeight;
else
this.Height += preservedHeight;
}
Hope that helps.

WPF UserControl background Transparency doesn't work

I try to pop up a usercontrol using own class ModalDialogManager : Control but the background doesn't seem transparent as shown on http://prntscr.com/6cgyc2
in my ModalDialogManager class, I did specify the windows to allow transparency:
Window w = new Window();
m_window = w;
w.Closing += w_Closing;
w.Owner = GetParentWindow(this);
w.DataContext = this.DataContext;
w.SetBinding(Window.ContentProperty, "");
w.Title = Title;
w.Icon = Icon;
w.Height = DialogHeight;
w.Width = DialogWidth;
w.ResizeMode = DialogResizeMode;
// SHOULD IT WORK?!
w.AllowsTransparency = true;
double t = GetParentWindow(this).Left;
if (IsBorderless)
{
w.WindowStyle = WindowStyle.None;
w.ShowInTaskbar = false;
if (IsStartUpLocationCenter)
{
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
else
{
w.Left = LeftPosition;
w.Top = RightPosition;
w.WindowStartupLocation = WindowStartupLocation.Manual;
}
}
else
{
w.WindowStartupLocation = WindowStartupLocation.CenterOwner;
}
if (IsModal)
w.ShowDialog();
else
w.Show();
but the UserControl design shows ok: http://prntscr.com/6cgyz8
Thus, I tried to use a window to attach the usercontrol and do window.showDialog() with a usercontrol as below:
Window w = new Window();
SolidColorBrush b = new SolidColorBrush();
b.Color = .Colors.Transparent;
w.Background = b;
Grid g = new Grid();
g.Children.Add(new ucSelectCloth());
w.Content = g;
g.Background = b;
w.Height = 300;
w.Width = 600;
w.ShowDialog();
As you can see that http://prntscr.com/6cgzdk the window doesn't look Transparent too.
Any thought?
window remains opaque until you set Window.AllowsTransparency property to true. Once you set Window.AllowsTransparency to true you have to set WindowStyle to None.
add following lines to your code,
w.WindowStyle = System.Windows.WindowStyle.None;
w.AllowsTransparency = true;

GridSplitter Not present

I use this in code behind to test how to add a grid splitter programmatically. (I know, don't use code behind - But this is one of those rare cases I need to. (I think))
public partial class ContainerView : Window, IContainerView
{
[ImportingConstructor]
public ContainerView()
{
InitializeComponent();
SetUp();
}
public void SetUp()
{
_grid = new Grid();
//Single column/single row
_grid.ColumnDefinitions.Add(new ColumnDefinition());
_grid.ColumnDefinitions.Add(new ColumnDefinition());
_grid.ColumnDefinitions.Add(new ColumnDefinition());
_grid.RowDefinitions.Add(new RowDefinition());
_grid.RowDefinitions.Add(new RowDefinition());
var button1 = new Button();
button1.Content = "Btn 1";
button1.Margin = new Thickness(5);
Grid.SetRow(button1, 0);
Grid.SetColumn(button1, 0);
var button2 = new Button();
button2.Content = "Btn 2";
button2.Margin = new Thickness(5);
Grid.SetRow(button2, 1);
Grid.SetColumn(button2, 2);
_grid.Children.Add(button1);
_grid.Children.Add(button2);
var splitterV = new GridSplitter();
Grid.SetRowSpan(splitterV, _grid.RowDefinitions.Count);
splitterV.VerticalAlignment = VerticalAlignment.Stretch;
splitterV.HorizontalAlignment = HorizontalAlignment.Right;
splitterV.ShowsPreview = true;
splitterV.Background = Brushes.Black;
Width = 5;
_grid.Children.Add(splitterV);
Grid.SetColumn(splitterV, 1);
Content = _grid;
}
I can see the two buttons, but the middle column is empty. The GridSplitter is not shown. What am I doing wrong?
You are absolutely correct but you are setting Window's width instead of GridSpitter's width & also you have to give it's ResizeBehaviour.
Instead of this :
Width = 5;
Set GridSpitter's Width & It's ResizeBehavior as :
splitterV.ResizeBehavior = GridResizeBehavior.PreviousAndNext;
splitterV.Width = 5;

changing the backcolor of a panel changes the backcolor for all panels

I have a custom control, OrderEntryCtl, with a TableLayoutPanel that uses Panels insided of the cells of the first row (call it the header row, the Panels are named HeaderPanel1, HeaderPanel2, etc[8 panels altogether, 1 for each column in row 0 of the TableLayoutPanel]). The BackColor of each Panel is set to blue first. At some point, I want to change the BackColor of each Panel to gray. Here's the problem I am running into: Changing the BackColor of 1 panel actually changes the BackColor of all Panels on all of my OrderEntryCtl's added to the Form.
FYI: I'm not creating any of the panels dynamically; they are all created via the designer and the code created by VS is in OrderEntryCtl.Designer.cs
So, consider, I have some number of OrderEntryCtl's on my form (these are added programmatically/dynamically at run time by my code, not by the designer). A user interacts with the first OrderEntryCtl (call it OrderEntry1), then clicks a button that's a part of the control. The click event handler for that button needs to turn the 8 HeaderPanel's to gray:
HeaderPanel1.BackColor = Color.DarkGray;
HeaderPanel2.BackColor = Color.DarkGray;
HeaderPanel3.BackColor = Color.DarkGray;
//etc
I'm expecting only the 8 header Panels to turn gray for OrderEntry1, however, ALL header Panels for ALL OrderEntryCtl's are turning gray. The really odd thing is, I could comment out the last 7 "HeaderPanel#.BackColor = Color.DarkGray;" commands, leaving only HeaderPanel1.BackColor = Color.DarkGray; and this still happens. But, if I add to the event handler
HeaderPanel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
only the border style of panel 2 of OrderEntry1 is affected, which is the expected behavior!
How do I get the BackColor property to behave the same as the BorderStyle property for my panels?
In response to first comment, I've included the code in the Designer.cs
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Panel HeaderPanel1;
private System.Windows.Forms.Panel HeaderPanel2;
private System.Windows.Forms.Panel HeaderPanel3;
private System.Windows.Forms.Panel HeaderPanel4;
private System.Windows.Forms.Panel HeaderPanel5;
private System.Windows.Forms.Panel HeaderPanel6;
private System.Windows.Forms.Panel HeaderPanel7;
private System.Windows.Forms.Panel HeaderPanel8;
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.HeaderPanel1 = new System.Windows.Forms.Panel();
this.HeaderPanel2 = new System.Windows.Forms.Panel();
this.HeaderPanel3 = new System.Windows.Forms.Panel();
this.HeaderPanel4 = new System.Windows.Forms.Panel();
this.HeaderPanel5 = new System.Windows.Forms.Panel();
this.HeaderPanel6 = new System.Windows.Forms.Panel();
this.HeaderPanel7 = new System.Windows.Forms.Panel();
this.HeaderPanel8 = new System.Windows.Forms.Panel();
this.tableLayoutPanel1.SuspendLayout();
this.HeaderPanel1.SuspendLayout();
this.HeaderPanel2.SuspendLayout();
this.HeaderPanel3.SuspendLayout();
this.HeaderPanel4.SuspendLayout();
this.HeaderPanel5.SuspendLayout();
this.HeaderPanel6.SuspendLayout();
this.HeaderPanel7.SuspendLayout();
this.HeaderPanel8.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.BackColor = System.Drawing.Color.White;
this.tableLayoutPanel1.ColumnCount = 8;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 24F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 26F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 24F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 18F));
this.tableLayoutPanel1.Controls.Add(this.HeaderPanel1, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.HeaderPanel2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.HeaderPanel3, 2, 0);
this.tableLayoutPanel1.Controls.Add(this.HeaderPanel4, 3, 0);
this.tableLayoutPanel1.Controls.Add(this.HeaderPanel5, 4, 0);
this.tableLayoutPanel1.Controls.Add(this.HeaderPanel6, 5, 0);
this.tableLayoutPanel1.Controls.Add(this.HeaderPanel7, 6, 0);
this.tableLayoutPanel1.Controls.Add(this.HeaderPanel8, 7, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(944, 90);
this.tableLayoutPanel1.TabIndex = 0;
//
// HeaderPanel1
//
this.HeaderPanel1.BackColor = global::WdRx.Fulfillment.Dispensing.Workstation.Properties.Settings.Default.OrderEntryHeader;
this.HeaderPanel1.Controls.Add(this.Lbl_Header1);
this.HeaderPanel1.DataBindings.Add(new System.Windows.Forms.Binding("BackColor", global::WdRx.Fulfillment.Dispensing.Workstation.Properties.Settings.Default, "OrderEntryHeader", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
this.HeaderPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.HeaderPanel1.Location = new System.Drawing.Point(675, 0);
this.HeaderPanel1.Margin = new System.Windows.Forms.Padding(0);
this.HeaderPanel1.Name = "HeaderPanel1";
this.HeaderPanel1.Size = new System.Drawing.Size(107, 45);
this.HeaderPanel1.TabIndex = 10;
Ok, after reviewing the above, I realize my problem is that I am associating the BackColor property to a color defined in my config file, and I'm doing this for all of the panels. The binding is for the property changed event, so change the property on 1 panel, updates all panels.
So, I'm now taking suggestions on how to still fetch my initial color from my config file, but without binding the OnPropertyChange event ? ? ? Anyone ?

Radiobuttons are invisible inside of Array of Panels

In the Form constructor I generate an array of panels (pnl_ in the code below), that include radiobuttons.
When I visualize the Form, only panels are visible, NOT radiobuttons inside.
Curiously, everything is OK, when I generate only one panel (pnl in the code below).
public partial class Radiobuttons_on_Panel : Form
{
private Panel pnl = new Panel();
private RadioButton rbtn1 = new RadioButton();
private RadioButton rbtn2 = new RadioButton();
private Panel[] pnl_ = new Panel[7];
private RadioButton[] rbtn1_ = new RadioButton[7];
private RadioButton[] rbtn2_ = new RadioButton[7];
public Radiobuttons_on_Panel()
{
InitializeComponent();
pnl.Location = new Point(10, 10);
pnl.Size = new Size(100, 100);
pnl.BorderStyle = BorderStyle.FixedSingle;
rbtn1.Location = pnl.Location;
rbtn1.Text = "AAA";
rbtn2.Location = new Point(pnl.Location.X, pnl.Location.Y + rbtn1.Height);
rbtn2.Text = "BBB";
pnl.Controls.Add(rbtn1);
pnl.Controls.Add(rbtn2);
this.Controls.Add(pnl);
for (int i = 0; i < pnl_.Length; i++)
{
pnl_[i] = new Panel();
pnl_[i].BorderStyle = BorderStyle.FixedSingle;
pnl_[i].Size = new Size(100, 100);
pnl_[i].Location = new Point(10 + i * 110, 200);
rbtn1_[i] = new RadioButton();
rbtn1_[i].Location = pnl_[i].Location;
rbtn1_[i].Text = "AAA";
rbtn2_[i] = new RadioButton();
rbtn2_[i].Location = new Point(pnl_[i].Location.X, pnl_[i].Location.Y + rbtn1_[i].Height);
rbtn2_[i].Text = "BBB";
pnl_[i].Controls.Add(rbtn1_[i]);
pnl_[i].Controls.Add(rbtn2_[i]);
this.Controls.Add(pnl_[i]);
}
}
}
Where is the problem?
Your problem with this is that your calculation of location is wrong. The location of the radio buttons are relative to their container - in this case, the panels. If you just set your locations to
rbtn1_[i] = new RadioButton();
rbtn1_[i].Location = new Point(10, 10);
rbtn1_[i].Text = "AAA";
rbtn2_[i] = new RadioButton();
rbtn2_[i].Location = new Point(rbtn1_[i].Location.X, rbtn1_[i].Location.Y + rbtn1_[i].Height);
rbtn2_[i].Text = "BBB";
the buttons will lay out like you want them to.
Thing work out in your first one because your radio button locations values are small enough to be visible in the panel. For those others, well, they are outside the bounds of their parent panels.
The long and short of it is that the Location property is always relative to the container, whether that is a Panel or a Form - the Location values for your panels are relative to the Form but the the Location values for your radio buttons are relative to whatever panel they are in.
MSDN Reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.location.aspx

Resources