473,394 Members | 1,778 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,394 software developers and data experts.

How to get instance of a container from the control inside

I have a class extending PictureBox. I use it as container adding a
Label control inside the PictureBox.

I use this kind of "widget" in another class, and I want to catch the
event on mouse click on the label only. That works.

But in the event function, I want to call a function to modify the
container, but I don't know how to do that.

Example:
namespace xxx
class myPictureBox : System.Windows.Forms.PictureBox
{
private Label txt;
public myPictureBox()
{
txtTab = new Label();
this.Controls.Add(txtTab);
}
public void SetPictureBoxAttributes(//some stuff)
{
//set some stuff
}
public Label GetTabLabel()
{
return txt;
}
}
class myApp
{
public myApp()
{
xxx.MyPictureBox pb = new xxx.MyPictureBox();
pb.SetPictureBoxAttributes(//some stuff);

pb.GetTabLabel().MouseDown += new
System.Windows.Forms.MouseEventHandler(this.pblabM ouseDown);
}
public void thetabMouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Label currentlabel = (Label)sender;
currentlabel.????? // what to call to retreive the container pb
and
// call the function
SetPictureBoxAttributes();
// ???????????????????????
}
}
Thank you
François

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 16 '05 #1
1 2466
You need to add the label to the picture boxes Controls collection, then you
can reference it with the Parent property

Label lbl = (Label)sender;
PictureBox pb = (PictureBox)lbl.Parent;

pb.XXXX = XXXX

Hope that helps.

Regards
Neil
"Efkas" <fl**@rfranco-dot-ca.no-spam.invalid> wrote in message
news:41**********@Usenet.com...
I have a class extending PictureBox. I use it as container adding a
Label control inside the PictureBox.

I use this kind of "widget" in another class, and I want to catch the
event on mouse click on the label only. That works.

But in the event function, I want to call a function to modify the
container, but I don't know how to do that.

Example:
namespace xxx
class myPictureBox : System.Windows.Forms.PictureBox
{
private Label txt;
public myPictureBox()
{
txtTab = new Label();
this.Controls.Add(txtTab);
}
public void SetPictureBoxAttributes(//some stuff)
{
//set some stuff
}
public Label GetTabLabel()
{
return txt;
}
}
class myApp
{
public myApp()
{
xxx.MyPictureBox pb = new xxx.MyPictureBox();
pb.SetPictureBoxAttributes(//some stuff);

pb.GetTabLabel().MouseDown += new
System.Windows.Forms.MouseEventHandler(this.pblabM ouseDown);
}
public void thetabMouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Label currentlabel = (Label)sender;
currentlabel.????? // what to call to retreive the container pb
and
// call the function
SetPictureBoxAttributes();
// ???????????????????????
}
}
Thank you
François

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Nov 16 '05 #2

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

Similar topics

4
by: Yasutaka Ito | last post by:
Hi, As you know, all the non-ui components (like Timer control, etc.) that sit on the form are contained in its private variable 'components'. How can I enumerate such components from any form...
1
by: cefrancke | last post by:
Is there a generic container that can go in a tab control? I cant seem to get a tab control (which can hold many types of other controls) to be contained by another tab control. My main form...
0
by: Earl Teigrob | last post by:
I have created a templated custom control that simply creates a spacing table around other objects. This control works fine for most uses but when I add it inside the ItemTemplate of a DataGrid...
13
by: Max | last post by:
Hi There! I'm having a mysterious error right after I login using Forms Authentication in my ASP.NET app. Below is the error... Exception Details: System.NullReferenceException: Object...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
3
by: Tom | last post by:
This is probably pretty easy, but how does one determine if a control is a CONTAINER control? I thought something like If Typeof myControl is ContainerControl then .... would work but that...
1
by: Graham | last post by:
Hi, I am trying to write a custom email form control that doesn't require programming experiance in order to implement (for our html guys). I have a base design that I would like to use for the...
2
by: Daniel Lipovetsky | last post by:
I would like for an object to "report" to a container object when a new instance is created or deleted. I could have a container object that is called when a new instance is created, as below. ...
1
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
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: 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
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.