是否可以从Visual Studio中的工具箱更改默认布局表单?

时间:2011-07-28 13:13:01

标签: c# winforms visual-studio-2008 toolbox

我已经尝试在谷歌中找到答案,但我可能没有使用正确的单词来获得有用的链接。

我使用Visual Studio 2008中的工具箱设计了一个C#GUI。最后我的GUI看起来并不好看,但功能非常适合我的应用。一些测试人员说我的GUI没有吸引力或太无聊。

这就是为什么我想改进它,我想知道是否可以更改例如视觉工作室中工具箱中的按钮或任何其他形式的默认布局?

或者有没有人知道用于与C#兼容的UI设计的丰富集合库?

3 个答案:

答案 0 :(得分:1)

AFAIK,您始终可以从基本控件派生,覆盖它们的部分/全部行为或视觉属性。

在回答问题的其他部分时,我认为DevExpress提供了相当丰富的此类控件。

答案 1 :(得分:1)

您始终可以派生控件并创建自己的控件。

如果您不喜欢WinForms或WPF外观,可以使用具有WX.NET的WxWidgets Toolkit。

或者,如果您使用的是Mono,则可以使用GTK#

答案 2 :(得分:0)

自己做并享受。

创建一个新的类文件并将此代码粘贴到: http://pastebin.com/cZ8xzTXX 然后在同一个文件中创建一个新类:

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;
            }
        }

    }
}

在学习代码时,您会注意到有三个主要功能:

  • 构造
  • ColorHook()
  • PaintHook()

构造函数将定义变量 ColorHook设置准备在PaintHook中使用的变量 PaintHook是绘制所有代码的函数。

我还包括关闭和最小化按钮。移动表单时非常错误,因此我在PaintHook()中限制了窗口大小。

正如您在Min / Close Classes中看到的那样,有MouseStates可以更改MouseEvent上的Graphics:

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;
        }

控件将显示在工具箱的顶部。