⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portraitform.cs

📁 飞信的收发使用csharp进行开发
💻 CS
📖 第 1 页 / 共 2 页
字号:
        }

        private void GetCustomPortraits()
        {
            string baseDirForMyUsedPortrait = this._user.PersistentManager.BaseDirForMyUsedPortrait;
            if (Directory.Exists(baseDirForMyUsedPortrait))
            {
                FileInfo[] files = new DirectoryInfo(baseDirForMyUsedPortrait).GetFiles("*.dat");
                if (files.Length > 0)
                {
                    foreach (FileInfo info2 in files)
                    {
                        Image image = ImpsResources.LoadImage(info2.FullName);
                        if (image != null)
                        {
                            Image icon = ImageHelper.TryGetSquareThumbnailImage(image, 0x60);
                            int num = info2.Name.LastIndexOf('.');
                            headicon headicon = new headicon(icon, info2.Name.Substring(0, (-1 == num) ? info2.Name.Length : num));
                            headicon.iconpath = info2.FullName.ToLower();
                            this.lbPortrait.add(headicon);
                        }
                    }
                }
            }
        }

        private void GetDefaultPortraits()
        {
            FileInfo[] initPortraits = ImpsPortrait.GetInitPortraits();
            if (initPortraits != null)
            {
                for (int i = 0; i < initPortraits.Length; i++)
                {
                    Image icon = ImpsResources.LoadImage(initPortraits[i].FullName);
                    if (icon != null)
                    {
                        string description = ImpsPortrait.GetDescription(initPortraits[i].Name);
                        headicon headicon = new headicon(icon, description);
                        headicon.iconpath = initPortraits[i].FullName.ToLower();
                        this.lbPortrait.add(headicon);
                    }
                }
            }
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(PortraitForm));
            this.buttonAdd = new XButton();
            this.buttonDel = new XButton();
            this.buttonOK = new XButton();
            this.buttonCancel = new XButton();
            this.label1 = new XLabel();
            this.m_pane = new Panel();
            this.pbMyPortrait = new DisplayPortrait();
            this.m_pane.SuspendLayout();
            base.SuspendLayout();
            base.menubar.Location = new Point(3, 0x15);
            this.buttonAdd.Location = new Point(0xe8, 8);
            this.buttonAdd.Name = "buttonAdd";
            this.buttonAdd.Size = new Size(0x4b, 0x15);
            this.buttonAdd.TabIndex = 2;
            this.buttonAdd.Text = "添加";
            this.buttonAdd.UseVisualStyleBackColor = true;
            this.buttonAdd.Click += new EventHandler(this.buttonAdd_Click);
            this.buttonDel.Enabled = false;
            this.buttonDel.Location = new Point(0xe8, 0x23);
            this.buttonDel.Name = "buttonDel";
            this.buttonDel.Size = new Size(0x4b, 0x15);
            this.buttonDel.TabIndex = 3;
            this.buttonDel.Text = "删除";
            this.buttonDel.UseVisualStyleBackColor = true;
            this.buttonDel.Click += new EventHandler(this.buttonDel_Click);
            this.buttonOK.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.buttonOK.CausesValidation = false;
            this.buttonOK.Enabled = false;
            this.buttonOK.Location = new Point(0x9d, 0x128);
            this.buttonOK.Name = "buttonOK";
            this.buttonOK.Size = new Size(0x4b, 0x15);
            this.buttonOK.TabIndex = 4;
            this.buttonOK.Text = "确定";
            this.buttonOK.UseVisualStyleBackColor = true;
            this.buttonOK.Click += new EventHandler(this.buttonOK_Click);
            this.buttonCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.buttonCancel.DialogResult = DialogResult.Cancel;
            this.buttonCancel.Location = new Point(0xee, 0x128);
            this.buttonCancel.Name = "buttonCancel";
            this.buttonCancel.Size = new Size(0x4b, 0x15);
            this.buttonCancel.TabIndex = 5;
            this.buttonCancel.Text = "取消";
            this.buttonCancel.UseVisualStyleBackColor = true;
            this.buttonCancel.Click += new EventHandler(this.buttonCancel_Click);
            this.label1.AutoSize = true;
            this.label1.Location = new Point(0xd1, 0x4e);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x1d, 12);
            this.label1.TabIndex = 6;
            this.label1.Text = "预览";
            this.m_pane.AutoSize = true;
            this.m_pane.BackColor = Color.Transparent;
            this.m_pane.Controls.Add(this.pbMyPortrait);
            this.m_pane.Controls.Add(this.buttonAdd);
            this.m_pane.Controls.Add(this.label1);
            this.m_pane.Controls.Add(this.buttonCancel);
            this.m_pane.Controls.Add(this.buttonDel);
            this.m_pane.Controls.Add(this.buttonOK);
            this.m_pane.Dock = DockStyle.Fill;
            this.m_pane.Location = new Point(6, 0x16);
            this.m_pane.Name = "m_pane";
            this.m_pane.Size = new Size(0x144, 0x142);
            this.m_pane.TabIndex = 7;
            this.pbMyPortrait.BackColor = Color.White;
            this.pbMyPortrait.BorderColor = Color.FromArgb(0xa4, 170, 220);
            this.pbMyPortrait.Image = (Image) manager.GetObject("pbMyPortrait.Image");
            this.pbMyPortrait.Location = new Point(0xd4, 0x60);
            this.pbMyPortrait.Name = "pbMyPortrait";
            this.pbMyPortrait.ShowSecondBorder = false;
            this.pbMyPortrait.Size = new Size(0x66, 0x66);
            this.pbMyPortrait.TabIndex = 7;
            this.pbMyPortrait.ToolTipText = "";
            this.pbMyPortrait.UseHandCursor = false;
            base.AcceptButton = this.buttonOK;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.CancelButton = this.buttonCancel;
            base.ClientSize = new Size(0x15d, 0x15f);
            base.Controls.Add(this.m_pane);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MinimizeBox = false;
            base.Name = "PortraitForm";
            base.Padding = new Padding(6, 0x16, 0x13, 7);
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterParent;
            base.Text = "我的头像";
            base.Shown += new EventHandler(this.PortraitForm_Shown);
            base.Controls.SetChildIndex(this.m_pane, 0);
            base.Controls.SetChildIndex(base.menubar, 0);
            this.m_pane.ResumeLayout(false);
            this.m_pane.PerformLayout();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void lbPortrait_SelectedIndexChanged(object sender, EventArgs e)
        {
            headicon headicon = this.lbPortrait.get_selected_item();
            if (headicon == null)
            {
                this.pbMyPortrait.Image = null;
                this.buttonDel.Enabled = false;
                this.buttonOK.Enabled = false;
            }
            else
            {
                if (this.lbPortrait.get_selected_index() <= this.m_index_of_customicon)
                {
                    this.buttonDel.Enabled = false;
                }
                else
                {
                    this.buttonDel.Enabled = true;
                }
                this.pbMyPortrait.Image = headicon.icon;
                this.label1.Visible = true;
                this.buttonOK.Enabled = true;
            }
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            this.lbPortrait.drawer = null;
            base.OnClosing(e);
        }

        protected override void OnCreateControl()
        {
            this.lbPortrait.Location = new Point(6, this.buttonAdd.Location.Y);
            this.lbPortrait.Size = new Size(this.pbMyPortrait.Left - 12, this.buttonOK.Top - 6);
            base.OnCreateControl();
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                try
                {
                    base.Close();
                    return;
                }
                catch (Exception exception)
                {
                    ClientLogger.WriteException(exception);
                }
            }
            base.OnKeyDown(e);
        }

        private void PortraitForm_Shown(object sender, EventArgs e)
        {
            this.m_index_of_sysicon = this.lbPortrait.add_separator("系统默认头像");
            this.GetDefaultPortraits();
            this.lbPortrait.SelectedIndex = 0;
            this.m_index_of_customicon = this.lbPortrait.Items.Count;
            this.m_index_of_customicon = this.lbPortrait.add_separator("自定义头像");
            this.GetCustomPortraits();
            this.label1.Visible = true;
            this.lbPortrait.Sorted = true;
            this.pbMyPortrait.Image = this._user.PersonalInfo.Portrait;
            this.SetSelectedPortrait();
        }

        private void SetSelectedPortrait()
        {
            if (this._user.Configuration.UserSetting.SaveMyInfo)
            {
                string path = this._user.Configuration.UserSetting.ConversationSetting.CurrentPortraitFileInfo.Split(new char[] { ',' })[1];
                if (File.Exists(path))
                {
                    int num = 0;
                    foreach (object obj2 in this.lbPortrait.Items)
                    {
                        if (obj2 is headicon)
                        {
                            headicon headicon = (headicon) obj2;
                            if (headicon.iconpath.CompareTo(path.ToLower()) == 0)
                            {
                                this.lbPortrait.SelectedIndex = num;
                                this.lbPortrait.Invalidate();
                                break;
                            }
                        }
                        num++;
                    }
                }
            }
            this.buttonOK.Enabled = false;
        }

        private static void uploadPortrait_ImpsError(object sender, ImpsErrorEventArgs e)
        {
            try
            {
                AsyncBizOperation operation = (AsyncBizOperation) sender;
                object[] contextForUi = (object[]) operation.ContextForUi;
                IFrameworkWindow framework = (IFrameworkWindow) contextForUi[0];
                Form owner = (Form) contextForUi[1];
                UiErrorHelper.ShowImpsError(framework, owner, e);
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException("上传头像", exception);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -