Exemplo n.º 1
0
        /// <summary>
        /// Add a new File Transfer control to the form. A connection is established between
        /// the client and server. Depending on the transfer mode, the local machine acts as
        /// a server or a client.
        /// </summary>
        /// <param name="mode">The transfer mode. Can be Send or Receive.</param>
        /// <param name="remoteUserName">Remote user's name.</param>
        /// <param name="remoteAddress">IP address of remote user.</param>
        /// <param name="key">Unique key for this file transfer.</param>
        /// <param name="fileName">Name of file to be sent/received.</param>
        /// <param name="fileSize">Size of the file.</param>
        public void AddFileTransfer(FileTransfer.Modes mode, string remoteUserName, string remoteAddress, string key, string fileName, string fileSize)
        {
            //  Create a new File Transfer control and set its properties.
            FileTransferControl fileTransferControl = null;

            try {
                fileTransferControl          = new FileTransferControl(mode, key, bAutoReceiveFile);
                fileTransferControl.UserName = remoteUserName;
                fileTransferControl.FileName = fileName;
                fileTransferControl.FileSize = long.Parse(fileSize);
                //  This will force the system to create a handle for the control.
                IntPtr dummy = fileTransferControl.Handle;
                fileTransferControl.Selected      += new FileTransferControl.SelectedEventHandler(FileTransferControl_Selected);
                fileTransferControl.MouseClick    += new FileTransferControl.MouseClickEventHandler(FileTransferControl_MouseClick);
                fileTransferControl.Notify        += new FileTransferControl.NotifyEventhandler(FileTransferControl_Notify);
                fileTransferControl.LayoutChanged += new FileTransferControl.LayoutChangedEventHandler(FileTransferControl_LayoutChanged);
                fileTransferControl.InitControl();
                //  Add the control to the top of the File transfer list.
                fileTransferList.Insert(0, fileTransferControl);

                if (mode == FileTransfer.Modes.Send)
                {
                    ShowWindow(false, false);
                    BeginAccept(key);
                }
                else
                {
                    ShowWindow(bFileToForeground, false);
                    BeginConnect(key, remoteAddress);
                }

                //  Update the panel's controls.
                PopulateTransferList(0);
                //  Set the UI theme.
                SetTheme(Properties.Settings.Default.UseThemes, Properties.Settings.Default.ThemeFile);
                //  Make the new control the selected control.
                SelectControl(fileTransferControl);
            }
            catch (Exception ex) {
                fileTransferControl.Dispose();
            }
        }
Exemplo n.º 2
0
 private void RemoveTransferFromList(FileTransferControl control)
 {
     fileTransferList.Remove(control);
     control.Dispose();
 }