| | |
Code Confusion
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
ok, after i got thelp with keypresses it is time to go one step further. i am ,making a very simple hangman game. the user will guess letters like you mormally do in hangman. what i want to be able to do is if he cant remember what he has guessed he can press a button. with that presss of the buttion all the letters/ keys that were captured would show up in a text box. but they would only show up when he pressed them.
i dont know if this is possible so any help would be great
Tayspen
i dont know if this is possible so any help would be great
Tayspen
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
couple of different ways you can handle it
I would probably do something like the following.
When the game starts instantiate a string called lettersUsed to be an empty string
then, when someone hits a letter, add it to the string if it isn't already there. (adding to the code from your previous post)
then when they hit space
I would probably do something like the following.
When the game starts instantiate a string called lettersUsed to be an empty string
C# Syntax (Toggle Plain Text)
string lettersUsed = "";
then, when someone hits a letter, add it to the string if it isn't already there. (adding to the code from your previous post)
C# Syntax (Toggle Plain Text)
case(Keys.A): if(lettersUsed.IndexOf("a") = -1) lettersUsed+= "a"; break;
then when they hit space
C# Syntax (Toggle Plain Text)
case(Keys.Space): MessageBox.Show("Letters used: " + lettersUsed); break;
heres that part of it keep in mind im new 
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
string keyData = "";
public Form1()
{
InitializeComponent();
string keyData = "";
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
bool result = false;
switch (keyData)
{
case(Keys.A):
if(lettersUsed.IndexOf("a") = -1) lettersUsed+= "a";
break;
case(Keys.Space):
MessageBox.Show("Letters used: " + lettersUsed);
break;
break;
}
return result;
}
[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);
}
}

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
string keyData = "";
public Form1()
{
InitializeComponent();
string keyData = "";
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
bool result = false;
switch (keyData)
{
case(Keys.A):
if(lettersUsed.IndexOf("a") = -1) lettersUsed+= "a";
break;
case(Keys.Space):
MessageBox.Show("Letters used: " + lettersUsed);
break;
break;
}
return result;
}
[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);
}
}
here it is closer i think
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form{
string lettersUsed = "";
public Form1()
{
InitializeComponent();
}
protected override bool ProcessCmdKey(ref Message msg, Keys lettersUsed)
{
bool result = false;
switch (lettersUsed)
{
case(Keys.A):
if(lettersUsed.IndexOf("a") = -1) lettersUsed+= "a";
break;
case(Keys.Space):
MessageBox.Show("Letters used: " + lettersUsed);
break;
break;
}
return result;
}
[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);
}
}
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form{
string lettersUsed = "";
public Form1()
{
InitializeComponent();
}
protected override bool ProcessCmdKey(ref Message msg, Keys lettersUsed)
{
bool result = false;
switch (lettersUsed)
{
case(Keys.A):
if(lettersUsed.IndexOf("a") = -1) lettersUsed+= "a";
break;
case(Keys.Space):
MessageBox.Show("Letters used: " + lettersUsed);
break;
break;
}
return result;
}
[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);
}
}
![]() |
Similar Threads
Other Threads in the C# Forum
- Previous Thread: sending email
- Next Thread: Possible???
Views: 4281 | Replies: 16
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast button buttons c# chat check checkbox class client combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking operator oracle path photoshop picturebox pixelinversion prime programming radians regex remote remoting resource richtextbox save saving serialization server socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






