473,378 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Create and delete Controls At Runtime

Assume i have a chart (a type of control)...
at run time, how could i add more charts and close the charts on a form by end user?
e.g.

---------------------
chart1
chart2
---------------------

as i add a new chart it become as below...

---------------------
chart1
chart2
chart3
---------------------

when i close chart2, chart3 could move up immediately
--------------------
chart1
chart3
--------------------

Could anyone tell me how to do that? please.
Jul 14 '09 #1
6 9826
to remove the chart2.. i could use the this.Controls.RemoveByKey("chart2"); command... but the problem is the chart3 wont shift up...
i'm not sure whether is it the right approach to use the command to delete the chart2.
Jul 14 '09 #2
tlhintoq
3,525 Expert 2GB
You will have to manually loop through your charts and change their .Location property


Chart3.Location = new Point(Chart2.Location.x, Chart2,Bounds.Bottom + 10);

and so on.
Jul 14 '09 #3
tlhintoq
3,525 Expert 2GB
This just occured to me...A panel has auto layout features.

Put a panel as the first control, with Dock to full. This becomes the primary panel. The "canvas" for your work.
Put your chart on another panel, whose width is the same as the primary panel.
Add the chart's panel to the primary panel. The primary panel will 'flow' the controls downward automatically.

When you want to delete a chart and have all the rest slide up, just delete the panel with that chart. The rest will take care of itself.
Jul 14 '09 #4
@tlhintoq
how to set dock to full??? Dock only could set to fill, bottom, right, left and top.

i set panel1 to fill. add another 3 panels ( panel2, panel3, panel4) and 1 button on tops of it. for button1_click i add the code this.panel1.Controls.RemoveByKey("panel3");

but the click button panel3 gone but panel4 didnt shift up...

please guide
Jul 15 '09 #5
tlhintoq
3,525 Expert 2GB
I should have said "FlowControlPanel"

Place a FlowControlPanel on your form and you will see several properties you want such as "FlowDirection" that you can set to "TopDown"

The code below works with FlowControlPanel dragged to the form along with two buttons.


Expand|Select|Wrap|Line Numbers
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             Panel One = new Panel();
  4.             One.BackColor = Color.Red;
  5.             One.Name = "One";
  6.             flowLayoutPanel1.Controls.Add(One);
  7.  
  8.             Panel Two = new Panel();
  9.             Two.BackColor = Color.White;
  10.             Two.Name = "Two";
  11.             flowLayoutPanel1.Controls.Add(Two);
  12.  
  13.             Panel Three = new Panel();
  14.             Three.BackColor = Color.Blue;
  15.             Three.Name = "Three";
  16.             flowLayoutPanel1.Controls.Add(Three);
  17.         }
  18.  
  19.         private void button2_Click(object sender, EventArgs e)
  20.         {
  21.             flowLayoutPanel1.Controls.RemoveByKey("Two");
  22.         }
  23.  
Depending on what your chart objects are like, you probably don't even need to place them on panels. Just put the charts directly into the FlowControlPanel. Just depends on the look and behavior you want. I tend to put in a Panel that is full width and alternate colors, then put the repetitive things like your charts on the panels making it easier to follow which record is which. Kind of like the old green/white bar computer paper.
Jul 15 '09 #6
Thank you.
i wonder if i can create a close button at the top right edge of each panel... so that i could close the panel with the 'x' button likewise the form we have.
Jul 15 '09 #7

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

Similar topics

4
by: Tom Rathbun | last post by:
This is probably simple but it has stumped me. I want to create objects at runtime for example: A program that would allow you to draw lines on a form. For each new line I would like to create a...
7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
3
by: David | last post by:
I have a problem that I cannot delete components that are placed on a Tabbed page in Visual Basic.Net 2003. (OS = Windows 2000 Professional) The form uses a Tab Control with several pages. I have...
3
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
4
by: Sakharam Phapale | last post by:
Hi all, Is it possible to create menu in runtime in VB 6.0. If yes then How? Thanks and Regards Sakharam Phapale
3
by: s.lustre | last post by:
after adding controls to a panel on my form, i need to delete them. does anybody know how to programatically delete controls? 'my add function works For i = 0 To...
4
by: David | last post by:
I have posted this request on several groups but not yet found anyone who has experience the problem. Hopefully this group may be more appropriate for the post. I run VB.NET in Windows 2000...
0
by: timbobd | last post by:
I have a Windows Form project with a TabControl-based window. After adding a second tab, I can no longer copy/paste/delete controls, either on the original tab or after they have been added to any...
7
by: Matt | last post by:
Hi all, I'm trying to create a system where it reads a number of records from a database and then creates a row in the GUI that contains a single field from the database and a button that has a...
3
by: tetsuo2030 | last post by:
Greetings all, (Access 2003) The bosses want me to take an old version of a database designed with a single-user-at-a-time mentality and update it to allow multiple, simultaneous users. The...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.