C# Generating a textbox and anchoring it at runtime
C# 4.0
----------
I have a tabcontrol called tabmain. I have a button which I click which will create a new tabpage with a richtextbox and a small textbox at the bottom. Similiar to a chat client, the richtextbox acts as the output from the server and the textbox is the input (trying to give you an image of what my tabpage looks like).
Heres my code
Code:
public void AddChannel(string _channel)
{
RichTextBox rtxt = new RichTextBox();
rtxt.Name = "out" + _channel.Remove(0, 1);
rtxt.Location = new System.Drawing.Point(0, 0);
rtxt.Size = new System.Drawing.Size(546, 352);
TextBox txt = new TextBox();
txt.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
txt.Name = "in" + _channel.Remove(0, 1);
txt.Location = new System.Drawing.Point(0, 355);
txt.Size = new System.Drawing.Size(546, 20);
TabPage page = new TabPage();
page.Controls.Add(txt);
page.Controls.Add(rtxt);
page.Text = _channel;
page.Location = new System.Drawing.Point(4,22);
page.Padding = new System.Windows.Forms.Padding(3);
page.Size = new System.Drawing.Size(546, 375);
page.UseVisualStyleBackColor = true;
page.Name = "page" + _channel.Remove(0, 1);
tabMain.TabPages.Add(page);
}
Now it works fine without the anchors but with the anchors it just messes everything up. i pretty much made it then copied the designer code. The right anchor goes past the tabcontrol is in aswell as the bottom, and the bottom textbox doesnt even show up. What am I doing wrong?
Re: C# Generating a textbox and anchoring it at runtime
Ya no that is not what i want. The richtextbox will fill the whole void and the textbox would overlapp it making you unable to see a line of the richtextbox. It works fine when I anchor it at design time but the generated ones just dont seem to work.
Re: C# Generating a textbox and anchoring it at runtime
Here I have made a tiny project that adds a tab with richtextbox and textbox at runtime and anchors them, you can see the results of the anchor. You would think, using the exact same code as the designer, it would have the same affects.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.