private unsafe void Draw() { CUIFrame frame; if (CUIApp.GetFrameCount() == 0) { CUIFrameMethods.Create(out frame, CUIFrameType.Main); CPadding padding; CCommonLib.CCommonInits.InitPaddingAll(out padding, 12); for (int row = 0; row < ROWS; row++) { for (int col = 0; col < COLS; col++) { var text = string.Format("({0},{1})", col, row); var btn = CUIViewMethods.Create(CUIViewType.Button); //btn.Text = Utils.StringToUshortArray(text); btn.Text = Utils.ToCharPointer(text); btn.TextSize = text.Length; btn.Size = new CSize() { Width = 190, Height = 50 }; btn.Size.Height = 50; btn.Style.FontColor = 0x00; btn.Style.BackColor = 0xFF;//字体没做好颜色混合,在灰度时,会出现白色内容,所以背景使用纯白色 btn.Style.BorderColor = 0xCC; btn.Style.BorderThickness = 1; btn.ActiveStyle.FontColor = 0x00; btn.ActiveStyle.BackColor = 0xEE; btn.ActiveStyle.BorderColor = 0x30; btn.ActiveStyle.BorderThickness = 1; btn.Location = new CPoint() { X = padding.Left + (padding.Left + btn.Size.Width) * col, Y = padding.Top + (padding.Top + btn.Size.Height) * row }; CUIFrameMethods.AddToFrame(ref frame, btn); } } CUIView button; CUIFrameMethods.GetChildView(frame, 0, out button); CUIFrameMethods.SetFocus(ref frame, button); CUIApp.Add(in frame); CUIFrameMethods.Refresh(ref frame); } else { CUIApp.GetActivedFrame(out frame); CUIFrameMethods.Refresh(ref frame); } RenderToPictureBox(); }
protected override void OnKeyUp(KeyEventArgs e) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); CUIFrame frame; CUIApp.GetActivedFrame(out frame); CUIView view; if (CUIFrameMethods.GetFocusedView(frame, out view)) { int index = CUIFrameMethods.GetChildViewIndex(frame, view); int col = index % COLS; int row = index / COLS; bool handle = true; switch (e.KeyCode) { case Keys.Up: { if (row > 0) { row--; } else { row = ROWS - 1; } break; } case Keys.Down: { if (row < ROWS - 1) { row++; } else { row = 0; } break; } case Keys.Left: { if (col > 0) { col--; } else { col = COLS - 1; } break; } case Keys.Right: { if (col < COLS - 1) { col++; } else { col = 0; } break; } default: handle = false; break; } if (handle) { CUIView next; CUIFrameMethods.GetChildView(frame, row * COLS + col, out next); CUIFrameMethods.SetFocus(ref frame, next); CUIFrameMethods.Refresh(ref frame); RenderToPictureBox(); } e.Handled = handle; } var time = stopwatch.ElapsedMilliseconds; }