using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter { /// /// 做成一个存在于右上角的菜单控件 /// public class TopRightMenuControl : FrameLayout { /// /// 框框控件 /// private FrameLayout frameLine = null; /// /// 行高度 /// private int RowHeight = 100; /// /// 行宽度 /// private int RowWidth = 310; /// /// 线的高度 /// private int LineHeight = 1; /// /// 菜单数计数 /// private int menuCount = 0; /// /// 做成一个存在于右上角的菜单控件 /// /// 父容器控件 /// 一共有几行 public TopRightMenuControl(FrameLayout frame, int i_RowCount) { //初始化画面的控件 this.InitFormControl(frame, i_RowCount); } /// /// 添加菜单行 /// /// 显示的文字 /// 单击菜单执行的事件 /// 调用action所传递的参数 /// 单击的时候,关闭菜单 public void AddRowMenu(string TextValue, Action action, object pramter = null, bool closeOnClick = true) { ViewNormalControl btnLine = null; if (this.menuCount > 0) { //画线 btnLine = new ViewNormalControl(Application.GetRealWidth(RowWidth), LineHeight); btnLine.Y = Application.GetRealHeight(RowHeight * this.menuCount) + this.menuCount * LineHeight; btnLine.BackgroundColor = UserCenterColor.Current.Line; frameLine.AddChidren(btnLine); } this.menuCount++; //显示文字 var btnText = new ViewNormalControl(RowWidth, RowHeight, true); btnText.Text = TextValue; btnText.TextAlignment = TextAlignment.Center; if (btnLine != null) { btnText.Y = btnLine.Bottom; } frameLine.AddChidren(btnText); btnText.MouseUpEventHandler += (sender, e) => { if (closeOnClick == true) { this.RemoveFromParent(); } if (action != null) { action(pramter); } }; } /// /// 初始化画面的控件 /// /// 父容器控件 /// 一共有几行 private void InitFormControl(FrameLayout frame, int i_RowCount) { this.BackgroundColor = UserCenterColor.Current.DialogBackColor; this.MouseUpEventHandler += (sender2, e2) => { //关闭自身 this.RemoveFromParent(); }; frame.AddChidren(this); //一个框 this.frameLine = new FrameLayout { X = Application.GetRealWidth(740), Y = Application.GetRealHeight(200), Width = Application.GetRealWidth(RowWidth), Height = Application.GetRealHeight(RowHeight * i_RowCount) + (i_RowCount - 1) * LineHeight, BackgroundColor = UserCenterColor.Current.White, Radius = 6, BorderColor = UserCenterColor.Current.TextFrameColor, BorderWidth = 1 }; this.AddChidren(frameLine); } } }