.


:




:

































 

 

 

 





csComp (SqwComp), . csServer (Server), (SqwServer), (SqwMain)

// C# File csSqw_Dll_Comp_7

using System;

using System.ComponentModel;

using System.Drawing;

 

namespace csComp

{

//

public class SqwComp: Component

{

private int numComp; //

private Point point; //

 

//

public SqwComp (int NumComp, Point Pnt)

{

numComp= NumComp;

point= Pnt;

}

// Number

public int Number

{

get

{

return numComp;//nt;

}

}

// Point

public Point Point

{

get

{

return point;

}

}

}

}

 

-

/////////////////////////

// C# File csSqw_Dll_7

// (Project/AddReference) csSqw_RemObject_Dll_4.dll

// (Project/AddReference) System.Runtime.Remoting.dll

// (Project/AddReference) csSqw_Dll_4.dll

using System;

using System.Drawing;

using System.Windows.Forms;

using System.Collections;

using System.ComponentModel;

using System.Runtime.Remoting;

using csComp;

using System.Threading;

 

namespace csServer

{

// - , .

//

public class Server: Form

{

private static int numCompnts= 0;

public SqwComp cs; //

private Random rand; //

public Container components = null;

 

//

public Server()

{

components= new Container ();

Text= " ";

rand= new Random ();

}

 

//

public virtual void CreateAdd ()

{

numCompnts++;

Point point= new Point ();

point.X= rand.Next (ClientSize.Width);

point.Y= rand.Next (ClientSize.Height);

SqwComp cmpnt= new SqwComp (numCompnts, point);

components.Add (cmpnt);

Invalidate ();

}

 

//

public virtual void Remove (int Num)

{

IEnumerator inum= components.Components.GetEnumerator ();

while (inum.MoveNext()) //

{

SqwComp cm= (SqwComp) inum.Current;

if (cm.Number == Num)

{

components.Remove (cm); //

Invalidate ();

break;

}

}

}

 

//

public virtual void GetRefList (ref ArrayList AL)

{

ArrayList aL= new ArrayList ();

IEnumerator inum= components.Components.GetEnumerator ();

while (inum.MoveNext()) //

{

SqwComp cm= (SqwComp) inum.Current;

aL.Add (cm.Number);

}

AL=aL;

}

 

//

protected override void OnPaint (PaintEventArgs e)

{

base.OnPaint (e);

IEnumerator inum=components.Components.GetEnumerator();

while (inum.MoveNext()) //

{

SqwComp cm= (SqwComp) inum.Current;

e.Graphics.DrawRectangle(new Pen(Color.Blue, 5),

cm.Point.X-20, cm.Point.Y-20, 40, 40);

e.Graphics.DrawString (cm.Number.ToString (),

new Font("Arial", 9),

new SolidBrush (Color.Red), cm.Point.X, cm.Point.Y);

}

}

}

}

/////////////////////////

// C# File csSqw_Server_7

// (Project/AddReference) csSqw__Dll_7.dll

// (Project/AddReference) System.Runtime.Remoting.dll

using System;

using System.Drawing;

using System.Windows.Forms;

using System.Collections;

using System.ComponentModel;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Http;

using csServer;

using System.Threading;

 

public class SqwServer

{

static void Main ()

{

Server serv= new Server();

HttpChannel httpChannel;

try

{

httpChannel= new HttpChannel (8080);

ChannelServices.RegisterChannel (httpChannel);

}

catch(Exception e)

{

Console.WriteLine(e.Message);

return;

}

RemotingServices.Marshal (serv, "RemoteServer");

Application.Run(serv);

}

}

 

/////////////////////////

// C# File csSqw_Client_7

// (Project/AddReference) csSqw_Dll_7.dll

// (Project/AddReference) csSqw_Dll_Comp_7.dll

// (Project/AddReference) System.Runtime.Remoting.dll

using System;

using System.Collections;

using System.Drawing;

using System.Windows.Forms;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Http;

using csComp;

using csServer;

 

namespace csSqw_Client_7

{

public class SqwMain: System.Windows.Forms.Form

{

private csServer.Server serv;

private Button butAdd;

private Button butDel;

private ListBox listBox;

int numComp= 0;

 

//

public SqwMain ()

{

Text= " ";

butAdd= new Button ();

butAdd.Text=" ";

butAdd.Location= new Point (10,10);

butAdd.Size= new System.Drawing.Size(130,20);

butAdd.Click+= new EventHandler (ClickButAdd);

this.Controls.Add (butAdd);

//-----

butDel=new Button ();

butDel.Text=" :";

butDel.Location= new Point (10,30);

butDel.Size= new System.Drawing.Size (180, 20);

butDel.Click += new EventHandler (ClickButDel);

this.Controls.Add (butDel);

listBox= new ListBox ();

listBox.Location= new Point (200, 30);

listBox.Size= new System.Drawing.Size (60, 20);

this.Controls.Add (listBox);

/////////////////////////////////////////////

HttpChannel httpChannel= new HttpChannel (0);

ChannelServices.RegisterChannel (httpChannel);

serv= (csServer.Server) Activator.GetObject(

typeof (csServer.Server),

"http://localhost:8080/RemoteServer");

}

 

//

void ClickButAdd (object o, EventArgs e)

{

numComp++;

serv.CreateAdd ();

ArrayList aL=null;

listBox.Items.Clear ();

serv.GetRefList (ref aL);

IEnumerator inum=aL.GetEnumerator();

while(inum.MoveNext())

{

int num= (int) inum.Current;

listBox.Items.Add (num);

}

}

 

//

void ClickButDel (object o, EventArgs e)

{

if (listBox.SelectedIndex==-1)

{

MessageBox.Show ("

");

}

else

{

int numSel= (int) listBox.SelectedItem;

listBox.Items.Remove (numSel);

serv.Remove(numSel);

///////////////

ArrayList aL=null;

listBox.Items.Clear ();

serv.GetRefList(ref aL);

 

for(int i= 0; i < aL.Count; i++)

{

int num= (int) aL[i];

listBox.Items.Add (num);

}

}

}

 

//

static void Main ()

{

SqwMain sqwMain= new SqwMain ();

Application.Run(sqwMain);

}

}

}

 





:


: 2017-02-11; !; : 185 |


:

:

, .
==> ...

1665 - | 1532 -


© 2015-2024 lektsii.org - -

: 0.037 .