[C#] Office Ribbon 按钮工具条 →→→→→进入此内容的聊天室

来自 , 2020-03-10, 写在 C#, 查看 134 次.
URL http://www.code666.cn/view/94aef384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Drawing.Drawing2D;
  9.  
  10. namespace RibbonDemo
  11. {
  12.     public partial class MainForm : RibbonForm
  13.     {
  14.         public MainForm()
  15.         {
  16.             InitializeComponent();
  17.             InitLists();
  18.             StartPosition = FormStartPosition.WindowsDefaultBounds;
  19.         }
  20.  
  21.         private Color GetRandomColor(Random r)
  22.         {
  23.             if (r == null)
  24.             {
  25.                 r = new Random(DateTime.Now.Millisecond);
  26.             }
  27.  
  28.             return Color.FromKnownColor((KnownColor)r.Next(1, 150));
  29.         }
  30.  
  31.         private void InitLists()
  32.         {
  33.             Image[] images = new Image[255];
  34.             RibbonProfessionalRenderer rend = new RibbonProfessionalRenderer();
  35.             BackColor = rend.ColorTable.RibbonBackground;
  36.             Random r = new Random();
  37.  
  38.             #region Color Squares
  39.             using (GraphicsPath path = RibbonProfessionalRenderer.RoundRectangle(new Rectangle(3, 3, 26, 26), 4))
  40.             {
  41.                 using (GraphicsPath outer = RibbonProfessionalRenderer.RoundRectangle(new Rectangle(0, 0, 32, 32), 4))
  42.                 {
  43.                     for (int i = 0; i < images.Length; i++)
  44.                     {
  45.                         Bitmap b = new Bitmap(32, 32);
  46.  
  47.                         using (Graphics g = Graphics.FromImage(b))
  48.                         {
  49.                             g.SmoothingMode = SmoothingMode.AntiAlias;
  50.  
  51.                             using (SolidBrush br = new SolidBrush(Color.FromArgb(255, i * (255 / images.Length), 0)))
  52.                             {
  53.                                 g.FillPath(br, path);
  54.                             }
  55.  
  56.                             using (Pen p = new Pen(Color.White, 3))
  57.                             {
  58.                                 g.DrawPath(p, path);
  59.                             }
  60.  
  61.                             g.DrawPath(Pens.Wheat, path);
  62.  
  63.                             g.DrawString(Convert.ToString(i + 1), Font, Brushes.White, new Point(10, 10));
  64.                         }
  65.  
  66.                         images[i] = b;
  67.  
  68.                         RibbonButton btn = new RibbonButton();
  69.                         btn.Image = b;
  70.                         lst.Buttons.Add(btn);
  71.                     }
  72.                 }
  73.             }
  74.  
  75.             //lst.DropDownItems.Add(new RibbonSeparator("Available styles"));
  76.             RibbonButtonList lst2 = new RibbonButtonList();
  77.  
  78.             for (int i = 0; i < images.Length; i++)
  79.             {
  80.                 RibbonButton btn = new RibbonButton();
  81.                 btn.Image = images[i];
  82.                 lst2.Buttons.Add(btn);
  83.             }
  84.             lst.DropDownItems.Add(lst2);
  85.             lst.DropDownItems.Add(new RibbonButton("Save selection as a new quick style..."));
  86.             lst.DropDownItems.Add(new RibbonButton("Erase Format"));
  87.             lst.DropDownItems.Add(new RibbonButton("Apply style..."));
  88.             #endregion
  89.  
  90.             #region Theme Colors
  91.  
  92.             RibbonButton[] buttons = new RibbonButton[30];
  93.             int square = 16;
  94.             int squares = 4;
  95.             int sqspace = 2;
  96.  
  97.             for (int i = 0; i < buttons.Length; i++)
  98.             {
  99.                 #region Create color squares
  100.                 Bitmap colors = new Bitmap((square + sqspace) * squares, square + 1);
  101.                 string[] colorss = new string[squares];
  102.                 using (Graphics g = Graphics.FromImage(colors))
  103.                 {
  104.                     for (int j = 0; j < 4; j++)
  105.                     {
  106.                         Color sqcolor = GetRandomColor(r);
  107.                         colorss[j] = sqcolor.Name;
  108.                         using (SolidBrush b = new SolidBrush(sqcolor))
  109.                         {
  110.                             g.FillRectangle(b, new Rectangle(j * (square + sqspace), 0, square, square));
  111.                         }
  112.                         g.DrawRectangle(Pens.Gray, new Rectangle(j * (square + sqspace), 0, square, square));
  113.                     }
  114.                 }
  115.                 #endregion
  116.  
  117.                 buttons[i] = new RibbonButton(colors);
  118.                 buttons[i].Text = string.Join(", ", colorss); ;
  119.                 buttons[i].MaxSizeMode = RibbonElementSizeMode.Medium;
  120.                 buttons[i].MinSizeMode = RibbonElementSizeMode.Medium;
  121.             }
  122.             RibbonButtonList blst = new RibbonButtonList(buttons);
  123.             blst.FlowToBottom = false;
  124.             blst.ItemsSizeInDropwDownMode = new Size(1, 10);
  125.             itemColors.DropDownItems.Insert(0, blst);
  126.             itemColors.DropDownResizable = true;
  127.  
  128.             #endregion
  129.  
  130.         }
  131.  
  132.         private void MainForm_Load(object sender, EventArgs e)
  133.         {
  134.  
  135.         }
  136.  
  137.         private void ribbonOrbOptionButton1_Click(object sender, EventArgs e)
  138.         {
  139.             Close();
  140.         }
  141.     }
  142. }

回复 "Office Ribbon 按钮工具条"

这儿你可以回复上面这条便签

captcha