|
Hi
I am trying to pass data back and forth windows forms but I am having trouble. What I am trying to do is this:
I have a mainForm that has 2 textboxes called plainText and ChiperText. This main form also has a menu bar of different algo to choose from(for instance shift Chiper).
When shift chiper is clicke id launched a new form(shiftchiper.cs). It has some options and it also have a toolbar with Encrypt and decrypt.
When encrypt is hit I want to take the data from mainForm PlainText textbox and encrypt it. Once encrypted send it back to the mainForms chiperText box.
If they hit decrypt it's the same thing just reversed.
By using this tutorial( I used the property way)
http://www.codeproject.com/KB/cs/pass_data_between_forms.aspx
I been able to send the PlainText data to the shiftChiper form and encrypt it. What I can't do is send the new encrypted data back to the ChiperText textbox in the mainForm.
So anyone know how to do this?
I simple example would be nice. It can be just 2 textboxes on one form and a button. when the button is clicked a form2 is made and it sends over one of the textboxes. One form2 it can have a button when clicked it sends the data that was sent back to form1.
I am doing it in C# by the way.
|
|
|
|
|
I think I know what you're talking about. let me see if I can help.
Anything in public access space on the popup can be accessed by the main form from wherever the instance of the popup is.
For example. on my main form named form1 I have a button that opens a popup named form2. in the button click event on form1's button I'd have something to the effect of
PopupFormTypenameGoesHere form2 = new PopupFormTypenameGoesHere( params to send et all)
form2.ShowDialogue();
Text = form2.someInfo;
and in form2's close event I'd have
someInfo = "hello world"; // or whatever
This would cause form1's title (ie it's Text property) to be set to "hello world" after the popup had closed (or whatever someInfo was set to in that form)
I hope that helps.
One thing you should be careful with is the usage of Show() and ShowDialogue() - they are NOT interchangeable.
-Gatsby
|
|
|
|
|
do you need to use 2 forms? is there a critical reason? i don´t see it.
i use (1) parent form/child form method or (2) the form + userforms (loaded in form) method
but i don´t see how you can get it to work, i assume you did the same in both forms. i think it´s because the first owes the second. Are you using delegates?
check articles here on those methods, you won´t get errors and look nicer
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Envents and/or delegates are the answer.
I posted a delegate sample here[^] previously.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Hi,
I am trying to use DGVComboBoxColumn. I googled but didn't find any solution for below issue.
When I click on the DropDown it shows me DisplayMember i.e State name but after selecting one of them when I click somewhere outside, it displays ValueMember i.e Id of the state.
Please can anyone help me? Below is the code to load the State in DGVComboBox.
void LoadState()
{
try
{
dtState = GetState();
dgvCmbState.DataSource = dtState;
dgvCmbState.ValueMember = "Id";
dgvCmbState.DisplayMember = "sName";
}
catch (Exception ex)
{
}
}
Thanks
|
|
|
|
|
Hi there.
How can we find WindowState changes?
Is there an event for that ?
Thanks in advance.
|
|
|
|
|
Depends on what window state change notifications you need.
The Form class from the System.Windows.Forms namespace has some very common ones, like:
- Shown
- StyleChanged
- SizeChanged
- ResizeBegin
- ResizeEnd
- VisibleChanged
and some more. If you need to capture all changes, then you could derive your own Form from Form and handle the underlying WinAPI WM_ messages yourself.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you Greeeg.
Greeeg wrote: Depends on what window state change notifications you need.
Minimize, Maximize, Normal
These were my purpose.
|
|
|
|
|
This[^] should help you
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
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)[^]
|
|
|
|