473,396 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

c#:Doubt in eventhandler?

40
hi all

i have two forms FORM1 and FORM2.and form1 has two buttons.

when buttons B1,B2 is clicked in FORM1, FORM2 should appear,
but i need to trace which button is clicked .so that i want to display dfferent controls in FORM2 accordin to button click.

Any body give some tips

I am trying to trace the "event e" in the FORM2 's load event.

pls help
Dec 19 '07 #1
6 1312
debasisdas
8,127 Expert 4TB
Simply you can declare a flag variable and set the flag to different values .
ie
1 for button1
2 for button2

you need to compare the value and display the group of controls accordingly in the target form.
Dec 19 '07 #2
Torgg
41
Here is how I would handle this.

On Form1 in button1_Click put the following

Expand|Select|Wrap|Line Numbers
  1.  Form2 frm2 = new Form2();
  2.  
  3. frm2.iMode = 1;
  4. frm2.Show();
In button2_Click put the following

Expand|Select|Wrap|Line Numbers
  1.            Form2 frm2 = new Form2();
  2.  
  3. frm2.iMode = 2;
  4. frm2.Show();
In Form2 put the following
Expand|Select|Wrap|Line Numbers
  1.     public partial class Form2 : Form
  2.     {
  3.         public int iMode = 0;
  4.         public Form2()
  5.         {
  6.             InitializeComponent();
  7.         }
  8.  
  9.         private void Form2_Load(object sender, EventArgs e)
  10.         {
  11.         if (iMode == 0)
  12.             {
  13.                 //No value was passed... don't show the form
  14.                 MessageBox.Show("Mode value not set");
  15.                 this.Close();
  16.             }
  17.             else if (iMode == 1)
  18.             {
  19.                 //Show some controls
  20.             }
  21.             else if (iMode == 2)
  22.             {
  23.                 //Show some other controls
  24.             }      
  25.        }
  26.     }
All your doing is setting the iMode value for Form2 depending on which button is pushed. So, if button1 is pushed then the iMode is set to 1 and if button2 is pushed then iMode is set to 2 and if iMode is not set then its defaults to 0 and Form2 will not show. I hope this helps

Torgg
Dec 19 '07 #3
Frinavale
9,735 Expert Mod 8TB
Here is how I would handle this.
...
All your doing is setting the iMode value for Form2 depending on which button is pushed. So, if button1 is pushed then the iMode is set to 1 and if button2 is pushed then iMode is set to 2 and if iMode is not set then its defaults to 0 and Form2 will not show. I hope this helps

Torgg
That's a great example Torgg.
Thanks a lot!

I just wanted to add to Torgg's recommendation by reminding you that you have the Object sender, and EventArgs e variables at your disposal to. You can use the Object sender parameter to determine what object triggered the event.

-Frinny
Dec 19 '07 #4
Torgg
41
That's a great example Torgg.
Thanks a lot!

I just wanted to add to Torgg's recommendation by reminding you that you have the Object sender, and EventArgs e variables at your disposal to. You can use the Object sender parameter to determine what object triggered the event.

-Frinny
Frinny
Could you give me an example of what you mean? Maybe based on the sample above.

Torgg
Dec 19 '07 #5
r035198x
13,262 8TB
This strikes me more as a job for the constructor to me than a job for the Form load event.
Just pass a different parameter to the constructor of Form2 depending on which button was clicked in Form1.
Dec 19 '07 #6
ssknov
40
i am trying

thank u very much torgg
Dec 20 '07 #7

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

Similar topics

2
by: Sandor Heese | last post by:
Question, When using BeginInvoke (on a From to marshal to the UI thread) with the EventHandler delegate I see some strange behaviour. The problem is that I call the UpdateTextBox method with a...
3
by: Remco | last post by:
Hello, Serverside I'm generating a html page. There are different controls for which I want to create an eventhandler manually. Like: document.forms.TextBox1.onchange = EventHandler;...
0
by: dominosly | last post by:
Okay, this is a rather complicated problem, so here is the short of it: I am using a custom designed user control that simply writes out a plain old html submit button to the page. When the...
12
by: aplaxas | last post by:
Hi! "CDemo.Call" eventHandler is added to "button3.click" Event when both button1 and button2 are clicked. However, I want to add "cd.Call" only one time even though I clicked both button1 and...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
9
by: Christopher Weaver | last post by:
Can anyone tell me how I could iterate through a collection of controls on a form while assigning their event handlers to another identical collection of controls on the same form. So far,...
13
by: jac | last post by:
Hae, I have a windows form with a ComboBox an other things. On that combobox I have an eventhandler on de selectedindexchanged. But somewhere in my code want to do excecute the same code that...
2
by: mawi | last post by:
Hi there, When removing page children controls created dynamically not in last-to-first order, the close button of the last control looses its event wiring, even though the handler is rewired...
2
cornfed
by: cornfed | last post by:
I've got a class to make Templates for different repeaters in my page. in one of these repeaters a linkbutton is needed. This LinkButton needs an event that is in a .cs file somewhere else in the...
1
by: rubrish | last post by:
HI all I am writing a code for creating a cell with numbers one to nine three in a row is there any problem with the following code? using System; using...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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...

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.