is it possible to change the default layout forms from the toolbox in Visual studio?
我已经尝试在 google 中找到答案,但我可能没有使用正确的词来获得有用的链接。
我使用 Visual Studio 2008 中的工具箱设计了一个 C# GUI。问题是最后我的 GUI 并不好看,但功能非常适合我的应用程序。一些测试人员说我的 GUI 不吸引人或太无聊。
这就是我想要改进它的原因,我想知道是否可以从 Visual Studio 的工具箱中更改按钮的默认布局或任何其他表单?
或者有谁知道与 C# 兼容的 UI 设计的丰富集合库?
您始终可以派生控件并创建自己的控件。
如果您不喜欢 WinForms 或 WPF 外观/感觉,可以使用具有 WX.NET 的 WxWidgets Toolkit。
或者,如果您使用的是 Mono,您可以使用 GTK#。
AFAIK,您始终可以从基本控件派生,覆盖它们的部分/全部行为或视觉属性。
针对您问题的另一部分,我认为 DevExpress 提供了相当丰富的此类控件集合。
自己制作并享受。
创建一个新的类文件并将此代码粘贴到:
http://pastebin.com/cZ8xzTXX
然后在同一个文件中创建一个新类:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | public class ThemeBaseUI : ThemeContainer154 { private string _UnderInfo =""; public string SoftwareInfo { get { return _UnderInfo; } set { _UnderInfo = value; Invalidate(); } } public ThemeBaseUI() { BackColor = Color.WhiteSmoke; Font = new Font("Segoe UI", 10); SetColor("Border", Color.FromArgb(0, 114, 198)); SetColor("Text", Color.White); _UnderInfo = GetCopyright() +" " + GetCompany(); } Color Border; Brush TextBrush; protected override void ColorHook() { Border = GetColor("Border"); TextBrush = GetBrush("Text"); } private string GetCopyright() { Assembly asm = Assembly.GetExecutingAssembly(); object[] obj = asm.GetCustomAttributes(false); foreach (object o in obj) { if (o.GetType() == typeof(System.Reflection.AssemblyCopyrightAttribute)) { AssemblyCopyrightAttribute aca = (AssemblyCopyrightAttribute)o; return aca.Copyright; } } return string.Empty; } private string GetCompany() { Assembly asm = Assembly.GetExecutingAssembly(); object[] obj = asm.GetCustomAttributes(false); foreach (object o in obj) { if (o.GetType() == typeof(System.Reflection.AssemblyCompanyAttribute)) { AssemblyCompanyAttribute aca = (AssemblyCompanyAttribute)o; return aca.Company; } } return string.Empty; } protected override void PaintHook() { //Form G.Clear(Border); G.FillRectangle(new SolidBrush(BackColor), new Rectangle(0, 36, Width, Height - 36)); G.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, Height - 20, Width, Height)); G.DrawString(FindForm().Text, Font, TextBrush, new Point(35, 9)); G.DrawIcon(FindForm().Icon, new Rectangle(10, 10, 16, 16)); G.DrawString(_UnderInfo, Font, new SolidBrush(Color.DimGray), new Point(5, Height - 19)); //Close //Minimise //Minimise //G.DrawRectangle(new Pen(Color.White, 2), new Rectangle(Width - 73, 0, 24, 24)); WindowStateClose WSC = new WindowStateClose(); WSC.Location = new Point(Width - 21, 0); WSC.Size = new Size(20, 20); Controls.Add(WSC); WindowStateMin WSMa = new WindowStateMin(); WSMa.Location = new Point(Width - 59, 0); WSMa.Size = new Size(34, 23); Controls.Add(WSMa); Size SetSize = new Size(Width, Height); MinimumSize = SetSize; MaximumSize = SetSize; } private class WindowStateClose : ThemeControl154 { public WindowStateClose() { //Close Button SetColor("Cross", Color.White); SetColor("Button", Color.FromArgb(0, 114, 198)); SetColor("Border", Color.White); } Color ButtonColor; Pen Border, Cross; protected override void ColorHook() { Cross = GetPen("Cross", 2); Border = GetPen("Border"); ButtonColor = GetColor("Button"); } protected override void PaintHook() { G.Clear(ButtonColor); G.SmoothingMode = SmoothingMode.AntiAlias; switch (State) { case MouseState.None: G.DrawEllipse(Cross, new Rectangle(Width - 20, 4, 15, 15)); break; case MouseState.Over: G.DrawEllipse(Cross, new Rectangle(Width - 20, 4, 15, 15)); G.FillEllipse(new SolidBrush(Color.White), new Rectangle(Width - 17, 7, 9, 9)); break; case MouseState.Down: G.DrawEllipse(Cross, new Rectangle(Width - 20, 4, 15, 15)); G.FillEllipse(new SolidBrush(Color.White), new Rectangle(Width - 16, 8, 7, 7)); Environment.Exit(0); break; } } } private class WindowStateMin : ThemeControl154 { public WindowStateMin() { //Close Button SetColor("Min", Color.White); SetColor("Button", Color.FromArgb(0, 114, 198)); SetColor("Border", Color.White); } Color ButtonColor; Pen Border, Min; protected override void ColorHook() { Min = GetPen("Min", 3); Border = GetPen("Border"); ButtonColor = GetColor("Button"); } protected override void PaintHook() { G.Clear(ButtonColor); G.SmoothingMode = SmoothingMode.AntiAlias; switch (State) { case MouseState.None: G.DrawLine(Min, new Point(Width - 44, 12), new Point(20, 12)); break; case MouseState.Over: G.DrawLine(Min, new Point(Width - 44, 6), new Point(20, 6)); G.DrawLine(Min, new Point(Width - 44, 12), new Point(20, 12)); G.DrawLine(Min, new Point(Width - 44, 18), new Point(20, 18)); break; case MouseState.Down: G.DrawLine(Min, new Point(Width - 44, 12), new Point(20, 12)); this.FindForm().WindowState = FormWindowState.Minimized; break; } } } } |
当您研究代码时,您会注意到有 3 个主要功能:
- 构造函数
- 颜色挂钩()
- 油漆钩()
构造函数将定义变量。
ColorHook 设置准备好在 PaintHook 中使用的变量。
PaintHook 是绘制所有代码的函数。
我还包括关闭和最小化按钮。移动表单时会出现很多问题,因此我在 PaintHook() 中限制了窗口大小。
正如您在 Min/Close 类中看到的,有 MouseStates 以更改 MouseEvent 上的图形:
1 2 3 4 5 6 7 8 9 10 11 12 | switch (State) { case MouseState.None: //When mouse is off break; case MouseState.Over: //When mouse is over control break; case MouseState.Down: //When you click and hold break; } |
工具箱顶部会出现一个控件。