473,788 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Control Event

Hello to everybody.

I have a little problem with a Custom Control that I have created. The thing
is that in my control, when I click a button, it should create another
object in the main form.

My control is located in a TabPage, and I want that when the user clicks a
button, a new tabPage is created, but by now, I don't know how to do that.

Any ideas, suggestions, links are wellcomed.

Many thanks,

Marc
Jun 12 '06 #1
3 1823
To add a tab page to an existing tab control you need the following :

TabControl tb1;

TabPage tabPage1 = new TabPage();
tabPage1.Text=" Tab page1";
tb1.Controls.Ad d(tabPage1);
Hope this helps..

Regards,
Tasos

Marc Solé wrote:
Hello to everybody.

I have a little problem with a Custom Control that I have created. The thing
is that in my control, when I click a button, it should create another
object in the main form.

My control is located in a TabPage, and I want that when the user clicks a
button, a new tabPage is created, but by now, I don't know how to do that.

Any ideas, suggestions, links are wellcomed.

Many thanks,

Marc


Jun 12 '06 #2
Well, to do it /properly/ you need to think about what each object should
legitimately be able to see; your control instance would either need to know
about the tab-control instance somehow, or the code containing your control
needs to catch an event and add the page outside of your control (since the
TabControl is not normally available inside your control - their could be 17
TabControl instances nested on the form for instance; which one do we add
to?).

From your post, the former seems more like what you want? In which case a
property may suffice:

using System;
using System.Windows. Forms;

public class MyControl : UserControl {
public MyControl() {
Button button = new Button();
button.Text = "Click Me";
Size = button.Size;
button.Dock = DockStyle.Fill;
button.Click += new EventHandler(bu tton_Click);
Controls.Add(bu tton);
}
private TabControl _tabControl;
public TabControl ParentTabContro l {
get { return _tabControl; }
set { _tabControl = value; }
}
void button_Click(ob ject sender, EventArgs e) {
TabControl tab = ParentTabContro l;
if (tab == null) return;
tab.TabPages.Ad d("New page");
}
}

public class Program {
private static void Main() {

using (Form form = new Form())
using (TabControl tc = new TabControl())
using (MyControl mc = new MyControl())
{
tc.Dock = DockStyle.Fill;
form.Controls.A dd(tc);
tc.TabPages.Add ("Page1");
mc.ParentTabCon trol = tc; // key line
tc.TabPages[0].Controls.Add(m c);
form.ShowDialog ();
}
}
}
Jun 12 '06 #3
Thanks for your answers Tasos and Marc. They have been very helpfully.

Marc

"Marc Solé" <ms***@emdep.co m> wrote in message
news:OG******** ******@TK2MSFTN GP05.phx.gbl...
Hello to everybody.

I have a little problem with a Custom Control that I have created. The thing is that in my control, when I click a button, it should create another
object in the main form.

My control is located in a TabPage, and I want that when the user clicks a
button, a new tabPage is created, but by now, I don't know how to do that.

Any ideas, suggestions, links are wellcomed.

Many thanks,

Marc

Jun 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4786
by: Steve Amey | last post by:
Hi all I am creating a basic control to perform some tasks, and I want to declare some events to be raised so they can be handled from the form that the control is on. I can create my own Event Handler class and use that, but I would like to use the System.EventArgs class so that my event can be handled by different controls. For example:
6
2440
by: Christian H | last post by:
Hi! I've created a custom control (myDrawControl) that deals with drawing. This control is then added to a form( myMainForm) Now, whenever something is dragged and dropped onto myDrawControl , I want to update a variable in myMainForm that keeps track of the objects that have been added.(ArrayList objectsAdded) Now I'm a little confused... How can I do this, when the method that deals
3
549
by: jlea | last post by:
I've created a custom control based on TreeView and it handles several events, such as Mousedown. I added this custom control to the toolbox in another project, dragged the custom control to the form and everything works as it should with the custom control responding to the mousedown event. I also want to respond to the mousedown down event occuring in the custom control inside of the form containing the custom control. Does anyone know...
15
10949
by: Tinus | last post by:
Hello all, I've created a custom control that draws a monthly schedule (using the Draw function in C#). Basically it draws 31 boxes and writes the day number in every box. This works great. But I now want to show a different tooltip for every day. For now I found out that I can add a tooltip for the entire custom control
1
1980
by: Lamont Adams | last post by:
Hi all, I've created numerous custom controls of varying complexity, but I've been on this problem for a day and a half, and I can't figure this mystery out. I hope one of you kind folks can point out the really obvious and stupid thing I'm overlooking here. :) I have a custom control that provides a tasklist similar to what you get in certain parts of Office. On the client it consists of a bunch of nested, named and id'ed divs with...
3
1562
by: Eric Sabine | last post by:
I've created a custom control (ascx) which contains a tree view, a drop down list, and a listbox. The custom control is included in a web form and at runtime, won't compile (I get the "inaccessible due to its protection level" error) because the NodePopulate event of the treeview is set to private. So I changed it to "protected" and the app compiles fine and runs and properly reacts to the event. Good. The problem is inside that...
15
6523
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then i added this line "" before my custom control class (i dont know what this line does). Now
2
2738
by: Michal Valent | last post by:
I would like to fire some custom server control event before Page_Load event like this (from the trace of an aspx page) : Trace Information Category Message From First(s) From Last(s) aspx.page Begin PreInit aspx.page End PreInit 5,38454603734274E-05 0,000054 aspx.page Begin Init 8,96405962016187E-05 0,000036 aspx.page End Init 0,00072941040948794 0,000640 aspx.page Begin InitComplete 0,000772971258380746 0,000044
2
19492
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.