Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi my name is vishal. For past 2 days i have been breaking my head on why am not getting created control array name of winsock control in properties windows or form properties window in c# windows forms.
So i have a winsock control in my form named:axWinsock1
I have created a winsock control array named:mySockets[] for for axWinsock1.Given below is the code:
C#
namespace DRRS_Socket_Application
{
    public partial class Form1 : Form
    {
        private AxMSWinsockLib.AxWinsock[] mySockets = new AxMSWinsockLib.AxWinsock[20];
 Socket sck;
public Form1()
        {
            InitializeComponent();
            sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); 
        }
private void Form1_Load(object sender, EventArgs e)
        {
            int x;
            for (x = 0; x < 20; x++)
            {
                mySockets[x] = new AxMSWinsockLib.AxWinsock();
                ((System.ComponentModel.ISupportInitialize)(this.axWinsock1)).BeginInit();
                mySockets[x].Enabled = true;
          }
            StartListen();
        }
private void StartListen()
        {
            sckServer.Close();
            sckServer.LocalPort = 25000;
            sckServer.Listen();  
        }

I able to create control of winsock control named:mySockets for winsock control named:axWinsock1. But the problem i am facing is once i click the combobox or drop-down combobox of properties window of form i am still getting axWinsock1.AxMsWinsockLib.AxWinsock. But instead i should get mySockets[0].AxMsWinsockLib.AxWinsock in my properties windows of my form.

Can anyone what should i do in my code in c# to get the required result? Can anyone help me please? Can anyone help me/guide me to solve my problem.? Any help/guidance in solving of this problem would be greatly appreciated! Thanks in advance.
Posted

1 solution

You can't.
A control doesn't know where it is stored. Think about this:
C#
MyClass mc1;
MyClass mc2;
MyClass[] array = new MyClass[10];
mc1 = new MyClass();
mc2 = mc1;
for (int i = 0; i < 10; i++)
   {
   array[i] = mc1;
   }
If the one and only instance of MyClass could know where it is stored, what value should it return?
mc1?
mc2?
array[0]?
...
array[9]?
And think even further: to "know" where it is stored, it would have to keep a reference to the "location" which means that the garbage collector could not dispose of the location (because it is being referenced by the instance) or of the instance (because it is being referred to by the location). So nothing could ever be disposed, and memory use would just increase until it ran out...

I don't know why you want to do this: but I think you need to reconsider what exactly you need this for!
 
Share this answer
 
Comments
Member 10248768 4-Jul-14 6:35am    
Well Mr.OriginalGriff
Thank you for replying to my query on such short notice. But in vb6 we can create a control array of winsock control for a/that winsock control using index property of that winsock control. Can we repeat the same here? If so can you show me a sample?! Reply please? I am waiting for your reply Sir.
OriginalGriff 4-Jul-14 6:43am    
No.
C# is not VB.
Thankfully, C# does not have control arrays, or any of VB's other silliness's.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900