如何在c#windows窗体中创建winsock控件的控件数组 [英] how to create control array of winsock control in c# windows forms

查看:729
本文介绍了如何在c#windows窗体中创建winsock控件的控件数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我的名字已经过去1周了,我一直在研究如何在c#windows窗体中创建控制阵列的winsock控件方面没什么成功。



我能够通过工具箱 - >选择项目 - > COM组件 - >在c#windows窗体中将winsock控件带到我的工具箱中。 Microsoft Winsock Control,版本6.0。

我在做客户端服务器程序,我必须仅为此目的使用Winsock控件,因为它是我的 BOSS 订单。



现在我正在从 vb6 过渡到 C# windows窗体。在下面给出的 vb6 vb6 控制阵列 winsock 控件的代码,我能够轻松创建和操作在 vb6

Hi my name is vishal for past 1 week i have been doing some research and with little success on how to create control array of winsock control in c# windows forms.

I was able to bring winsock control to my toolbox in c# windows forms through toolbox->choose items->COM Components-> Microsoft Winsock Control,version 6.0.
I doing client-server program and that i have to use Winsock control only for this purpose since it is my BOSS order's.

Now that i am on transition from vb6 to C# windows forms. In vb6 given below is vb6 code of control array of winsock control which i was able to easily create and manipulate in vb6:

Private Sub Form_Load()
    Dim x As Integer
    For x = 1 To 20    'This will allow a maximum of 20 clients to be connected at once
        Load sckClient(x)
        sckClient(x).Close
    Next
    StartListen
End Sub
Private Function StartListen()
    sckServer.Close
    sckServer.LocalPort = 25000
    sckServer.Listen
End Function



其中 sckClient 是名称我的winsock控件在vb6中。

以下是我的 c#代码翻译/上述 vb6 代码的解释:


where sckClient is name of my winsock control in vb6.
Given below is my c# code translation/interpretation of above vb6 code:

private void StartListen()
        {
            sckServer.Close();
            sckServer.LocalPort = 25000;
            sckServer.Listen();
        }
 private void Form1_Load(object sender, EventArgs e)
        {
            int x;
            for (x = 1; x == 20; x++)
            {
                
              
                StartListen();
            }
        }



c#中的上述代码中,我遇到了 vb6 <的翻译/解释/ b>行到c#windows表单


In above code in c# i get stuck at translation/interpretation of vb6 line to c# windows forms

Load sckClient(x)



在c#windows窗体中我发现创建控制数组几乎是不可能的c#windows窗体中的winsock控件。

我在c#windows窗体中使用命名空间:使用System.Net ;

使用System .Net.Sockets ;

我浏览过如何在c#windows窗体中创建控件数组的文章。



有解决方案但不是如何在c#windows窗体中创建winsock控件的控件数组(或数组)。

有人可以帮我吗?!谁能帮助我/指导我如何在c#windows窗体中创建winsock控件的控件数组?

我只需要一个关于如何在c#windows窗体中创建winsock控件的控件数组的示例,并且能够使用c#windows窗体中的winsock控件的控件数组进行一些代码操作。任何人都可以帮助我!?任何帮助/指导解决这个问题都将非常感谢!


In c# windows forms i find it nearly impossible to create control array of winsock control in c# windows forms.
I am using namespaces in my c# windows forms: using System.Net;
using System.Net.Sockets;
I have browsed through articles in net of how to create control arrays in c# windows forms.

There are solutions but not how to create control arrays(or arrays) of winsock control in c# windows forms.
Can anyone help me please?! Can anyone help me/guide me on how to create control array of winsock control in c# windows forms?
I just need a sample on how to create a control array of winsock control in c# windows forms and be able to some code manipulations using control array of winsock control in c# windows forms. Can anyone help me please!? Any help/guidance in solving of this problem would be greatly appreciated!

推荐答案

您可能应该使用更现代的Socket控件,它可以完成WinSock的所有功能,只是不同。



但是,如果你必须使用WinSock,并且你已经将WinSock控件添加到你的工具箱中,那么它并不复杂。

首先看看VS为你做什么来添加一个Winsock。

1)将一个拖到你的表单上。它将被称为 axWinsock1

2)转到你的代码视图,并在任何方法中使用变量:只需键入它的名称。

3)右键单击它,然后选择转到定义。

4)您将在以下行查看Designer文件:

You should probably be using a more modern Socket control, which can do everything a WinSock can, just differently.

However, if you must use WinSock, and you have added WinSock controls to your toolbox, then it's not complex.
Start by looking at what VS does for you to add a Winsock.
1) Drag one onto your form. It will be called axWinsock1
2) Go to your code view, and in any method use the variable: just type it's name.
3) Right click it, and select "Go to definition".
4) You will be looking at the Designer file, at the line:
private AxMSWinsockLib.AxWinsock axWinsock1;



不要对此文件进行任何更改。

5)右键单击 axWinsock1 再次选择查找所有引用

您将获得一个新的符号结果窗格,显示创建实例所需的代码。

全部您现在要做的是在您自己的文件中复制该代码,但改为使用控件数组:


DO NOT MAKE ANY CHANGES TO THIS FILE.
5) Right click axWinsock1 again, and select "Find all references"
You will get a new symbol results pane showing you exactly what code is needed to create an instance.
All you have to do now is duplicate that code in your own file, but using an array of controls instead:

private AxMSWinsockLib.AxWinsock[] mySockets = new AxMSWinsockLib.AxWinsock[20];
...
for (int i = 0; i < 20; i++)
   {
   mySockets[i] = new AxMSWinsockLib.AxWinsock();
   ((System.ComponentModel.ISupportInitialize)(this.axWinsock1)).BeginInit();
   mySockets[i].Enabled = true;
   ...
   }





或者至少,这是理论 - 我没试过,但是它应该工作正常!



Or at least, that's the theory - I've not tried, but it should work fine!


这篇关于如何在c#windows窗体中创建winsock控件的控件数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆