Monday, June 30, 2014

how to create control array of winsock control control/controls in c# windows forms

Dear Mr.Muthukrishnan Ramasamy


Are you telling that i should add a panel control(named:Panel1) to my Form1(name of my form in c# windows forms) at design time with all other controls inside it?


Given below is c# code of Form1.Designer.cs:



namespace DRRS_Socket_Application
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.listBox1 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.Winsock1 = new AxMSWinsockLib.AxWinsock();
this.sckServer = new AxMSWinsockLib.AxWinsock();
this.axWinsock1 = new AxMSWinsockLib.AxWinsock();
((System.ComponentModel.ISupportInitialize)(this.Winsock1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.sckServer)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.axWinsock1)).BeginInit();
this.SuspendLayout();
// listBox1
//
this.listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = 18;
this.listBox1.Location = new System.Drawing.Point(22, 23);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(301, 382);
this.listBox1.TabIndex = 1;
this.listBox1.Click += new System.EventHandler(this.listBox1_Click);
this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
//
// button1
//
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button1.Location = new System.Drawing.Point(345, 61);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(151, 43);
this.button1.TabIndex = 2;
this.button1.Text = "Get IP Address";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button2.Location = new System.Drawing.Point(345, 110);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(151, 48);
this.button2.TabIndex = 3;
this.button2.Text = "Start Listen";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox1.Location = new System.Drawing.Point(22, 427);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(301, 43);
this.textBox1.TabIndex = 7;
this.textBox1.Text = "localhost";
//
// textBox2
//
this.textBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox2.Location = new System.Drawing.Point(345, 427);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(151, 43);
this.textBox2.TabIndex = 8;
this.textBox2.Text = "1234";
//
// textBox3
//
this.textBox3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox3.Location = new System.Drawing.Point(22, 476);
this.textBox3.Multiline = true;
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(474, 145);
this.textBox3.TabIndex = 9;
this.textBox3.Text = "Message";
//
// button3
//
this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button3.Location = new System.Drawing.Point(432, 628);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(94, 43);
this.button3.TabIndex = 10;
this.button3.Text = "Send";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Winsock1
//
this.Winsock1.Enabled = true;
this.Winsock1.Location = new System.Drawing.Point(390, 226);
this.Winsock1.Name = "Winsock1";
this.Winsock1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("Winsock1.OcxState")));
this.Winsock1.Size = new System.Drawing.Size(28, 28);
this.Winsock1.TabIndex = 11;
this.Winsock1.Error += new AxMSWinsockLib.DMSWinsockControlEvents_ErrorEventHandler(this.Winsock1_Error_1);
this.Winsock1.DataArrival += new AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEventHandler(this.Winsock1_DataArrival_1);
this.Winsock1.ConnectEvent += new System.EventHandler(this.Winsock1_ConnectEvent_1);
//
// sckServer
//
this.sckServer.Enabled = true;
this.sckServer.Location = new System.Drawing.Point(366, 277);
this.sckServer.Name = "sckServer";
this.sckServer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("sckServer.OcxState")));
this.sckServer.Size = new System.Drawing.Size(28, 28);
this.sckServer.TabIndex = 12;
this.sckServer.ConnectEvent += new System.EventHandler(this.sckServer_ConnectEvent);
this.sckServer.ConnectionRequest += new AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEventHandler(this.sckServer_ConnectionRequest_1);
//
// axWinsock1
//
this.axWinsock1.Enabled = true;
this.axWinsock1.Location = new System.Drawing.Point(400, 277);
this.axWinsock1.Name = "axWinsock1";
this.axWinsock1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWinsock1.OcxState")));
this.axWinsock1.Size = new System.Drawing.Size(28, 28);
this.axWinsock1.TabIndex = 13;
this.axWinsock1.Error += new AxMSWinsockLib.DMSWinsockControlEvents_ErrorEventHandler(this.axWinsock1_Error);
this.axWinsock1.DataArrival += new AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEventHandler(this.axWinsock1_DataArrival);
this.axWinsock1.ConnectEvent += new System.EventHandler(this.axWinsock1_ConnectEvent);
this.axWinsock1.CloseEvent += new System.EventHandler(this.axWinsock1_CloseEvent);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(637, 729);
this.Controls.Add(this.axWinsock1);
this.Controls.Add(this.sckServer);
this.Controls.Add(this.Winsock1);
this.Controls.Add(this.button3);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Server Listening";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.Winsock1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.sckServer)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.axWinsock1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion

private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;

private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button3;
private AxMSWinsockLib.AxWinsock Winsock1;
private AxMSWinsockLib.AxWinsock sckServer;
private AxMSWinsockLib.AxWinsock sckClient1;
private AxMSWinsockLib.AxWinsock axWinsock1;
}
}

Sorry for my long code of my form named: Form1.Designer.cs


I just thought that this might provide clear idea of how to create control array of winsock control in c# windows forms.


If not can you provide me a sample of adding invisible panel to my Form1 and adding Winsock controls to that panel which should be be AFTER EndInit.? Reply please?! I am waiting for your reply Sir!




vishal


No comments:

Post a Comment