📄 notifywindowaddbuddyrequest.cs
字号:
namespace Imps.Client.Pc.BizControls.NotifyWindows.Templates
{
using Imps.Client;
using Imps.Client.Core;
using Imps.Client.Pc;
using Imps.Client.Pc.BizControls.NotifyWindows;
using Imps.Client.Resource;
using Imps.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.CompilerServices;
public class NotifyWindowAddBuddyRequest : NotifyWindowTemplateBase
{
protected NotifyWindowLabel contentLabel;
protected string contentText = "";
private const int MAXLENGTH = 5;
protected Image portraitImage;
public event NotifyWindowEventHandler ContentClick;
public NotifyWindowAddBuddyRequest(Imps.Client.Core.Contact contact, string desc, string mobileNo, Image backgroundImage)
{
if (string.IsNullOrEmpty(mobileNo))
{
base.title = this.GenerateTitle(contact.PersonalInfo.DisplayName);
this.contentText = this.GenerateMessage(contact.PersonalInfo.DisplayName, null);
}
else
{
base.title = this.GenerateTitle(desc);
this.contentText = this.GenerateMessage(desc, mobileNo);
}
base.BackgroundImageNotify = backgroundImage;
try
{
this.portraitImage = contact.PersonalInfo.Portrait;
}
catch
{
if (contact.PersonalInfo.Gender == Gender.Female)
{
this.portraitImage = ImpsPortrait.GetGirlPortrait(0x60, 0x60);
}
else
{
this.portraitImage = ImpsPortrait.GetBoyPortrait(0x60, 0x60);
}
}
base.InitContent();
}
private void contentLabel_Click(object sender, NotifyWindowEventArgs e)
{
this.OnContentClick(e);
}
protected override void CreateContent(NotifyWindowContent content)
{
Rectangle textRectangle = new Rectangle(content.Rectangle.X + 0x49, content.Rectangle.Y + ((content.Rectangle.Height - 60) / 2), 0x88, 60);
this.contentLabel = new NotifyWindowLabel(this.contentText, textRectangle);
this.contentLabel.Clickable = true;
this.contentLabel.Click += new NotifyWindowEventHandler(this.contentLabel_Click);
content.Elements.Add(this.contentLabel);
Rectangle rectangle = new Rectangle(content.Rectangle.X + 8, content.Rectangle.Y + ((content.Rectangle.Height - 60) / 2), 60, 60);
Bitmap bitmap = (Bitmap) ImpsResources.GetImage("Images.48.png");
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.DrawImage(this.portraitImage, 8, 8, 0x30, 0x30);
}
NotifyWindowImage image = new NotifyWindowImage(rectangle, bitmap);
content.Elements.Add(image);
}
protected string GenerateMessage(string desc, string mobileNo)
{
if (string.IsNullOrEmpty(mobileNo))
{
return string.Format("{0}\r\n想要添加您为好友", this.shrinkDesc(desc));
}
string text = this.shrinkDesc(desc);
if (text.Length > 2)
{
return string.Format("{0}\r\n(手机号{1})\r\n想要添加您为好友", text, mobileNo);
}
return string.Format("{0}(手机号{1})\r\n想要添加您为好友", text, mobileNo);
}
protected string GenerateTitle(string desc)
{
return string.Format("来自{0}的邀请", this.shrinkDesc(desc));
}
public void OnContentClick(NotifyWindowEventArgs e)
{
if (this.ContentClick != null)
{
this.ContentClick(this, e);
}
}
private string shrinkDesc(string desc)
{
string text = "";
float num = 100f;
float num2 = 0f;
List<object> list = EmoticonParser.ParseString(null, desc);
rich_string _string = new rich_string(desc);
Graphics g = Graphics.FromHdc(InnerWin32.GetWindowDC(base.Handle));
if (_string.MeasureText(g, this.Font).Width > num)
{
num -= g.MeasureString("...", this.Font).Width - 10f;
}
List<object>.Enumerator enumerator = list.GetEnumerator();
try
{
Label_0133:
while (enumerator.MoveNext())
{
object obj2 = enumerator.get_Current();
if (obj2 is Emoticon)
{
if ((num2 + 16f) >= num)
{
goto Label_014F;
}
text = text + ((Emoticon) obj2).Key;
num2 += 17f;
}
else if (obj2 is string)
{
string text2 = (string) obj2;
SizeF empty = SizeF.Empty;
for (int i = text2.Length; i > 0; i--)
{
string text3 = text2.Substring(0, i);
empty = g.MeasureString(text3, this.Font);
if ((num2 + empty.Width) <= num)
{
text = text + text3;
num2 += empty.Width + 1f;
goto Label_0133;
}
}
}
}
}
finally
{
enumerator.Dispose();
}
Label_014F:
if (num < 100f)
{
text = text + "...";
}
return text;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -