chuawenching Posted July 27, 2003 Posted July 27, 2003 Hi there. I was migrating to c# from vb6.. and now i am headache. In vb6, i can store arrays for buttons like: button1(0) button1(1) but i can't do this in c#... and now in vb6 there is: button1(0).Value = true/false how to code that in c#? Any help please? Thanks. Regards, Chua Wen Ching :p Quote
*Experts* mutant Posted July 27, 2003 *Experts* Posted July 27, 2003 You can create an array of buttons in code, control arrays are not supported in the designer: Button[] buttons = new Button[2]; buttons[0] = new Button(); buttons[1] = new Button(); buttons[0].Location = new Point(0,0); buttons[1].Location = new Point(200,200); this.Controls.AddRange(buttons); This is just an example, it creates an array of buttons, initializes them and adds to the form. Quote
chuawenching Posted July 27, 2003 Author Posted July 27, 2003 Oh but that does not really answer my question... can i set button[0].value = true But thanks for the tips... Regards, Chua Wen Ching :p Quote
*Experts* mutant Posted July 27, 2003 *Experts* Posted July 27, 2003 Yes you can do that with the example I showed you. Quote
chuawenching Posted July 27, 2003 Author Posted July 27, 2003 Nope i try already... i can't find value in button[0]. (the intellisense don't show value) How do you manage to do that? Any help? Thanks. Regards, Chua Wen Ching :p Quote
*Experts* jfackler Posted July 27, 2003 *Experts* Posted July 27, 2003 The button control in .net (at least vb I assume c as well) has no value property. Are you referring to a radiobutton? Quote
chuawenching Posted July 27, 2003 Author Posted July 27, 2003 nono! In vb6 there is .value, that is why i ask here, is there a value for a button in c#. Bcs i can't find one! if there no value property (true/false) for button in c#, any idea how to do it? Thanks. Regards, Chua Wen CHing :p Quote
JABE Posted July 27, 2003 Posted July 27, 2003 If I remember correctly, button.value = True in VB6 is in effect calling the click sub for the button or the Button1_Click sub, assuming that the button is named Button1. In .NET (C# as well as VB.NET), this has no equivalent but you can invoke the sub directly via code just like any other procedure. Quote
*Experts* mutant Posted July 27, 2003 *Experts* Posted July 27, 2003 Oh, you were referring to one property. I thought you meant overall referring to any value of the button. Quote
chuawenching Posted July 27, 2003 Author Posted July 27, 2003 but you can invoke the sub directly via code just like any other procedure. --> maybe you can explain to me a bit clearer... not really understand what you meant! Can you show me how it can be done in vs.net ? Thanks. Regards, Chua Wen Ching :p Quote
JABE Posted July 29, 2003 Posted July 29, 2003 Given button1, you can hook up to its click event via: [C#] this.button1.Click += new System.EventHandler(this.button1_Click); [/C#] But you can also directly invoke button1_Click just like any other procedure. From button2_Click, for example, you can do: this.button1_Click(button1, e); But I think I've realized where you're heading. Given a button object, you'd want to know how to invoke its Click delegate w/o knowing exactly the name of the sub. It's interesting but unfortunately, I don't have the answer to that now. Will get back to you when I do but in the meantime, I hope the experts of this forum can help you on your problem, if it's really possible in the first place. Quote
chuawenching Posted July 29, 2003 Author Posted July 29, 2003 Thanks for the reply. Regards, Chua Wen Ching :p Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.