C # using dockstyle and specified stock

I am trying to insert several objects into a new form that I programmatically create; basically I want the Buttonbottom and RichTextBoxfill all the remaining space. I set the former as Dock = DockStyle.Bottom, and the latter as Dock = DockStyle.Fill, and it works.

Now I'm trying to insert a gap between the elements, so I added an addition in the form and a mark in the button. The first works correctly, but the margin is not, so between RichTextBoxand Buttonthere is no space.

Here is the code and output. Did I miss something?

// Parent Form
SMSForm.Padding = new Padding(5);

// TextBox
RichTextBox SMStext = new RichTextBox();
SMSForm.Controls.Add(SMStext);
SMStext.Dock = DockStyle.Fill;

// Button
Button SMSsend = new Button();
SMSsend.Text = "Send SMS to ";
SMSForm.Controls.Add(SMSsend);
SMSsend.Margin = new Padding(10);
SMSsend.Dock = DockStyle.Bottom;

enter image description here

+4
source share
2 answers

Margin .

MSDN. Table layout panel

           RichTextBox SMStext = new RichTextBox();

            TableLayoutPanel pnl1 = new TableLayoutPanel();
            pnl1.RowStyles.Clear();
            pnl1.ColumnStyles.Clear();
            pnl1.RowCount += 2;
            pnl1.ColumnCount += 1;
            pnl1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100.0F));
            pnl1.RowStyles.Add(new RowStyle(SizeType.Percent,80.0F));
            pnl1.RowStyles.Add(new RowStyle(SizeType.Percent,20.0F));
            pnl1.Controls.Add(SMStext,0,0);
            SMStext.Dock = DockStyle.Fill;
            Button SMSsend = new Button();
            SMSsend.Text = "Send SMS to ";
            this.Controls.Add(pnl1);
            pnl1.Dock = DockStyle.Fill;
            pnl1.Controls.Add(SMSsend,0,1);
            SMSsend.Dock = DockStyle.Fill;
           SMSsend.Margin = new Padding(10);
+4

RTB. RTB , ( ).

RTB .

.

, , .

+2

All Articles