473,806 Members | 2,319 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form.ActiveForm problem....

Form activeForm = System.Windows. Forms.Form.Acti veForm;

Form activeMdiChildF orm = activeForm.Acti veMdiChild;

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 NullReferenceEx ception
whenever I am debugging and a line of code executes that directly or
indirectly triggers the event that invokes this code.

Is there some kind of a workaround for this problem? It is very counter
productive!

Thanks

Pete
Jun 25 '07 #1
3 7689
Hi Peter,

That is an unfortunately consequence of how the debugger interact with the
normal execution.

As the debugger is the active form then your program has no active form,
hence the result you see.

A possible workaround would be to place the breakpoint after you get the
reference to the active form.

"Peter Morris" <su*****@NOdroo pySPAMeyes.comw rote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Form activeForm = System.Windows. Forms.Form.Acti veForm;

Form activeMdiChildF orm = activeForm.Acti veMdiChild;

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
NullReferenceEx ception whenever I am debugging and a line of code executes
that directly or indirectly triggers the event that invokes this code.

Is there some kind of a workaround for this problem? It is very counter
productive!

Thanks

Pete


Jun 25 '07 #2
A possible workaround would be to place the breakpoint after you get the
reference to the active form.
That's what I do when I debug that particular code, however, that code is
triggered from multiple places.

My component's method is triggered whenever a new business object is
created, whenever a business object is modified or deleted. It checks if it
(the component) belongs to the active form, if it does it adds the
modification to its list of altered business objects. Unfortunately this
happens just about everywhere! I could be stepping through code in a
business object "Customer.c s" in a separate DLL and when it does something
like this

this.MadeLiveDa te = DateTime.Now;

It will modify the object and therefore trigger the code in my component
that is subscribed to all changes in the object space. Basically this means
that it is almost impossible to debug my app.
Pete
Jun 25 '07 #3

"Peter Morris" <su*****@NOdroo pySPAMeyes.comw rote in message
news:ef******** ******@TK2MSFTN GP04.phx.gbl...
>A possible workaround would be to place the breakpoint after you get the
reference to the active form.

That's what I do when I debug that particular code, however, that code is
triggered from multiple places.

My component's method is triggered whenever a new business object is
created, whenever a business object is modified or deleted. It checks if
it (the component) belongs to the active form, if it does it adds the
modification to its list of altered business objects. Unfortunately this
happens just about everywhere! I could be stepping through code in a
business object "Customer.c s" in a separate DLL and when it does something
like this

this.MadeLiveDa te = DateTime.Now;

It will modify the object and therefore trigger the code in my component
that is subscribed to all changes in the object space. Basically this
means that it is almost impossible to debug my app.
Yes,

It can be a challenge with those conditions
Jun 26 '07 #4

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

Similar topics

3
10879
by: Sherwood | last post by:
Greetings, I have the following code (which displays a second form), but it is not working as expected. I want to close the calling form after the dismissing the second form. However, the second form never displays with the code I have below. Any suggestions? . ActiveForm.Hide(); frmInstructions frmInstructions = new frmInstructions(); frmInstructions.Show();
2
2048
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
5
3397
by: Sherwood Page | last post by:
Greetings, I have a "newbie" question related to forms. I have the following code in which I display a second form when a button on the first form is pressed (using the "Click" event). private void btnClickMe_Click(object sender, System.EventArgs e) { ActiveForm.Hide(); frmInstructions frmInstructions = new frmInstructions();
7
1928
by: Hugh | last post by:
Hi, I used following sentex to change form width: MainForm.ActiveForm.width = 200 However, a error was generated: An unhandled exception of type 'System.NullReferenceException' occurred. I am confused. The same command works for other applications. Any idea.
0
2542
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
2250
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.
2
4092
by: Jim Madsen | last post by:
OK--Beginner question-- I have a project with one form -- Form1. To change the text, why can't I use "Form1.Text = something"? Instead I have to use "Form1.ActiveForm.Text = Something". As an exercise, I rewrote a timer app that I wrote in VB 5.0. You set the time, and when it runs, it minimizes until the time is up, and then pops back up again and gives an alerting sound. In VB 5.0, I was able to write the time to the forms text...
10
43628
by: John Brown | last post by:
Hi there, Does anyone know how to (generically) determine the currently active form for an application using a "static" function (so I can call it from anywhere). There is no offiical way I've been able to find so I've written the following for starters: public static Form GetActiveForm() { // Returns null for an MDI app Form activeForm = Form.ActiveForm; if (activeForm == null) {
2
1786
by: Emre Sevinc | last post by:
Hello, I have a strange situation. I create a very simple Windows Forms application and place the code below however even though I place breakpoints in various event handling points VS.NET 2005 only enters the breakpoint for the button but not for the form. Am I missing something? Why don't the events for my form Form1 have any effect? Form1.cs:
0
9719
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
9597
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
10366
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
10371
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,...
0
10110
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
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...
0
5546
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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.