Windows Develop Bookmark and Share   
 index > Windows Forms General > Help with migration from VB to C# (re: form controls)
 

Help with migration from VB to C# (re: form controls)

Hello,

I'm still making the migration from VB to C# (finally!).

As you may know, VB considers a Form to be an Object. Thus, you can reference any Control on the Form, using the Object. This, of course, exposes those controls to almost anywhere Sad

Could someone provide a link or otherwise code-snippet, to explain how I send text to a Control on a C# Form, from another Class?

Here is what I'd like to do:

1. ListBox Control on a Form

2. Class called "Mathematics"

3. This Class has a function called "CalculatePI()" which calculates PI and also has debug messages along the way.

4. Send the value of PI and the messages to the ListBox Control on the Form.

Thank you for any help!

Sincerely,

Chris.

chris_dev  Wednesday, April 11, 2007 4:57 PM

Suppose you have a form FormCalculator.

1) add a function to that form say: AddPIToListBox

public AddPIToListBox(float pi)

{

this.listBoxPis.Items.Add(pi);

}

2) now you want to add Pi to the ListBox on that form, you can simply create that form, showit and call that function from your Mathematics class to pass that pi value as a parameter to that function and it'll be displayed in there.

If the form is already opened and you want to add pi to existing form you should have reference to that form and use that reference to call that function and add pi value in there.

FormCalculator formCalc = new Form();

formCalc.Show();

formCalc.AddPIToListBox(piValueHere);

All you need is to save formCalc object somewhere to access it from different blocks of your code.

Thats' it.

I hope this will help.

Best regards,

Rizwan aka RizwanSharp

RizwanSharp  Wednesday, April 11, 2007 5:26 PM

Suppose you have a form FormCalculator.

1) add a function to that form say: AddPIToListBox

public AddPIToListBox(float pi)

{

this.listBoxPis.Items.Add(pi);

}

2) now you want to add Pi to the ListBox on that form, you can simply create that form, showit and call that function from your Mathematics class to pass that pi value as a parameter to that function and it'll be displayed in there.

If the form is already opened and you want to add pi to existing form you should have reference to that form and use that reference to call that function and add pi value in there.

FormCalculator formCalc = new Form();

formCalc.Show();

formCalc.AddPIToListBox(piValueHere);

All you need is to save formCalc object somewhere to access it from different blocks of your code.

Thats' it.

I hope this will help.

Best regards,

Rizwan aka RizwanSharp

RizwanSharp  Wednesday, April 11, 2007 5:26 PM

Cool. Thanks Smile Using your reply, I can pass the Function() return value, and then display it in the ListBox.

Question: What about simple messages?

For example (removing all actual mathematical calculations):

Code Snippet

public class Mathematics

{

public void CalculatePI()

{

Console.WriteLine("inside the class function.....");

Console.WriteLine("ready to calculate PI");

}

}

I could use MessageBox.Show("text");...but that can get tedious if there are LOTS of debug messages!!!

How would I send those messages to the Form's ListBox control?

I've done this, and it's close, "but no cigar"!---> using TheFormNamespace;

Thanks for any help!

Chris.

chris_dev  Wednesday, April 11, 2007 7:38 PM

You can use google to search for other answers

Custom Search

More Threads

• Changing Color of Single DataColumn in DataGrid
• ErrorProvider doesn't display icon for one control (desperate!)
• Problem uploading image to Access dB and SQL 2000 dB
• Treeview in FW and Compact FW
• How to convert datagridview cell to combobox
• Persisting Graphics Problem
• To disable the first radio button selection.
• MenuStrip with RenderMode=System in Windows 2000
• C# Window label Text
• Disable the stop button in an media player component