Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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.

Posted

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

Posted
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.
Posted

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...