473,796 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What replaces frmMain.ActiveF orm (WinForms)

Let's say I have a child form - frmEdit - on that form a RichText Box called
txtedit

So - in VB6 days - I used to be able to refer to that particular active
form's Rich Text box - like this:

With frmMain.ActiveF orm.txtedit.... ...

So - now - I'm using DotNet 2.0 - --

How can I do the same thing?
Nov 23 '05 #1
5 2277
"Elmo Watson" <sp*****@nospam .yahoo.com> schrieb
Let's say I have a child form - frmEdit - on that form a RichText
Box called txtedit

So - in VB6 days - I used to be able to refer to that particular
active form's Rich Text box - like this:

With frmMain.ActiveF orm.txtedit.... ...

So - now - I'm using DotNet 2.0 - --

How can I do the same thing?


Reading your other question, I assume it's an MDI application.

The way you do it now was already bad practice in VB6 because not every
active Form must have a control named "txtEdit". They might have but not by
definition, as ActiveForm is of type Object and not each object has a
property txtEdit. I recommend early binding to get safer code. The solution
depends on how abstract the child form is to be. It also depends on whether
the MDI parent can contain different types of Forms or only instances of the
same Form. If the latter is the case, you can simply use
"Directcast(me. mdiparent.activ emdichild, TypeOfChildForm ).txtEdit". Before,
you probably will have to check that the active Form is not the Form that
does the check (because it probably does not have a txtEdit property). If
the former ist the case, you should consider deriving these Forms from the
same base form or implement an interface. Then cast to that interface or
base type to access txtEdit. You also would have to check whether the active
Form is of that type (If Typeof..is..).

In a good solution, many things must be considered to find a good design.
Armin

Nov 23 '05 #2
Well in this case, Every ActiveForm WILL contain a txtEdit -
That just seems like a lot of code just to access the txtEdit control on the
active form.
I'm using DotNet 2.0, by the way - I thought DotNet was all about
(especially with 2.0) reducing coding
:)

"Armin Zingler" <az*******@free net.de> wrote in message
news:Os******** ******@TK2MSFTN GP12.phx.gbl...
"Elmo Watson" <sp*****@nospam .yahoo.com> schrieb
Let's say I have a child form - frmEdit - on that form a RichText
Box called txtedit

So - in VB6 days - I used to be able to refer to that particular
active form's Rich Text box - like this:

With frmMain.ActiveF orm.txtedit.... ...

So - now - I'm using DotNet 2.0 - --

How can I do the same thing?


Reading your other question, I assume it's an MDI application.

The way you do it now was already bad practice in VB6 because not every
active Form must have a control named "txtEdit". They might have but not
by definition, as ActiveForm is of type Object and not each object has a
property txtEdit. I recommend early binding to get safer code. The
solution depends on how abstract the child form is to be. It also depends
on whether the MDI parent can contain different types of Forms or only
instances of the same Form. If the latter is the case, you can simply use
"Directcast(me. mdiparent.activ emdichild, TypeOfChildForm ).txtEdit".
Before, you probably will have to check that the active Form is not the
Form that does the check (because it probably does not have a txtEdit
property). If the former ist the case, you should consider deriving these
Forms from the same base form or implement an interface. Then cast to that
interface or base type to access txtEdit. You also would have to check
whether the active Form is of that type (If Typeof..is..).

In a good solution, many things must be considered to find a good design.
Armin

Nov 23 '05 #3
I tried that - in VS.net 2005, I get a 'TypeofChildFor m' is not defined.....
Then, in the Red correction Dot - there's no available correction
available....

"Armin Zingler" <az*******@free net.de> wrote in message
news:Os******** ******@TK2MSFTN GP12.phx.gbl...
"Elmo Watson" <sp*****@nospam .yahoo.com> schrieb
Let's say I have a child form - frmEdit - on that form a RichText
Box called txtedit

So - in VB6 days - I used to be able to refer to that particular
active form's Rich Text box - like this:

With frmMain.ActiveF orm.txtedit.... ...

So - now - I'm using DotNet 2.0 - --

How can I do the same thing?


Reading your other question, I assume it's an MDI application.

The way you do it now was already bad practice in VB6 because not every
active Form must have a control named "txtEdit". They might have but not
by definition, as ActiveForm is of type Object and not each object has a
property txtEdit. I recommend early binding to get safer code. The
solution depends on how abstract the child form is to be. It also depends
on whether the MDI parent can contain different types of Forms or only
instances of the same Form. If the latter is the case, you can simply use
"Directcast(me. mdiparent.activ emdichild, TypeOfChildForm ).txtEdit".
Before, you probably will have to check that the active Form is not the
Form that does the check (because it probably does not have a txtEdit
property). If the former ist the case, you should consider deriving these
Forms from the same base form or implement an interface. Then cast to that
interface or base type to access txtEdit. You also would have to check
whether the active Form is of that type (If Typeof..is..).

In a good solution, many things must be considered to find a good design.
Armin

Nov 23 '05 #4
"Elmo Watson" <sp**********@N OSpam.yahoo.com > schrieb

Reading your other question, I assume it's an MDI application.

The way you do it now was already bad practice in VB6 because not
every active Form must have a control named "txtEdit". They might
have but not by definition, as ActiveForm is of type Object and
not each object has a property txtEdit. I recommend early binding
to get safer code. The solution depends on how abstract the child
form is to be. It also depends on whether the MDI parent can
contain different types of Forms or only instances of the same
Form. If the latter is the case, you can simply use
"Directcast(me. mdiparent.activ emdichild,
TypeOfChildForm ).txtEdit". Before, you probably will have to check
that the active Form is not the Form that does the check (because
it probably does not have a txtEdit property). If the former ist
the case, you should consider deriving these Forms from the same
base form or implement an interface. Then cast to that interface
or base type to access txtEdit. You also would have to check
whether the active Form is of that type (If Typeof..is..).

In a good solution, many things must be considered to find a good
design.

I tried that - in VS.net 2005, I get a 'TypeofChildFor m' is not
defined..... Then, in the Red correction Dot - there's no available
correction available....

Replace 'TypeofChildFor m' by the type of the child Form. :-) Example: If
it's class name is 'MyMdiChild', use
Directcast(me.m diparent.active mdichild, myMdiChild).txt Edit
Armin

Nov 23 '05 #5
"Elmo Watson" <sp**********@N OSpam.yahoo.com > schrieb
"Armin Zingler" <az*******@free net.de> wrote in message
news:Os******** ******@TK2MSFTN GP12.phx.gbl...
"Elmo Watson" <sp*****@nospam .yahoo.com> schrieb
Let's say I have a child form - frmEdit - on that form a
RichText Box called txtedit

So - in VB6 days - I used to be able to refer to that particular
active form's Rich Text box - like this:

With frmMain.ActiveF orm.txtedit.... ...

So - now - I'm using DotNet 2.0 - --

How can I do the same thing?
Reading your other question, I assume it's an MDI application.

The way you do it now was already bad practice in VB6 because not
every active Form must have a control named "txtEdit". They might
have but not by definition, as ActiveForm is of type Object and
not each object has a property txtEdit. I recommend early binding
to get safer code. The solution depends on how abstract the child
form is to be. It also depends on whether the MDI parent can
contain different types of Forms or only instances of the same
Form. If the latter is the case, you can simply use
"Directcast(me. mdiparent.activ emdichild,
TypeOfChildForm ).txtEdit". Before, you probably will have to check
that the active Form is not the Form that does the check (because
it probably does not have a txtEdit property). If the former ist
the case, you should consider deriving these Forms from the same
base form or implement an interface. Then cast to that interface
or base type to access txtEdit. You also would have to check
whether the active Form is of that type (If Typeof..is..).

In a good solution, many things must be considered to find a good
design.


Well in this case, Every ActiveForm WILL contain a txtEdit -


Do you mean every instance or every class? This means, do you have several
instances of the same Form class or do you have several Form classes, all
having a txtEdit property/field?
That just seems like a lot of code just to access the txtEdit
control on the active form.
a) The type of ActiveForm is Form.
b) The Form class does not have a txtEdit property
Thus you will have to cast to the specific type. Using an interface or a
common base class makes it easier because you only have to cast to that
type. Otherwise you'd have to check several types (if you do have several
types as asked above).
I'm using DotNet 2.0, by the way - I thought DotNet was all about
(especially with 2.0) reducing coding
:)


Programming is all about type safety. Safety first. :) Enabling late binding
(as you did in VB6) can make programming quicker, but it's more dangerous.
It's more dangerous because it disables some compile time checks and
consequently creates the risk of undiscovered programming errors that cost
you more time in the end than you thought you saved before. It can, it
doesn't have to. Using late binding or not is a matter of how much risk
you want to take. I, personally, don't want to answer for faults caused
by turned-off compile time checks. I will always use this free and helpful
offer.
Armin

Nov 23 '05 #6

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

Similar topics

3
402
by: D Witherspoon | last post by:
Whats the purpose of Application.Run(frmMain) in the Sub Main method. Why not just... Dim fMain as New frmMain frmMain.Show() ???
2
2047
by: Dennis C. Drumm | last post by:
Why is it that when I am debugging an application that has a call to Form.ActiveForm, if I set a breakpoint before the call then when I reach that statement a NullReferenceException is thrown, but if the breakpoint was set following the call to Form.ActiveForm, then I can continue the debug session without a problem? Thanks, Dennis
2
1460
by: T-Man | last post by:
Hey All, In VB6, one could the following: VB.Clipboard.SetData frmSubmit.picToolbarIcon.Image or LoadPicture(App.Path & MY_PIC_PATH)
7
2567
by: ljlevend | last post by:
Is there any way (either .NET or API) to detect when Windows.Forms.Form.ActiveForm changes? Thanks, Lance
2
1536
by: Lou | last post by:
How do I access a property of a control that is part of frmMain from a class? Example: Public Class myClass Public ReadOnly Property DWidth() As Integer Get
0
2540
by: Eugene | last post by:
Hi All, I uses System.Windows.Forms.Form.ActiveForm to get the form with the current control having the focus. However, I got a problem when my application pops up another ShowDialog form. The problem is .ActiveForm doesn't returns me the ShowDialog form, but instead the previously active form. Does anyone know how I can determine the currently active form is the ShowDialog form? Or is there anyhow I can know the previous form is no...
3
2249
by: ramhog | last post by:
Hello all, I have a C# control that is housed on a form that was created in VB 6. There are some activities I want to do only if the control is on the ActiveForm. However, since the form is a VB 6 form when I call Form.ActiveForm I get a null back, even though I can see the form is the active windows form. Is there a good way to get the ActiveForm in this scenario? Thank you.
0
1229
by: sudhansutiwari | last post by:
Hi Friends, I am trying to port an application written in VB 6.0 to VB 2005. As I am new to .NET environment any suggestion would be highly precious for me. My Current problem is : li_mode = Screen.ActiveForm.ScaleMode 'UPGRADE_ISSUE: Form property Screen.ActiveForm.ScaleMode is not supported. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="8027179A-CB3B-45C0-9863-FAA1AF983B59"'...
3
7689
by: Peter Morris | last post by:
Form activeForm = System.Windows.Forms.Form.ActiveForm; Form activeMdiChildForm = activeForm.ActiveMdiChild; This code is in a component of mine and is triggered from various places within my application. My problem is that when I run the app Form.ActiveForm is always set, whereas when I am stepping through code using the debugger it is always null. This results in a NullReferenceException
0
9685
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
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
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
10244
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...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7558
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
5454
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...
1
4130
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
2931
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.