473,785 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you access a control property of a main form from a custom user control?

i have a custom control that gets loaded at runtime. i need to be
able to access a property of a control thats part of the main form,
through the clcik event of the custom control.

i may be making this harder than it needs to be, but seem to be
buffaloed at this point.

thanks to all....

-
john

Aug 22 '07 #1
6 2324


"forest demon" <me********@gma il.comwrote in message
news:11******** **************@ e9g2000prf.goog legroups.com...
>i have a custom control that gets loaded at runtime. i need to be
able to access a property of a control thats part of the main form,
through the clcik event of the custom control.

i may be making this harder than it needs to be, but seem to be
buffaloed at this point.

thanks to all....

-
john
1.) The control you want to access from the user control needs to be visible
to the usercontrol by making the control public or internal.
2.) In the user control's code, you would use the FindForm method (instance
member of Control) and cast the result to the main form's type. (FindForm
returns a reference to the form the control is a child of).
3.) You access the control by name/id on the main form's reference (since
it's a visible member of the main form).

HTH,
Mythran
Aug 22 '07 #2
John,

If the control on the main form is exposed as a public member (or
internal, if they are in the same assembly), then you can just call Parent
on the child control, and cast it to an instance of the parent form and
access the member.

If not, then you have to expose a method/property/field on the parent
form to expose the control you want.

Either that, or you have to pass this information to the control
somehow, either by setting a property, field, or calling a method.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"forest demon" <me********@gma il.comwrote in message
news:11******** **************@ e9g2000prf.goog legroups.com...
>i have a custom control that gets loaded at runtime. i need to be
able to access a property of a control thats part of the main form,
through the clcik event of the custom control.

i may be making this harder than it needs to be, but seem to be
buffaloed at this point.

thanks to all....

-
john

Aug 22 '07 #3

"forest demon" <me********@gma il.comwrote in message
news:11******** **************@ e9g2000prf.goog legroups.com...
>i have a custom control that gets loaded at runtime. i need to be
able to access a property of a control thats part of the main form,
through the clcik event of the custom control.

i may be making this harder than it needs to be, but seem to be
buffaloed at this point.
It sounds to me as if you have inversion of control issues and overcoupling.

A custom control is concerned with its own drawing, properties, etc. A
custom control is not concerned with making the parent form function
correctly.

Declare a public event on the custom control, write a handler in the parent
form. That's the appropriate place to handle interaction between controls.
Aug 22 '07 #4
You can implement an interface, such as IServiceProvide r in the form class.
Later in the user control you can query the interface from the parent form.

--
Sheng Jiang
Microsoft MVP in VC++
"forest demon" <me********@gma il.comwrote in message
news:11******** **************@ e9g2000prf.goog legroups.com...
i have a custom control that gets loaded at runtime. i need to be
able to access a property of a control thats part of the main form,
through the clcik event of the custom control.

i may be making this harder than it needs to be, but seem to be
buffaloed at this point.

thanks to all....

-
john

Aug 22 '07 #5
"forest demon" <me********@gma il.comwrote in message
news:11******** **************@ e9g2000prf.goog legroups.com...
>i have a custom control that gets loaded at runtime. i need to be
able to access a property of a control thats part of the main form,
through the clcik event of the custom control.

i may be making this harder than it needs to be, but seem to be
buffaloed at this point.

thanks to all....

-
john

Use System.Manageme nt and read the "WindowsDirecto ry" property of WMI's
class Win32_Operating System.
Next sample reads the "windowsdirecto ry" from a remote server (BOBSMachine)
....
ConnectionOptio ns co = new ConnectionOptio ns();;
co.Username = "administrator" ; // user with sufficient privileges to
connect to the cimv2 namespace
co.Password = "adminPwd"; // his password
ManagementScope scope = new
ManagementScope (@"\\BOBSMachin e\root\cimv2", co);
SelectQuery query =
new SelectQuery("Se lect windowsdirector y from
Win32_Operating System");
ManagementObjec tSearcher searcher =
new ManagementObjec tSearcher(scope , query);
foreach (ManagementObje ct windir in searcher.Get())
Console.WriteLi ne("Value = {0}", windir["windowsdirecto ry"]);
....

Willy.

Aug 22 '07 #6
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:eo******** ******@TK2MSFTN GP03.phx.gbl...
"forest demon" <me********@gma il.comwrote in message
news:11******** **************@ e9g2000prf.goog legroups.com...
>>i have a custom control that gets loaded at runtime. i need to be
able to access a property of a control thats part of the main form,
through the clcik event of the custom control.

i may be making this harder than it needs to be, but seem to be
buffaloed at this point.

thanks to all....

-
john


Use System.Manageme nt and read the "WindowsDirecto ry" property of WMI's
class Win32_Operating System.
Next sample reads the "windowsdirecto ry" from a remote server
(BOBSMachine)
...
ConnectionOptio ns co = new ConnectionOptio ns();;
co.Username = "administrator" ; // user with sufficient privileges to
connect to the cimv2 namespace
co.Password = "adminPwd"; // his password
ManagementScope scope = new
ManagementScope (@"\\BOBSMachin e\root\cimv2", co);
SelectQuery query =
new SelectQuery("Se lect windowsdirector y from
Win32_Operating System");
ManagementObjec tSearcher searcher =
new ManagementObjec tSearcher(scope , query);
foreach (ManagementObje ct windir in searcher.Get())
Console.WriteLi ne("Value = {0}", windir["windowsdirecto ry"]);
...

Willy.

Sorry, wrong thread, please ignore previous reply .

Willy.

Aug 22 '07 #7

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

Similar topics

49
14358
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The application is relatively big: around 200 tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data (SQL Server 2000), 40 users. I'm wondering what are the disadvantages of using Access as front-end? Other that it's not...
16
7239
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
4
2693
by: BBFrost | last post by:
We have a data entry application written within Framework 1.0 that contains 20+ custom user controls. The controls overlay each other so that only one custom control is visible at a time. What is the best way to keep the cursor from jumping to another non-visible control when the user tabs past the (currently designated) last control on the form. I've had some luck using the Leave event but the last visible control can change...
11
11577
by: John J. Hughes II | last post by:
I have a DataGridView displaying data from a DataSet. To the right of that I have a custom user control which displays one of the data set fields. The custom user control is bound to the data set object and displays the data correctly when I move from row to row. The problem I am having is the data set always reads the data back and considers it change even when it's not. I am looking for how to change the following code so the...
15
6522
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
3259
by: ahmed.maryam | last post by:
Hello Everyone, I designed a custom control that is entirely covered by a picture box. I then dragged this custom control onto a windows form application (called main) and I need to handle mouse events in my main application. Specifically, when a user double clicks on my custom control I need to draw something on another picture box located in my main application. I'm going to attempt to draw the scenario because I think it will
0
1977
by: ChopStickr | last post by:
I have a custom control that is embedded (using the object tag) in an html document. The control takes a path to a local client ini file. Reads the file. Executes the program specified in the ini on the client's PC. After the program has ended the control looks in a client side temp folder (specified by the ini file) for an image created by the executed program. If the image is there, then the control moves the file to a public folder...
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...
4
2492
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried unsuccessfully in creating the whole pane as a user control and have succeeded in adding the pane and then dynamically adding the content which is a user control to the pane, dynamically within the page. However I would like to have a single pane...
0
9645
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
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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
8979
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...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
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
5383
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
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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

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.