// create a "other user" control with given properties, then place it on screen public static Panel CreateUserPanel(string user, int panelCount, string displayName, Image userIcon) { int panelX = 30; int panelY = 380; int panelWidth = 220; int panelHeight = 50; int pictureBoxOffset = 8; int pictureBoxX = pictureBoxOffset; int pictureBoxHeight = (int)(panelHeight * 0.9); int pictureBoxY = (int)((panelHeight - pictureBoxHeight) * 0.58); int pictureBoxWidth = pictureBoxHeight; int buttonX = pictureBoxWidth + pictureBoxOffset; int buttonY = 0; int buttonWidth = panelWidth - pictureBoxWidth; int buttonHeight = panelHeight; Panel p = CreateUserPanel(user, displayName, panelX, panelY, panelHeight, panelWidth, panelCount); RoundPictureBox pb = CreateUserPictureBox(pictureBoxX, pictureBoxY, pictureBoxWidth, pictureBoxHeight, p, userIcon); Button b = CreateUserButton(user, buttonWidth, buttonHeight, buttonX, buttonY, panelCount, p); //SetUserIconByName(user, pb); p.Controls.Add(pb); p.Controls.Add(b); return(p); }
private static RoundPictureBox CreateUserPictureBox(int pictureBoxX, int pictureBoxY, int pictureBoxWidth, int pictureBoxHeight, Panel p, Image userIcon) { RoundPictureBox pb = new RoundPictureBox() { BackColor = Color.Transparent, Anchor = AnchorStyles.Left | AnchorStyles.Bottom, BackgroundImageLayout = ImageLayout.Stretch, Size = new Size(pictureBoxWidth, pictureBoxHeight), Location = new Point(pictureBoxX, pictureBoxY), TabStop = false, Image = userIcon }; pb.MouseEnter += (s, e) => { p.BackColor = Color.LightGray; }; pb.MouseLeave += (s, e) => { p.BackColor = Color.Transparent; }; return(pb); }
//Received UI public ChatUI(string message, string date, Image contactPicture, int buffer, EmojiPanel emoji) { messageTab = new Panel(); Panel picturePanel = new Panel(); RoundPictureBox picture = new RoundPictureBox(); Panel messageBoxPanel = new Panel(); messageBox = new MyFixedRichTextBox(true); messageBox.setEmojiRef(emoji);//Update richtextbox to have a reference to the emojiPanel Label time = new Label(); messageTab.Controls.Add(messageBoxPanel); messageTab.Controls.Add(time); messageTab.Controls.Add(picturePanel); messageTab.Dock = DockStyle.Top; messageTab.Padding = new Padding(0, buffer, 0, 0); messageTab.Size = new Size(767, 42 + buffer); picturePanel.BackColor = Color.White; picturePanel.Controls.Add(picture); picturePanel.Dock = DockStyle.Left; picturePanel.Padding = new Padding(0, 0, 10, 0); picturePanel.Size = new Size(52, 42); picture.BackColor = Color.Transparent; picture.BackgroundImageLayout = ImageLayout.None; picture.Dock = DockStyle.Top; picture.Image = contactPicture;//Properties.Resources.user; picture.Size = new Size(42, 42); picture.SizeMode = PictureBoxSizeMode.StretchImage; messageBoxPanel.Controls.Add(messageBox); messageBoxPanel.BackColor = Color.FromArgb(240, 244, 248); messageBoxPanel.ForeColor = Color.FromArgb(43, 43, 48); messageBoxPanel.Dock = DockStyle.Fill; messageBoxPanel.Padding = new Padding(14, 8, 50, 6); messageBox.BackColor = Color.FromArgb(240, 244, 248); messageBox.ForeColor = Color.FromArgb(43, 43, 48); messageBox.BorderStyle = BorderStyle.None; messageBox.Dock = DockStyle.Fill; messageBox.Font = new Font("Segoe UI", 11F); messageBox.ReadOnly = true; messageBox.WordWrap = true; messageBox.Multiline = true; messageBox.ScrollBars = RichTextBoxScrollBars.None; messageBox.Text = message; messageBox.GotFocus += new EventHandler(messageBox_GotFocus); messageBox.TextChanged += (sender, e) => messageBox_SizeChanged(messageBox, buffer, messageTab, messageBoxPanel); messageBox.Resize += (sender, e) => messageBox_SizeChanged(messageBox, buffer, messageTab, messageBoxPanel); time.ForeColor = Color.FromArgb(102, 116, 134); time.Dock = DockStyle.Right; time.Font = new Font("Segoe UI", 8F); time.ImageAlign = ContentAlignment.TopCenter; time.Padding = new Padding(50, 11, 0, 0); time.Size = new Size(176, 42); time.Text = date;// DateTime.Now.ToString("h:mm tt"); time.TextAlign = ContentAlignment.TopCenter; }
//private Label mood;//Might Add Later public ContactUI(string username, Image contactPic, bool contact) { contactTab = tab(contact); contactPicture = picture(contactPic, contact); contactName = name(username, contactTab, contact); contactTab.Controls.Add(contactName); contactTab.Controls.Add(contactPicture); }
private RoundPictureBox picture(Image contactPic, bool contact) { RoundPictureBox pic = new RoundPictureBox(); pic.BackColor = Color.Transparent; pic.BackgroundImageLayout = ImageLayout.None; pic.Dock = DockStyle.Left; pic.Image = contactPic; if (contact) { pic.Size = new Size(42, 52); } else { pic.Size = new Size(70, 80); } pic.SizeMode = PictureBoxSizeMode.StretchImage; return(pic); }
private void MainForm_Load(object sender, EventArgs e) { FormBackup = this; Save.FriendsList = JsonConvert.DeserializeObject <FriendsList>(SendRequest($@"{Save.url}v1/LuaApiCaller?qq={Save.curentQQ}&funcname=GetQQUserList&timeout=10", "{\"StartIndex\":0}")); Save.GroupList = JsonConvert.DeserializeObject <GroupList>(SendRequest($@"{Save.url}v1/LuaApiCaller?qq={Save.curentQQ}&funcname=GetGroupList&timeout=10", "{\"NextToken\":\"\"}")); Thread getGroupInfo_Thread = new Thread(() => { foreach (var item in Save.GroupList.TroopList) { item.GroupMemberList = JsonConvert.DeserializeObject <GroupMemberList>(SendRequest($@"{Save.url}v1/LuaApiCaller?qq={Save.curentQQ}&funcname=GetGroupUserList&timeout=10", $"{{\"GroupUin\":{item.GroupId},\"LastUin\":0}}")); } }); getGroupInfo_Thread.Start(); //根据登录时的QQ号 获取QQ昵称 string name = Save.FriendsList.Friendlist.First(x => x.FriendUin == Save.curentQQ).NickName.ToString(); Save.name = name; if (!Directory.Exists("conf")) { Directory.CreateDirectory("conf"); } if (File.Exists(LogHelper.GetLogFilePath()) is false) { LogHelper.CreateDB(); } //读取窗口相关配置 if (File.Exists(@"conf\states.json")) { AppConfig = JObject.Parse(File.ReadAllText(@"conf\states.json")); } //配置文件为空或不包含配置相关键 if (AppConfig.Count == 0 || !AppConfig.ContainsKey("Main")) { JObject config = new JObject { new JProperty("FormX", Left), new JProperty("FormY", Top), new JProperty("ShowWindow", true), new JProperty("TopMost", true), new JProperty("ExpandWindow", false) }; AppConfig.Add(new JProperty("Main", config)); File.WriteAllText(@"conf\states.json", AppConfig.ToString()); } else//存在并读取配置 { Left = Convert.ToInt32(AppConfig["Main"]["FormX"].ToString()); Top = Convert.ToInt32(AppConfig["Main"]["FormY"].ToString()); //不直接给Visable赋值是因为外部调用Show函数会覆盖对Visable的赋值 //所以在调用Show之后需要用标志位恢复对Visable的变化值 ShowFlag = bool.Parse(AppConfig["Main"]["ShowWindow"].ToString()); TopFlag = bool.Parse(AppConfig["Main"]["TopMost"].ToString()); ExpandWindow(bool.Parse(AppConfig["Main"]["ExpandWindow"].ToString())); } //设置窗口透明色, 实现窗口背景透明 this.TransparencyKey = Color.Gray; this.BackColor = Color.Gray; //隐藏日志窗口, 但不关闭 logForm.Text = $"运行日志 - {Save.curentQQ}"; logForm.Show(); logForm.Visible = false; //初始化托盘 NotifyIconHelper._NotifyIcon = notifyIcon; NotifyIconHelper.Init(); NotifyIconHelper.ShowNotifyIcon(); //载入插件 pluginManagment = new PluginManagment(); Thread thread = new Thread(() => { pluginManagment.Init(); }); thread.Start(); //将托盘右键菜单复制一份 pictureBox_Main.ContextMenu = notifyIcon.ContextMenu; //实例化圆形图片框, 实现圆形的头像 HttpWebClient http = new HttpWebClient() { TimeOut = 3000 }; byte[] data = { }; //默认头像,防止网络问题造成空头像出现 Image image = Image.FromFile(@"conf\DefaultPic.jpeg"); try { data = http.DownloadData($"http://q1.qlogo.cn/g?b=qq&nk={Save.curentQQ}&s=640"); MemoryStream ms = new MemoryStream(data); if (ms.Length > 0)//下载成功 { image = Image.FromStream(ms); } else//下载失败 { image = Image.FromFile(@"conf\DefaultPic.jpeg"); } } catch { //网络异常,图片使用默认头像 LogHelper.WriteLog("下载头像超时,重新启动程序可能解决这个问题"); } RoundPictureBox RoundpictureBox = new RoundPictureBox { Size = new Size(43, 43), SizeMode = PictureBoxSizeMode.StretchImage, Left = -1, Top = 0, ContextMenu = notifyIcon.ContextMenu }; if (image != null) { RoundpictureBox.Image = image; } //添加拖动事件 RoundpictureBox.MouseDown += pictureBox_Main_MouseDown; //显示控件, 置顶 this.Controls.Add(RoundpictureBox); RoundpictureBox.BringToFront(); RoundpictureBox.MouseDoubleClick += RoundpictureBox_MouseDoubleClick; Loaded = true; Save.LoginStatus = true; //事件处理 SocketHandler(); //置顶维护时钟,每60秒将窗口重新置顶 Timer.Interval = 60000; Timer.Tick += CheckTopMost; Timer.Start(); }
// create a "other user" control with given properties, then place it on screen private void AddChangeUserPanel(string user, int panelCount) { int panelX = 30; int panelY = 380; int panelWidth = 200; int panelHeight = 50; int pictureBoxOffset = 8; int pictureBoxX = pictureBoxOffset; int pictureBoxHeight = (int)(panelHeight * 0.9); int pictureBoxY = (int)((panelHeight - pictureBoxHeight) * 0.58); int pictureBoxWidth = pictureBoxHeight; int buttonX = pictureBoxWidth + pictureBoxOffset; int buttonY = 0; int buttonWidth = panelWidth - pictureBoxWidth; int buttonHeight = panelHeight; Panel p = new Panel() { Anchor = AnchorStyles.Left | AnchorStyles.Bottom, Location = new Point(panelX, panelY + panelHeight * panelCount * -1), Size = new Size(panelWidth, panelHeight), BorderStyle = BorderStyle.None, BackColor = Color.Transparent, BackgroundImageLayout = ImageLayout.Stretch, TabStop = false }; if (!(user is null) && user == UserPrincipal.Current.DisplayName) { p.BackgroundImage = Properties.Resources.defaultButtonBackground; } p.MouseEnter += (s, e) => { p.BackColor = Color.LightGray; }; p.MouseLeave += (s, e) => { p.BackColor = Color.Transparent; }; RoundPictureBox pb = new RoundPictureBox() { BackColor = Color.Transparent, Anchor = AnchorStyles.Left | AnchorStyles.Bottom, BackgroundImageLayout = ImageLayout.Stretch, Size = new Size(pictureBoxWidth, pictureBoxHeight), Location = new Point(pictureBoxX, pictureBoxY), TabStop = false }; pb.MouseEnter += (s, e) => { p.BackColor = Color.LightGray; }; pb.MouseLeave += (s, e) => { p.BackColor = Color.Transparent; }; Button b = new Button() { Anchor = AnchorStyles.Left | AnchorStyles.Bottom, Size = new Size(buttonWidth, buttonHeight), Location = new Point(buttonX, buttonY), FlatStyle = FlatStyle.Flat, BackColor = Color.Transparent, Font = new Font("Segoe UI", 13), ForeColor = Color.White, Text = user, TextAlign = ContentAlignment.MiddleLeft, TabStop = false }; b.MouseEnter += (s, e) => { p.BackColor = Color.LightGray; }; b.MouseLeave += (s, e) => { p.BackColor = Color.Transparent; }; b.FlatAppearance.BorderSize = 0; b.FlatAppearance.MouseOverBackColor = Color.Transparent; b.FlatAppearance.MouseDownBackColor = Color.Transparent; SetUserIconByName(user, pb); p.Controls.Add(pb); p.Controls.Add(b); Controls.Add(p); }