示例#1
0
        public MessengerForm(string ip)
        {
            if (String.IsNullOrWhiteSpace(ip) || String.IsNullOrEmpty(ip))
            {
                MessageBox.Show("Please specify the server IP in the launch arguments like so:\n\nC:/.../MESENGER.exe -[ip:port]\n\nThe program will now close.");
                Process.GetCurrentProcess().Kill();
                return;
            }

            var loginForm = new LoginForm(ip);

            loginForm.ShowDialog();

            _server  = loginForm._client;
            _stream  = loginForm._stream;
            _account = loginForm._account;

            if (_account == null)
            {
                Process.GetCurrentProcess().Kill();
            }

            InitializeComponent();

            lblProfile.Text = _account.Nickname;

            pbProfile.Image = _account.GetProfileImage();

            pbProfile.AllowDrop = true;

            //listen for incomming data
            new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        if (_server.Connected && _stream.CanRead && _stream.DataAvailable)
                        {
                            BinaryFormatter bf = new BinaryFormatter();
                            onDataReceived(bf.Deserialize(_stream));
                        }
                    }
                    catch
                    {
                    }

                    Thread.Sleep(1);
                }
            })
            {
                IsBackground = true
            }.Start();
        }
示例#2
0
        private void lbOnline_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (lbOnline.Items.Count > 0 && e.Index != -1)
            {
                ClientUserAccount account = lbOnline.Items[e.Index] as ClientUserAccount;

                DrawingHelper.enableSmooth(e.Graphics, false);

                e.DrawBackground();

                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    e = new DrawItemEventArgs(e.Graphics,
                                              e.Font,
                                              e.Bounds,
                                              e.Index,
                                              e.State ^ DrawItemState.Selected,
                                              e.ForeColor,
                                              Color.FromArgb(0, 180, 255));

                    e.DrawBackground();
                    e.DrawFocusRectangle();
                }

                Brush brush = account.banned ? new SolidBrush(Color.FromArgb(255, 50, 100)) : new SolidBrush(account.Online ? Color.FromArgb(150, 255, 50) : Color.FromArgb(50, 50, 50));

                e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Width - 5, e.Bounds.Y, 5, 50));
                DrawingHelper.enableSmooth(e.Graphics, true);

                Image img = ImageUtils.ResizeAndCrop(account.GetProfileImage(), 50, 50);

                e.Graphics.DrawImage(img, e.Bounds.X, e.Bounds.Y);

                if (account.isTyping)
                {
                    Font f = new Font(lbOnline.Font.FontFamily, 21, FontStyle.Bold);

                    string text = "...";

                    SizeF s = e.Graphics.MeasureString(text, f, new Size(50, 50));

                    e.Graphics.FillRectangle(new SolidBrush(Color.Black), 10, e.Bounds.Y + 50 - 10, 50 - 20, 10);

                    e.Graphics.DrawString(text, f, Brushes.Turquoise, 25 - s.Width / 2f + 1, e.Bounds.Y + 25 - s.Height / 2f + 14);
                }

                int i = (int)e.Graphics.MeasureString(account.ToString(), lbOnline.Font, lbOnline.Width - 60).Height;
                e.Graphics.DrawString(account.ToString(), e.Font, new SolidBrush(Color.Black),
                                      new Rectangle(new Point(55, e.Bounds.Y + 25 - i / 2), new Size(e.Bounds.Width - 60, 50)));
            }
        }