Exemplo n.º 1
0
        public SoulerForm(string uid, QuerySoulerInfoResponse soulerInfo, Image img)
        {
            InitializeComponent();
            soulerID = uid;

            // 标题
            this.Text = $"{soulerInfo.data.signature} - {Application.ProductName}";

            // 用户头像
            picSouler.Image     = img;
            picSouler.BackColor = ((Bitmap)img).GetPixel(0, 0);

            QuerySoulerHomepageResponse response = SoulAPI.QuerySoulerHomepage(uid);

            foreach (DataItem data in response.data)
            {
                KeyValueListItem item = new KeyValueListItem();

                var nowTime = new DateTime(1970, 1, 1, 8, 0, 0).AddMilliseconds(data.createTime);

                item.Key   = $"{nowTime.Month}月{nowTime.Day}日";
                item.Value = data.content;

                msgList.Items.Add(item);
            }
        }
        private void Settings_Load(object sender, EventArgs e)
        {
            // 设置窗体可拖动范围
            mmc.Form = this;
            mmc.Add(new Control[] { this, panelContent, panelTitle, labTitle });

            // 加载配置文件
            ReadSettingsFile();

            // 获取Souler信息
            foreach (string uid in settings.Soulers)
            {
                try
                {
                    // 获取数据
                    QuerySoulerInfoResponse response = SoulAPI.QuerySoulerInfo(uid);

                    // 用户性别和人称代词
                    string gender  = response.data.gender == 1 ? "女" : "男";
                    string pronoun = response.data.gender == 1 ? "她" : "他";

                    // 实例化SoulerItem对象
                    SoulerItem item = new SoulerItem();
                    item.Tag     = response;
                    item.Title   = response.data.signature;
                    item.TagText = $"[{response.data.postCount}个瞬间]";
                    item.Content = $"{pronoun}来到Soul已有{response.data.registerDays}天";
                    item.Image   = SoulAPI.GetSoulerImageByAvatarName(response.data.avatarName);

                    // 为快捷菜单选项添加事件
                    item.tsmiCopySignature.Click  += (s, args) => { Clipboard.SetDataObject(response.data.signature); Toast.Show("已复制到粘贴板"); };
                    item.tsmiCopyAvatarName.Click += (s, args) => { Clipboard.SetDataObject(response.data.avatarName); Toast.Show("已复制到粘贴板"); };
                    item.tsmiOpenWeb.Click        += (s, args) => { System.Diagnostics.Process.Start($"https://w3.soulapp-inc.cn/activity/#/web/user?targetUserId=-1&userIdEcpt={uid}"); };
                    item.tsmiDelete.Click         += (s, args) => { DeleteSouler(uid, item); };
                    item.tsmiOpen.Click           += (s, args) => { OpenSoulerForm(uid, response, item.Image); };
                    item.Click += (s, args) => { OpenSoulerForm(uid, response, item.Image); };

                    // 将SoulerItem控件加入面板
                    panelSoulerList.Controls.Add(item);
                }
                catch (Exception ex)
                {
                    DialogBoxes.MsgBox("获取Souler信息失败", ex.Message);
                }
            }
        }