473,325 Members | 2,442 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,325 software developers and data experts.

object.TopLevel control

Hi,
I inherited Button and I created my component (MyButton)
In this button onclick event I want show this objects parent form. When my
form is not MDIChild this codes run correct. But when my form is MDIChild
this codes show MDIParents name.
How can I show parent form name (not MDIParent)

public class MyButton: System.Windows.Forms.Button{
{
....
protected override void OnClick(EventArgs e)
{
if (this.TopLevelControl is Form)
{
Form Form_ = (Form)this.TopLevelControl;
MessageBox.Show(Form_.Name);
}
base.OnClcik(e;)
}
....
}
Nov 16 '05 #1
2 6155
The TopLevelControl property for controls on MDI childs will always be
the MDI Parent form. You can iterate through the parents of your control
and return the first parent that is a Form.

protected override void OnClick(EventArgs e)
{
Control parent = this.Parent;
while( !(parent is Form) && (parent != null))
parent = parent.Parent;

if(parent != null)
{
MessaegBox.Show(parent.Name);
}

base.OnClcik(e;)
}

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Levis wrote:
Hi,
I inherited Button and I created my component (MyButton)
In this button onclick event I want show this objects parent form. When my
form is not MDIChild this codes run correct. But when my form is MDIChild
this codes show MDIParents name.
How can I show parent form name (not MDIParent)

public class MyButton: System.Windows.Forms.Button{
{
...
protected override void OnClick(EventArgs e)
{
if (this.TopLevelControl is Form)
{
Form Form_ = (Form)this.TopLevelControl;
MessageBox.Show(Form_.Name);
}
base.OnClcik(e;)
}
...
}

Nov 16 '05 #2
Hi Levis,

Try calling button's FindForm method.
If you read in the docs about TopLevelControl you'll find out that what
you've got with this property is exactly what it supposed to return

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Levis" <Ia*@sssss.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
I inherited Button and I created my component (MyButton)
In this button onclick event I want show this objects parent form. When my
form is not MDIChild this codes run correct. But when my form is MDIChild
this codes show MDIParents name.
How can I show parent form name (not MDIParent)

public class MyButton: System.Windows.Forms.Button{
{
...
protected override void OnClick(EventArgs e)
{
if (this.TopLevelControl is Form)
{
Form Form_ = (Form)this.TopLevelControl;
MessageBox.Show(Form_.Name);
}
base.OnClcik(e;)
}
...
}

Nov 16 '05 #3

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

Similar topics

0
by: Scott Holmes | last post by:
I'm trying to determine best practices as well as learn basic coding syntax. I wish to open an input screen to view/enter data. The screen also requires a menu. This is part of the code I have...
0
by: MetalOne | last post by:
I would like to build an interactive interpreted mode(TopLevel) similar to what Python provides when run without a script. I want the TopLevel interpreter for JavaScript. I don't care about...
2
by: HarryD | last post by:
Hello, Maybe someone can help? According to ms kb-article 183329 i am trying to populate a treeview object on a asp-page, with realtime data from a accessdatabase. The database routine works...
2
by: HarryD | last post by:
Hello, Maybe someone can help? According to ms kb-article 183329 i am trying to populate a treeview object on a asp-page, with realtime data from a accessdatabase. The database routine works...
2
by: python programming newb | last post by:
Hi all, first post. I'm new to python and tkinter. I'm trying to write a program that opens the root window with a button that then opens a toplevel window that then has it's own widgets. I...
8
by: gel | last post by:
Hi I would like to pass a variable in and use it as part of a name of an object, something like below, where I pass the variable software into the function and use it as part of the name of the...
2
by: Tuomas | last post by:
From a PyGTK component I would like to react moving and resizing the toplevel window. I try to connect the toplevel 'frame-event' to my callback, but the toplevel do not fire on moving or resizing....
7
by: Chris | last post by:
Hi, If a user resizes a Toplevel window, or I set a Toplevel's geometry using the geometry() method*, is there any way to have the geometry reset to that required for all the widgets? I think...
2
by: Pedro | last post by:
Hi I'm trying to build a small application that can display some images in a toplevel window. I have this code: def Results(master): from Tkinter import Toplevel, Button, Label from PIL...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.