How would the user add textboxes and other objects to the form

aewarnick

Senior Contributor
Joined
Jan 29, 2003
Messages
1,031
I need to make a program that has the capasity to add object permanantly to the form (unless they choose to delete it). I tried this but it does not work:

C#:
Control r=new RichTextBox();
			r.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			r.Location = new System.Drawing.Point(80, 162);
			r.Name = "richTextBox3";
			r.Size = new System.Drawing.Size(520, 56);
			r.TabIndex = 3;
			r.Text = "richTextBox3";

And they would need the ability to move and resize them too. How would I do this?
 
Last edited by a moderator:
You're almost there. Your code will work, but you need to add the following line to the end:

C#:
Controls.Add(r);

As for moving and resizing, you will have to write all this logic yourself, including drawing the selection rectangles and adjusting sizes when the user drags the mouse. It's not a trivial task, but the ControlPaint class may help with some of the drawing.
 
Thank you. How would the user permanantly save it to the program?

And, when the user add a box, how would I make it so that the boxes would only go to a specific place?

For example: The user has a peoples names area on the form for the peoples names to be entered and all the rest is something else. How would I specifically put them in a locatioin right after the last box in that area?
 
You'll have to do all those things yourself, by writing code to persist the number of boxes and their position (either to the registry or to an xml file, etc).

Are you sure you really need to do things this way?
 
I don't know. You need to give a broader description of your project and what it needs to do. It is unusual for a program to create textboxes on the fly and maintain them from one execution to the next.
 
Why do I always do unusual things?. . .
Ms word seems to do it with the toolbar. Not textboxes but icons.
 
Would it be ok to just create a whole buch of text boxes (about 20) and just hide them. When the user wants more to go into design mode and drag them to where they want them?
 
I wouldn't want to maintain it. Why don't you do as divil suggested and provide some more details of the project and let someone help come up with a more appropriate UI design?
 
I hope that goes through. I sent the whole project. I am making a log for my company to write details about people and about the house. I want to separate all the people from the house text boxes. And the people and house boxes can come and go.
 

Attachments

It isn't clear what Textbox1 and textbox2 are for. Are they two separate log entries? What is button1 for on the new comm log input form?

btw. having variable names the same as keywords, like your "New" is not so good.
 
It is very unfinished.

The form will initiallly have about 16 Text boxes on it (includes Rich). Only 2 of them (Text Box: persons name)(Rich text box: persons information) will be 1 person initially. But that will fluxuate when more than one person is at each house. That means I'll need to add textboxes at runtime.

Ignore button1. I was just experimenting.

I am thinking that I could just create a child window for the house info. So that would be 2 separate forms that could auto scroll.
 
Why not use a control list a listbox or listview, which is meant for adding and removing items programmatically?
 
That is not permanant enouph. It is rare that people will be leaving and rare that new boxes will need to be added but they will need to be addes eventually.

The small boxes are for their names and they will stay the same each time the program is opened (they clear now, but they won't later). When a resident of the house dies or leaves their name will be removed along with the corrosponding Rich text box.

But if a residnet comes to live there, 2 new boxes must be made.

When the user enters in info on the residents for that day it saves to a text file names as the current date. On the first form it reads that file to display it to the users.
 
Back
Top