By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

Dynamic Control creation

P: 38
I have a Panel wherein i place textboxes dynamically. I have set AutoScroll property for the Panel to true. So when the size exceeds automatically Vertical Scroll bar appears.
I place dynamic textboxes in sequential order i.e one after the other row wise. I calculate the exact Location and place the control. This works fine.
The problem happens when i use the scroll bar to scroll down and then add few more TextBoxes. Now the location of the new added Text Box after scroll is not properly placed. Eventhough the calculation is the same. There is more gap between the previous and the next TextBox control. Why?
Feb 1 '08 #1
Share this Question
Share on Google+
4 Replies


kenobewan
Expert 2.5K+
P: 4,871
Could be spaces are added or new textboxes need a style?
Feb 1 '08 #2

P: 38
Could be spaces are added or new textboxes need a style?
As per your suggestion i changed the BorderStyle for dynamic textBox controls but i still see the same problem.
Could you suggest what else i can try to fix the spacing problem
Feb 5 '08 #3

Shashi Sadasivan
Expert 100+
P: 1,435
seems your calculation is running a for loop which keeps adding more space each time a new control is added.
Would you like to show the code calculation for the space?
Feb 5 '08 #4

P: 38
seems your calculation is running a for loop which keeps adding more space each time a new control is added.
Would you like to show the code calculation for the space?
There is no for loop. On click on the button i'm adding the new Textboxes.

Created a Windows Application
On the Form add a new Panel. Set the AutoScroll property to true
Add a button below the Panel

private ArrayList textboxes;
private int pos;
private int noOfTextBox;
public Form1()
{
InitializeComponent();
pos = 10;
noOfTextBox = 0;
this.textboxes = new ArrayList();
}
private void button1_Click(object sender, EventArgs e)
{
// Increment the count
noOfTextBox++;

// Set the location for new steps
pos += 41;
int i = noOfTextBox-1;

// Add the new Step to ArrayList and Panel
this.textboxes.Add(new RichTextBox());

((RichTextBox)this.textboxes[i]).Location = new System.Drawing.Point(12, pos);
((RichTextBox)this.textboxes[i]).Name = "TextBoxName" + i.ToString();
((RichTextBox)this.textboxes[i]).Size = new System.Drawing.Size(539, 35);
((RichTextBox)this.textboxes[i]).TabIndex = noOfTextBox;
((RichTextBox)this.textboxes[i]).Text = "Step" + noOfTextBox;
((RichTextBox)this.textboxes[i]).BorderStyle = BorderStyle.Fixed3D;

// Add the new Step to Panel
this.panel1.Controls.Add(((RichTextBox)this.textbo xes[i]));
}
Feb 5 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.