Пример #1
0
        private void OnQuestionAnswersReceived(QuestionModel model)
        {
            while (!this.IsHandleCreated)
            {
                ;
            }
            if (this.InvokeRequired)
            {
                this.Invoke((QuestionController.ExternalEventHandler)
                            OnQuestionAnswersReceived, model);
                return;
            }
            int start = 0;

            if (answersRichTextBox.Text.Length != 0)
            {
                start = model.Answers.Count - 1;
            }

            for (int i = start; i < model.Answers.Count; i++)
            {
                answersRichTextBox.SelectionStart     = answersRichTextBox.Text.Length;
                answersRichTextBox.SelectionFont      = new Font("Verdana", 8, FontStyle.Bold);
                answersRichTextBox.SelectionBackColor = Color.LightGray;
                UserData owner = new UserData("x", "y");
                for (int j = 0; j < model.AnswerOwners.Count; j++)
                {
                    if (model.Answers[i].Owner == model.AnswerOwners[j].Id)
                    {
                        owner = model.AnswerOwners[j];
                        break;
                    }
                }
                answersRichTextBox.SelectedText = owner.Username + "\t" + model.Answers[i].Timestamp + "\n";
                answersRichTextBox.SelectedRtf  = model.Answers[i].Content;
                answersRichTextBox.SelectedText = "\n\n";
            }
            answersRichTextBox.ScrollToCaret();

            int index = 0;

            ratingUsers = new Dictionary <RatingControl, UserData>();
            usersPanel.Controls.Clear();
            foreach (UserData user in model.AnswerOwners)
            {
                RatingControl voteWidget = new RatingControl();
                voteWidget.Location = new Point(10, 27 + index * 45);
                voteWidget.AutoSize = false;
                voteWidget.Scale(new SizeF((float)0.45, (float)0.5));
                voteWidget.Fixed = false;
                if (user.Id == LoggedInUserModel.Instance.User.Id)
                {
                    voteWidget.Enabled = false;
                }
                voteWidget.SelectRating += new Rating.RatingControl.SelectRatingHandler(this.onVoteWidgetClick);
                if (model.My_votes.ContainsKey(user.Id))
                {
                    voteWidget.Rating = model.My_votes[user.Id];
                }
                else
                {
                    controller.CheckUserVote(user);
                }
                usersPanel.Controls.Add(voteWidget);


                Label userLabel = new Label();
                userLabel.Text     = user.Username + " (" + String.Format("{0:0.##}", user.Rank) + ")";
                userLabel.Location = new Point(55, 15 + index * 22);
                userLabel.AutoSize = true;
                usersPanel.Controls.Add(userLabel);
                userLabels.Add(userLabel, user.Id);
                userLabel.MouseClick += new System.Windows.Forms.MouseEventHandler(userClicked);
                index++;

                ratingUsers.Add(voteWidget, user);
            }

            postRichTextBox.Focus();
            changeStateIMButtons(model);
        }