|
|
On my windows form, upon clicking on a form i add a button where ever the mouse was clicked. But how
can i know if a "ESC" key is press so i cancel the add button on a form.
|
|
|
|
|
One quick solution would probably something like:
1) on first mouse click, create the button and set its type to something like "floating"
2) while floating, let the button follow the mouse cursor (mouse move event)
3a) if the user presses the mouse button again, then set the button to a fixed position on the form and remove the "floating" property
3b) if the user presses the escape key (KeyPress/KeyUp-event) while the new button is in "floating" mode, remove it from the list of controls entirely.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
class playingcard
{
enum Cards
{
Two = 1,
Three = 2,
Four = 3,
Five = 4,
Six = 5,
Seven = 6,
Eight = 7,
Nine = 8,
Ten = 9,
Jack = 10,
Queen = 10,
King = 10,
Ace = 11,
}
static void Main(string[] args)
{
string[] card = new string[] { "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Jack ", "Queen ", " King", "Ace " };
string[] cardSuits = { " Spades", " Heart", " Club", " Diamond" };
Random random = new Random();
string Randomcard = card[random.Next(0, card.Length)];
string RandomcardSuits = cardSuits[random.Next(0, cardSuits.Length)];
string selectedcard = String.Concat(Randomcard, "of", RandomcardSuits);
Console.WriteLine(selectedcard);
int[] vals = (int[])Enum.GetValues(typeof(Cards));
Console.WriteLine("your points are:{0}",vals[0]);
Console.ReadLine();
}
}
i need help to get the point i am done with random selection of suits and cards now i want to print the point of randomly selected card that values are stored in array int[] vals but i dont know how to display that specific value that is randomly selected please help me with this thank you
|
|
|
|
|
Member 3958312 wrote: i need help to get the point i am done with random selection of suits and cards now i want to print the point of randomly selected card that values are stored in array int[] vals but i dont know how to display that specific value that is randomly selected please help me with this thank you
If you use punctiation when you write, it gets very much easier to understand what it is that you are trying to say.
To get the card value, you have to use the index of the card that you have picked. You have to store that value in a variable before using it to get the value from the card array, so that you can use it to get a value from the cardValues array also.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
can u please help me with coding?
thats where i am stuck
|
|
|
|
|
Member 3958312 wrote: please help me with this thank you
This is just wrong all over.
First off, selecting a random rank (string[] card) and a random suit (string[] cardSuits) to create a card is a bad idea. What if you pick the same card twice in one hand? How will you remove cards from a "deck" as they are dealt. You better rethink your object design.
Second, your cardvalues array is wrong. For example, let's say your random number for the card rank is "0" (which, by the way, you don't save anywhere). You have string card[0] == "Two " but int cardvalues[0] = 1 . That's wrong.
I'm not saying this is the best design, but start with something like:
cardID = random.Next(0,52);
cardSuit = cardID / 13;
cardRank = cardID % 13;
blackjackValue = cardValues[cardRank];
|
|
|
|
|
ok that is very unlucky
how to implement above idea i need a little extra detail to work on it
ty
|
|
|
|
|
Hi All,
I am trying to create a table but getting following complie time error:
Error: 'Table' does not contain a definition for 'BorderStyle'
can anyone help please.
Here are my code for review:
Table tbl = new Table();
tbl.BorderStyle = BorderStyle.Solid; //Error at this line
tbl.BorderColor = Color.Black;
tbl.CellSpacing = 0;
Thanks,
A.Asif
A.Asif
|
|
|
|
|
The System.Web.UI.WebControls.Table class has a BorderStyle property, so that's obviously not the class that you created. Is that the class that you intended to create?
Is it a WPF project? Then you use BorderBrush and BorderThickness to specify the border.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
Thanks for your help. However, I am using System.Web.UI.WebControls.Table class that has a BorderStyle property, so obviously I should NOT get this error, but for some reason I am geting this error. Also this not a WPF project. Any idea what could be wrong, I am using VS 2005. Please help if you can.
Thanks
A.Asif
|
|
|
|
|
Well, since you just specified "Table" and not "System.Web.UI.WebControls.Table" explicitly, you're using a Table class from a different namespace. That's why yo're getting this message. Change the code to be specific and you won't see this error.
|
|
|
|
|
Hello,
I no really nothing about unicode. So I am trying to convert a string that starts out in English and convert it to Japanese. This is what I am doing, but I have no idea what to do and nothing is coming out as Japanese. I tried looking on the internet and the best thing I found was this. http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx
But I still can't get it to convert the string. This is what I have for code written so far. Please help. I would expect "This is a Test" to convert to Japanese but it does not.
string TestString = "This is a Test";
Encoding ascii = Encoding.GetEncoding(932);
Encoding japanese = Encoding.GetEncoding(20127);
byte[] unicodeBytes = ascii.GetBytes(TestString);
byte[] JapaneseBytes = Encoding.Convert(ascii, japanese, unicodeBytes);
char[] JapaneseChars = new char[japanese.GetCharCount(JapaneseBytes, 0, JapaneseBytes.Length)];
japanese.GetChars(JapaneseBytes, 0, JapaneseBytes.Length, JapaneseChars, 0);
string JapaneseString = new string(JapaneseChars);
string test = System.Text.Encoding.GetEncoding(932).GetString(JapaneseBytes);
I just tried this and the string is still in English. I am just looking at the string in the debugger to see what it looks like and it is still english.....
modified on Friday, September 12, 2008 1:45 PM
|
|
|
|
|
Are you trying to translate the text in the string? There is no conversion or encoding that can do that for you.
A proper translation can only be done by a human. There are some pages on the web where you can get an automatic translation, that is at least usable.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Well, what I am trying to do is say, a person types in an 'a', I can then take that letter and translate it to the Japanese representation of 'a' or what the japanese representation of the key pressed on the keyboard for for 'a' which I think is key 65.
|
|
|
|
|
I don't know alot about Japanese, but I don't think the Japanese alphabet can be compared to the Latin (our) alphabet. Japanese and Chinese characters are syllables, no letters. I also think the Japanese alphabet has alot more characters than ours.
Edit: People that want to see Japanese characters will need the East-Asian characters to be enabled with their OS. Check this Wikipedia page for more information how to do this (not too hard).
http://en.wikipedia.org/wiki/Help:Multilingual_support_(East_Asian)[^]
|
|
|
|
|
So there is no way to convert a single key press to the Japanese representation of that key press?
|
|
|
|
|
No, because there is no relationship between the two languages. Any translation of a letter in English language is an approximation of the CONCEPT of 'a' in Japanese. For instance, there may not be anything like an 'a' key, or whatever key you hit, on a Japanese keyboard. One character can represent a word, like "Song", and may even represent an entire paragraph in English.
Last I heard, in Japanese Kanji, there were over 4,000 characters!
|
|
|
|
|
SRogers88 wrote: I no really nothing about unicode.
I would suggest reading this article[^] for a good introduction.
|
|
|
|
|
Hi,
i can use this code to change the ownership of a directory
*********************************************
DirectoryInfo dInfo = new DirectoryInfo(folderPath);
DirectorySecurity oDirectorySecurity = new DirectorySecurity();
NTAccount owner = new NTAccount("Administrators");
oDirectorySecurity.SetOwner(owner);
dInfo.SetAccessControl(oDirectorySecurity);
*********************************************
but does anyone know how to make this recursive, so it changes the owner of all the sub files and folders?
Many Thanks,
Phil
|
|
|
|
|
use Directory.GetDirectories and Directory.GetFiles instead
and do it recursively
hope it help
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
great, thanks.
works a treat.
|
|
|
|
|
Is there a way to specify a class inherited from a generic list object to serialize its children with a specific tag name? For instance, I want:
[Serializable(), XmlRoot("Products")]
public class ProductList : List<Product>
to output as
<Products>
<Content>
</Content>
</Products>
not as
<Products>
<Product>
</Product>
</Products>
It seems I can only use the XmlArrayItem attribute on fields/properties/etc, not on classes. Placing an XmlRoot tag on the Product class doesn't get me the results I want either. Thanks in advance!
modified on Friday, September 12, 2008 12:52 PM
|
|
|
|
|
Works for me....
[Serializable(), XmlRoot("Products")]
public class ProductList : System.Collections.Generic.List<Product>
{
public ProductList()
{
}
public void Load()
{
this.Add(new Product("111"));
this.Add(new Product("222"));
this.Add(new Product("333"));
}
}
public class Product
{
public string Name;
public string Test;
public Product()
{
}
public Product(string val)
{
Name = val;
Test = "Default " + val;
}
}
I do this in the test app:
ProductList p = new ProductList();
p.Load();
..and then serialize and get this....
<?xml version="1.0" encoding="utf-8"?>
<Products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Product>
<Name>111</Name>
<Test>Default 111</Test>
</Product>
<Product>
<Name>222</Name>
<Test>Default 222</Test>
</Product>
<Product>
<Name>333</Name>
<Test>Default 333</Test>
</Product>
</Products>
Erik Westermann - wWorkflow.net - BizTalk Consulting Services
SOA * ESB * BPI * SaaS ... forget the alphabet soup - get the main course with our consulting services!
wWorkflow.net or +1 416-809-1453
|
|
|
|
|
IM working on a small C# program to backup My Access database automatically and woould like to add a few bells and whistles. Id like to be able to open the selected database from the program in exclusive and non-exclusive mode. Ive read the articl on SMSDN about Access automation as well as others but still have a problem.
using Access = Microsoft.Office.Interop.Access;
.......
private void btnOpenCurrDB_Click(object sender, EventArgs e)
{
Access.Application oAccess = new Access.ApplicationClass();
if (cbExclMode.Checked == true)
{
oAccess.OpenCurrentDatabase(@"C:\FTTH.mdb", true,null);
}
else
{
oAccess.OpenCurrentDatabase(@"C:\FTTH.mdb", false,null);
}
}
When I run the program, and click on the OpenCurrDB button I get 'InvalidCastException was unhandled'
Unable to cast COM object of type 'Microsoft.Office.Interop.Access.ApplicationClass' to interface type 'Microsoft.Office.Interop.Access._ApplicationClass'. The exception cmoes in either of the two oAccess.OpenCurrentDatabase lines depending on whether or not I have the exclusive checkbox checked.
Im a novice programmer, the rest of my program works fine, I just cant seem to get my hand on this part.
|
|
|
|
|