User Control cannot access form variables

Hi All

I am using VB Net 2008.

I am trying to build a large application with multiple integrated functional 
modules like:

- Operation
- Accounting etc.

I have tried to work on a premise where:
- there would be a small root application which will build the basic 
environment for the entire application and display the main menu. Variables 
that control basic environment would be passed on from one form to another.
- each function module would be a "Windows Forms Control Library".
- when an option is selected from the menu in the root program, the form 
would be loaded from the appropriate Windows Forms Control Library (DLL).
- each form has multiple user controls.

NOW:
I am able to load the form and display the first user control. The first 
user control hides on demand and a second user control is displayed on the 
form. However I am unable to access the controls on the form either from the 
first or second user control. Similarly I am unable to access the controls 
on the first user control from the second user control.

Questions:
1. Am I doing the right thing or is there any other better way of doing 
this.
2. How can I access the controls on the parent from from user controls 
(first and second)

Example of Code:
--------------------
Imports AM      ' One functional module

Public Class UserClass01

    Dim UserControl01s As New UserControl01

    Private Sub frmA002_Load(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles Me.Load
        UserControl01s .Height = SplitContainer1.Panel2.Height
        UserControl01s .Width = SplitContainer1.Panel2.Width
        UserControl01s .Parent = Me.SplitContainer1.Panel2
        UserControl01s .Dock = DockStyle.Fill
        UserControl01s .Show()
   End Sub
------------------

Thanks
Mike TI 

0
MikeTI
6/23/2010 8:44:13 AM
dotnet.languages.vb 830 articles. 0 followers. Follow

2 Replies
1659 Views

Similar Articles

[PageSpeed] 9

MikeTI wrote:
> Hi All
> 
> I am using VB Net 2008.
> 
> I am trying to build a large application with multiple integrated 
> functional modules like:
> 
> - Operation
> - Accounting etc.

Each one should be an class/object, an independent little machine that 
can take care of itself like populating itself from and persisting 
itself to a database, along with the ability to interact with other objects.

> 
> I have tried to work on a premise where:
> - there would be a small root application which will build the basic 
> environment for the entire application and display the main menu. 
> Variables that control basic environment would be passed on from one 
> form to another.

That would be a Control object, a public object, that has all the 
properties in it, and the object is passed around.

> - each function module would be a "Windows Forms Control Library".
> - when an option is selected from the menu in the root program, the form 
> would be loaded from the appropriate Windows Forms Control Library (DLL).
> - each form has multiple user controls.
> 

Each form would have its own public Interface with UI controls on the 
Interface using a Model View Presenter and, each UserControl would have 
its own public Interface with UI controls and its Model View Presenter.

> 2. How can I access the controls on the parent from from user controls 
> (first and second)
> 

You treat the form, controls and user controls as objects, because 
that's what they are -- objects,  and you can pass them around and make 
them interact with each other and interact with your custom objects 
(Operations, Accounting, Control etc, etc).

Have you ever heard of design patterns?

0
Mr
6/23/2010 11:59:04 AM
On 23/06/2010 09:44, MikeTI wrote:

> I am using VB Net 2008.

> I am trying to build a large application with multiple integrated
> functional modules like:

> I am able to load the form and display the first user control. The first
> user control hides on demand and a second user control is displayed on
> the form. However I am unable to access the controls on the form either
> from the first or second user control. Similarly I am unable to access
> the controls on the first user control from the second user control.
>
> Questions:
> 1. Am I doing the right thing or is there any other better way of doing
> this.
> 2. How can I access the controls on the parent from from user controls
> (first and second)

Forms and UserControls are classes, just like any other; you just happen 
to be able to see them on screen.

If you want to be able to use the properties and methods of class 'A' 
from class 'B' then you have to "get" a reference to 'A' into 'B' - 
somehow.  Here's one way:

Class UserControl1
    Inherits UserControl

    Sub New()
    End Sub

    Sub New( ByVal parentForm as Form1 )
       m_parent = parentForm

       ' and from here on, Me.Parent.<whatever>
       '   gets you access to the form
    End Sub

    Private ReadOnly Property Parent() as Form1
       Get
          Return m_parent
       End Get
    End Property

    Private m_parent As Form1 = Nothing

End Class

Class Form1
    Inherits Form

    Sub Form_Load( ...
       Dim uc1 as New UserControl1( Me )
       . . .
       Me.Controls.Add( uc1 )
       uc1.Size = New Size( ...
       . . .
    End Sub

End Class

OK, I realise that the Forms Designer insists on having a niladic 
constructor (a "Sub New" with zero arguments) to work with; you could 
pass the reference to the base Form into the UserControl through a 
Property instead, if you prefer.

HTH,
    Phill  W.
0
Phill
6/23/2010 12:30:25 PM
Reply:

Similar Artilces:

Business Portal Error-SQL server does not exist or access denied
Hi, We are running business portal 4.0 for one of our customer. It was running correctly, however, they have changed the SQL server port (previously it was set as default 1433). After that the business portal becomes very slow and while creating a new request (purchase requisition) if we open the item pop up; it is showing exception "SQL Server does not exist or access denied...." Can any body tell me how can I provide the new port number to business portal connection to the database. Thanks and Regards, Waliullah, Thanks for using the newsgroups. I have a...

What's happened to the findfirst function in Access 2010?
I have a working Access 2007 Application which is now failing miserably in 2010. It hinges on location the first available working document in a table runing the following VBA code: With Me.Recordset .FindFirst "([fld1] + [fld2]) = 0" If .NoMatch Then .FindLast "([fdl1] + [fld2]) <> 0" Exit Sub End If .... FURTHER PROCESSING ... What must I do to correct this? Go through a record by record search? End With In 2007, this works correctly, stopping at the appropriate record (approc. rec 1385 in the recordset...

Trouble with Tab Control
I have a form in which i have a tab on it. The problem is the tab appears white and I would like to show the background behind it. I saw in the properties there was a section to make it "transparent" or "normal" i've selected botha nd nothing changes. Any ideas on how to solve this. thanks On Jan 25, 9:32 am, tsla...@gmail.com wrote: > I have a form in which i have a tab on it. The problem is the tab > appears white and I would like to show the background behind it. I > saw in the properties there was a section to make it "transparent" or > ...

open two different Access reports
Hi, I was wondering if i can get some help here. I have two different reports that i want to open when a user clicks a button to view the reports for printing. Is there any way of popping them up at the same time in VBA? Thank you in advance Associates wrote: >Hi, > >I was wondering if i can get some help here. I have two different reports >that i want to open when a user clicks a button to view the reports for >printing. Is there any way of popping them up at the same time in VBA? > >Thank you in advance Yes. Call the DoCmd.OpenReport command twic...

Transferring control of CClientDC to CDC
Hi, I have a class MSWinDisplayManager which I want to take a CClientDC device context so that it's member functions can perform drawing routines on it. I want the class to have it's own CClientDC member which all the methods have access to draw on. My constructor looks like this: MSWinDisplayManager::MSWinDisplayManager(CClientDC& win) { private_win.attach(win); } This is called by the user like: CClientDC dlg(this); MSWinDisplayManager wdm(dlg); then I want to do things like: wdm.drawCars(); The problem I have is that private_win isn't getting control of the device ...

Removing multiple users from Outlook
We did some computer switching, which involved uninstalling a copy of Office XP and replacing it with a copy of Office 2003. Now when I open Outlook, it makes me choose a user. This wasn't in the .pst file which was transferred for the other computer, but apparenly it was on this computer someplace. How can I get Outlook to simply open for the one account without that dialog box popping up? Aloha Annie, Control Panel | Mail | Show Profiles...remove any profiles you don't want. Select the one you do want and set it as the default. (if there are more than one left) -Ben-...

Access 2007 and Vista code problem
I am developing a database on a XP SP2 machine. On a form I have created some buttons with event procedures that run 2 queries and open a form. I sent the db to someone running Access 2007 on a Vista machine and nothing happens when she clicks the buttons and there are no messages. I know nothing about Vista so thanks in advance for any help. Tim Might be a reference problem, have them open the open a code window and click tools references. See what says missing and tell them what should be there, Add it and it should work. Duff "Tim Reid" <TimReid@discussions.micr...

Word2007. Checkbox. No Form
Hello! We have a document (not a form) that we would like to use checkboxes in. This document has a couple of sections where it would be useful if the user could check if something is applicable. We can't protect the whole document. Thank you for your help! Stacey I actually used this feature in a form this morning. Although you don't say what version of Word you are using, you can access the Control Toolbox toolbar in Word 2003, or in Word 2007, it is on Developer tab. To show the developer tab, click the Microsoft Office Button and then click Word Options. S...

Using Access 2003 on client to see Sharepoint 2007
Testing a Sharepoint environment and I can easily manipulate and run the database from Access 2007, but when I try to use Access 2003 it wants me to save the database to a location. The Access 2003 has the compatiblity pack, but it seems to not work when I download it. So the question is using Sharepoint 2007 and posting the Access 2007 format to it, can a user go to the sharepoint site and use a 2003 Access database that has the compatibility pack and open without having to download it? -- Message posted via http://www.accessmonster.com Send check for $500.00 to: David A Jenn...

I would like to know how to set up a 'fill in the blanks' form?
I would like to set up a templet of sorts to fill in the blanks for certificates. ...

compact database in VBA access 2007
Hello, I have recently upgrade to office 2007 from office 2003. To compact a database from within the database itself, I used the follwing code. Unfortunately it no longer works in access 2007. Is there some similar code that will work? Public Function FncCompactTheCurrentDB() CommandBars("Menu Bar"). _ Controls("Tools"). _ Controls("Database utilities"). _ Controls("Compact and repair database..."). _ accDoDefaultAction End Function Thank You, SL On Thu, 28 Jan 2010 17:34:01 -0800, SL <SL@discussions.microsoft....

How do I bind a XAML text box control to a dataset?
Hello; I am new to using WinFx and I am having trouble figuring out how to bind a text box to a field in a dataset. I found an MSDN article: http://msdn2.microsoft.com/en-us/library/ms752057.aspx My question deals with the text box code: <TextBlock Text="{Binding Path=ISBN}" Grid.Column="1" /> How does this text box know to bind to the field "ISBN" in "myDataSet"? How does the control implement the dataset? Thank you Monty ...

Controlling NDR's sent to Originator
Hi, I have a scenario: An Exchange2k User sets up an Auto Forward Rule to forward all inbound mail to a personal email account. This person recieves email into his Inbox and the Rule fires off forwarding the email to their personal account. His personal account is not reachable and Exchange sends a NDR to the original sender. Example: Step 1: john23@example.com sends email to corpuser7@corp14.com Step 2: corpuser7@corp14.com has an Inbox rule that forwards this email to his personal account at homeacct@isporg.com Step 3: exchangeserver.corp14.com recieves an NDR from pubmailer.isporg.c...

LDAP Write access?
My ldap server allows Write access to entries - and a few clients now support this. Any plugins available for Outlook to allow this too? Thanks None that I'm aware of. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipstick.com/outlook/ol2007/ Outlook Tips by email: dailytips-subscribe-request@lists.outlooktips.net Subscribe to Exchange Messaging Outlook newsletter: EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.EASE.LSOFT.COM Outlook Tips: http://www.outlook...

TEMP environment variable
Hi, Does somebody know what happens when I write in the 'TEMP' environment variable more than one directory, seperated by a ';' (For example 'C:\windows\temp ; d:\temp')? Does the OSs (98, 2000, XP) know to use BOTH directories as a temporary directories? Regards, Ram ...

Indirect Method for Name Box Variable? #2
DARN The reason I want to do this is that I have to collect data on a dail basis but I have to display it on a graph on a weekly basis. I select the entire week of cells and give it a name like week52. The following week I have to select the entire week and name i week53. Everything is set up that I can just copy and the numbers will progres for whatever length of time I need to graph (months, years, etc) excep this. Maybe I'll just go back to using the range of cell numbers. Thanks guys -- Chris Brenna ----------------------------------------------------------------------- Chris Bre...

MS Access 2007 code not running
I have created a brand new database in Access 2007 and linked some VB code to run on Form_Load. This code worked perfect with no problems the day I created it. Now today I opened the same form and it is not running the Form_Load code anymore (and yes it is still there, I did not delete it). I got frustrated so I copied and pasted the code to Form_Current and several On_Change events and set breakpoints at the beginning of all the events just to see if it was the Form_Load that was not triggering, but NO events are triggering my VB code. Any ideas? See this page: http://accessjunkie.com/fa...

unable to grant existing user access to TEST company
Set up test company using live company data; ran the script referenced in CustomerSource article ID#871973; can grant and remove user access in all other companies; ran grantsql 9.2; the dexsql log shows the user already has access probably because of using the other company data for the test; I can set up a new user and grant them access, existing users who already have access can view the company...but, I cannot figure out how to grant access to the TEST company to an existing user. The error popup reads "The user could not be added to one or more databases." Dynamics 9.0,...

Picture control on a form
What is the best way to fill a form with a picture control so that when the client window is resized the picture control will fill the form? -- Just Al Take a look at this and see if this is what you want: http://www.codeproject.com/dialog/bmpdlg01.asp Tom "Al" <Al@discussions.microsoft.com> wrote in message news:5BEA0FA2-3F95-4090-B908-A75DBF1D19DE@microsoft.com... > What is the best way to fill a form with a picture control so that when > the > client window is resized the picture control will fill the form? > -- > Just Al Thank You! -- Just Al &...

Null value in form not trapped by beforeupdate event
I have a form in Access 2003 linked to a SQL Server 2005 table. When I clear the value in a textbox (bound field is varchar and is required), I want the before update event to run to tell the user the value cannot be null. When I press the tab button to move to the next field after clearing the texbox, the before update event is not triggering and instead I'm getting the following error: You tried to assign the Null value to a variable that is not a Variant data type. (Error 3162) How can I prevent nulls before and this error from triggering? Thanks! ...

Accessing another user's calendar OL2000/OL2003/Ex2000
Here's the situation: Running Exchange2000, v 6.0, sp4. Users are on XP/OL2003 or NT/OL2000. (we're in the process of upgrading all of the workstations to XP.) VIP user is on XP/OL2003. He can access his calendar just fine on his workstation. His secretary and other office admin type people are still on NT/OL2000. They have reviewer or editor rights to his calendar. They try to access his calendar by chosing File/Open/Other User's Folder... and put in his name and calendar. When they do this, the process hangs. In Task Manager, Outlook is "Running." End the Outloo...

Re-enabled user account cannot log in
In trying to troubleshoot and issue in CRM where I had multiple user accounts for a single ADUC user, I tried disabling and re-enabling a user's account. But even after re-enabling the account the user cannot log in now. The error message says that it is disallowed when he tries to browse to the CRM server. Please help, I need to get this user account working again asap. Joel ...

How export all mailbox-enabled users from the GAL using Outlook?
Hello, We have a user which, for administrative reasons, needs to export all mailbox-enabled users in the GAL now and then. They just need all the names. Is there a straightforward way for them to do that? We don't want to give them any special permissions and want to avoid server scripting. Ideally, they should be able to export it to a CSV file or any text file. Thanks, - Alan. Alan wrote: > We have a user which, for administrative reasons, needs to export all > mailbox-enabled users in the GAL now and then. They just need all the > names. Is there a straightforward way fo...

Disappearing data in sync'd forms
I have a small sized text box in a form called frmMain. This text box may or may not contain a large amount of text. If the text box does contain alot of text I want to open up a new form called frmLargeText that contains a larger text box to allow the user to easily see and edit the large amount of text. I also need the two forms to stay in sync. i.e. if the user moves to a new record then both forms move to the same record. I thought I could do this by setting the recordset of frmLargeText to equal the recordset of frmMain as follows: Dim frm as Form_frmLargeText Dim rst As DAO.Rec...

Can't use openURL or access internet on some locations
I have previously raised a question where openUrl threw an exception in a specific office location. However the problem I have now is that the application just freeze when I call openURL. It seems as it is waiting for something. This only happens at one company so far the company does have a proxy but so do I at work and I have no problems. I have also tried the Microsoft TEAR sample and it behaves the exact same way, it says "Opening internet...Connection made" and then it just stops. If I run it on my computer it gets the webpage and everything finishes ok. I have tried to set t...