473,699 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form can't see event in usercontrol

3 New Member
Hello,

I'm trying to make an event that will close a usercontrol and open another one. The first user control is for login and when the password have been validated, the event should fire and the event/form would close the usercontrol. The problem is that the form can't see the event with the error "are you missing a using directive or an assembly reference?"

The form code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.Odbc;
  10.  
  11. namespace økonomi
  12. {
  13.  
  14.     public partial class MainForm : Form
  15.     {
  16.         UserControl LoginControl = new LoginControl();
  17.         public MainForm()
  18.         {
  19.             InitializeComponent();
  20.             InitControl();
  21.         }
  22.  
  23.         void InitControl()
  24.         {
  25.  
  26.             LoginControl.OnMyEvent += new LoginControl.onMyEventHandler(catchevent);
  27.             panel1.Controls.Add(LoginControl);
  28.         }
  29.  
  30.         static void catchevent(object sender, EventArgs e)
  31.         {
  32.             MessageBox.Show("Hello");
  33.         }
  34.     }
  35. }
It's line 26 that gives me the error (OnMyEvent).

And the usercontrol:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace økonomi
  11. {
  12.  
  13.     public partial class LoginControl : UserControl
  14.     {
  15.         public delegate void onMyEventHandler(object sender, EventArgs e);
  16.         public event onMyEventHandler OnMyEvent;
  17.  
  18.         public LoginControl()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         public void btnLogin_Click(object sender, EventArgs e)
  24.         {
  25.             if (txtPwd.ToString() == "1234")
  26.             {
  27.                 OnMyEvent(this, e);
  28.             }
  29.  
  30.         }
  31.     }
  32. }
Aug 17 '10 #1
5 2082
fastestindian
74 New Member
The cause for this error are:


1.You do not have class with that name in your project
2. You add the class later on and run the project without compiling
3. You have the class but you do not specify the namespace via Imports or using keyword

Even though you have the dll added to your reference, use Imports statement.

For example if we have a tiered app, in which there is a namespace called BusinessDataObj ects, in which I write all my classes, to reference this in my project I add the dll to this namespace, but then in my code in the presentation layer to use this I also write using BusinessDataObj ects. in your case it will be Imports EmailMessage.

Hope this works
Aug 18 '10 #2
Henrik
3 New Member
I'm not sure i understand what dll am i suppose to import where? I think it's you point 3 that is the problem in my case...
Aug 18 '10 #3
Christian Binder
218 Recognized Expert New Member
Why namespace EmailMessage? ("in your case it will be Imports EmailMessage.") This namespace isn't used here?

Do you have multiple projects or are LoginControl and MainForm in the same project/assembly?
Aug 18 '10 #4
Henrik
3 New Member
Yes they are in the same project.
Aug 18 '10 #5
Christian Binder
218 Recognized Expert New Member
Oh, I think, I figured out, what's wrong:
Change line 16 from
UserControl LoginControl = new LoginControl();
to
LoginControl LoginControl = new LoginControl();
[/code]
Aug 19 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2963
by: Jason | last post by:
I have a main form with a sub form. All the fields in the subform are mandatory. I had some code on the main form Before Update Event to check if all the fields in the sub form have data. If not, I want to cancel update event and allow user to enter the sub form to fill in all mandatory fields. I tried many code and don't have any solution to work around. It never allows me to go into the sub form again after triggering the before update...
4
14480
by: athlonman | last post by:
Hi all!! II'm trying to set the Text of a TextBox in "Form1" when I click a Button in a UserControl. My code is: : public class Form1 : System.Windows.Forms.Form { public System.Windows.Forms.TextBox textBox1; private WindowsApplication1.UserControl1 userControl11;
0
1180
by: ATS | last post by:
PRB: Can not get UserControl/HTML/OBJECT to work on XP/SP2/IIS/IE6 Please help, I can not get my UserControl to work from a simple OBJECT tag in a simple HTML web page on Windows XP with SP2 and IIS. I have made UserControls before, but for whatever reason, XP/SP2/IIS/something is not letting the web page run the UserControl, giving an error of "Object doesn't support this property or method". Here are the steps to reproduce:
3
3605
by: feng | last post by:
We have a windows form project that has multiple child forms inherit from one base form. In our base form's form load event handler, we have some common logic in there. These common logic is needed by all the child forms when they load up. So when a child form gets called, the base's form load event handler gets called first, so is the common logic, then the child's load event handler gets executed. So far, everything works fine,...
5
2126
by: gsb58 | last post by:
Hi! In my application I have code that will give the user a choice when he click's the close button on the ToolBar1. However, when he clicks the close button of the form, the form will shut down even if he chooses the cancel button of the messagebox that pop's up. Now...if he, on the other hand, chooses ALT+F4, then I catch this in
1
1379
by: kmercer46 | last post by:
i want to use a form's OnError event to close the form if an error occurs, but the event is not working. it just brings up the error window with the End and Debug buttons. i remember seeing an option somewhere that consults the form's event before any other control's event, but i can't find that in any property windows. is that the issue? or.. maybe someone can hear my main problem and address another way to handle it:
3
2379
by: lesperancer | last post by:
I've got application A, with a hidden form, whose unload event is cancelled unless you use an 'exit' button (so I can do special processing) this works fine when using just application A and it prevents me from 'x'ing out of msaccess.exe now, I open application A from within application B using the code below
13
1991
by: PW | last post by:
Hi, This is bizarre. I've check and rechecked the spelling, cut and paste the name of the form (when trying to rename the form) and the control yet I still get a parameter prompt when the form runs. I've even deleted the control and started over. This is the code for the recordsource of the form: "SELECT * FROM qryGuestStorePurchases_pw WHERE
5
2017
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I guess this probably a very silly question. I am not sure if this can be done in classical asp. A button has to be clicked if a selection in drop down list has been changed. If not, a pop up message pops and reminds the user you need to click the button before continue. Can this be done in some ways??? Thank you! -- Betty
0
818
by: Hillbilly | last post by:
Right now I have a lot of form data in an event handler I will need to reuse in other event handlers in the same page. Using firstName1 and firstName2 for strings can't possibly be the way I should be coding this type of task not to mention its tedious as all get out. What's a workable way to move the initialization out of the event handler and into the class or wherever so the data in the form can be used by different event handlers in...
0
8686
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
9173
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
8882
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
7748
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
6533
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
5872
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
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
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
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.