473,395 Members | 2,010 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,395 software developers and data experts.

c# how do i open a window on doubleclick once it's closed?

12
Hi,

I'm so new at this so my question might sound a bit odd.
Alright, I'm trying to write a chat program that'll only work amongst the workers within the same company and network as msn and such messangers are prohibited.

I have made this form where you have nicknames. And I have written the command for preventing a window to be opened more than once when you doubleclick on it. But the problem is, when i close the popped query, and try opening it again with doubleclick it just does nothing. how do i solve that?PS: Sorry for my english.

Expand|Select|Wrap|Line Numbers
  1. ListViewItem SecilenKisi;
  2.  
  3.         private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  4.         {
  5.             SecilenKisi = e.Item;
  6.  
  7.         }
  8.         ArrayList nameList = new ArrayList();
  9.  
  10.         private void listView1_DoubleClick(object sender, EventArgs e)
  11.         {
  12.  
  13.             bool bulundu = false;
  14.  
  15.                 if(!bulundu)
  16.                 {
  17.                     foreach (String names in nameList)
  18.                     {
  19.                         if (nameList.Contains(SecilenKisi.Text))
  20.                         {
  21.                             bulundu = true;
  22.                             break;
  23.                         }
  24.                     }
  25.                     if (bulundu == false)
  26.                     {
  27.                         Form2 frm = new Form2();
  28.                         frm.Show();
  29.                         frm.textBox1.Text = SecilenKisi.Text;
  30.                         nameList.Add(SecilenKisi.Text);
  31.                     }
  32.  
That's what I've done so far... SecilenKisi indicates the person choosed and bulundu means found
Jun 3 '10 #1
3 1468
GaryTexmo
1,501 Expert 1GB
Well, the way your code reads is that if nameList contains SecilenKisi.Text then bulundu gets set to true. Then, when bulundu is true, the form won't show. The behaviour you describe actually seems pretty expected. On the first run nameList is empty so bulundu stays false. Since it is false, the form shows and adds SecilenKisi.Text to nameList. The next time this is clicked, nameList contains SecilenKisi.Text (assuming that doesn't change) and thus the form doesn't open.

A little debugging and the above seems pretty clear. I realize you're new so hopefully that process I described helps you in the future. Something that also helps is setting breakpoints, or even putting Console.WriteLine commands in to let you know what's running and the values of certain flags/variables. When you're working on something, it's pretty easy to miss things like this 'cause you've been staring at it for so long, so it's also good to just step back from it and give yourself a break. When you come back to it, you might see things from a different angle ;)

As for what you're trying to do, if you want to prevent a window from being opened more than once perhaps just have a variable at the class level called nickFormOpen (or something like that). Set it to true when you open the form, and have that form's closing event set it to false. Then only open it if the flag specifies that the form is closed. A quick example...

Expand|Select|Wrap|Line Numbers
  1. private bool m_formOpen = false;
  2. private void SomeEvent(...)
  3. {
  4.   SubForm newForm = new Form();
  5.   newForm.Closing += new EventHandler(SubFormClosingEvent);
  6.   newForm.Show();
  7.   m_formOpen = true;
  8. }
  9.  
  10. private void SubFormClosingEvent(...)
  11. {
  12.   m_formOpen = false;
  13. }
There are other ways to solve this of course, that's only one way (though not as elegant as other solutions :D). Think about what works best for you.

Lastly, and this is more just a helpful tip, but you've got the following in your code...

Expand|Select|Wrap|Line Numbers
  1. bool someFlag = false;
  2. if (someFlag == false)
  3. {
  4.   ...
  5. }
There isn't any reason for this if to be there. In fact, if you have compile time optimization turned on, it might even be removed for you by the compiler. Not a big deal, but I thought I'd point it out.
Jun 3 '10 #2
Plater
7,872 Expert 4TB
I would attached an event handler to the frm object to fire when the frm is closed, then you can deal with the bulundu value
Jun 3 '10 #3
xinnie
12
Okay thanks guys, I've managed to get it done. For further questions I might show up here :) Thank you for sparing your time.
Jun 4 '10 #4

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

Similar topics

1
by: Guy | last post by:
I have 4 images on a page and when someone clicks on one of them I open a secondary window and write a few lines to it describing the image. If they don't close that secondary window however, and...
4
by: Anna Quick | last post by:
I am quite new to javascript, and don't seem to find the problem with stupid internet explorer. The script works fine in safari and mozilla. I searched the groups, but evidently put in the wrong...
10
by: Marshall Dudley | last post by:
When I do the following line in Netscape, the popup loads as it should, but the parent window usually, but not always, reloads as well. <a href="#"...
3
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The...
4
by: vagos | last post by:
Hi, When opening a page, i want to open a new javascript window and close the first. like: <script language=javascript> function openw(){...
29
by: wayne | last post by:
Hey there... I'm having some problems passing url parameters with an open.window command. I'm not terribly familiar with java script but here is the code below. When executed it opens the...
0
by: Daniel | last post by:
is there any way to clear the buffer of a System.IO.StreamWriter so that it does not do a flush when it is closed in the finaly block?
3
by: stumorgan | last post by:
There is probably an extremely simple answer to this question and I'm just being foolish. I have a main form (let's say FormMain) which opens other forms (let's say Form1, Form2). How do I keep...
4
by: Csaba Gabor | last post by:
Up until a few weeks ago, javascript code like window.open("http://mydomain.com", "windowName"); would always bring my new or reused window to the top, with focus. Lately, Firefox (Deer park...
1
by: TPK | last post by:
Here is what I want to do with javascript. On a page with text place a javascript link that: 1) When a user clicks the link (onClick) a new browser window opens (the easy part) NewWindow =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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.