Need some help in my first Win Form application.
A key click event handler works fine internally as a private method.
Unfortunately I don't know how I can extract the information out of the private event handler.
I need the 'keynum' paramater outside the method.
A return parameter is not accepted in the event handler (The relevant hidden delegate is set void?)
The error is: byte WindowsFormsApplication4.Form1.Key_Click(object, System.EventArgs)' has the wrong return type
Sam
C# |

Roei BarRank #1,271 · 1.4K reputationPosted Sep 12, 2009, 11:41 AM EDT
Sam159 reputationPosted Sep 13, 2009, 1:00 AM EDT
How?
The automatic C# event handler is Private, void.
Thanks
Sam
Roei BarRank #1,271 · 1.4K reputationPosted Sep 13, 2009, 6:28 AM EDT
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { byte keynum = null; public Form1() { InitializeComponent(); } private void Key_Click(object sender, EventArgs e) { Button currentkey = (Button)sender; //remove the word 'Key' from the name like from 'Key05' string currentKey = currentkey.Name.Remove(0, 3); this.keynum = Convert.ToByte(currentKey); textBox1.Text = Convert.ToString(keynum); } } }hope this helps
Sam159 reputationPosted Sep 15, 2009, 5:26 AM EDT
I did as you suggested and it works now (after making the field private and adding getter and setter properties).
Another question:
I have a small rich textbox printing method in my Form1 class. When I call it from another class with a parameter, it prints null.
The reason I found to be the initialization of the text box each time I call its class.
(When i do the same printing from within Form1 it work perfect).
What am I doing wrong?
Thanks.