1

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

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

这就是为什么我想改进它,我想知道是否可以从 Visual Studio 的工具箱中更改按钮的默认布局或任何其他表单?

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

4

3 回答 3

1

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

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

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

于 2011-07-28T13:28:07.293 回答
1

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

针对您问题的另一部分,我认为DevExpress提供了相当丰富的此类控件集合。

于 2011-07-28T13:22:29.667 回答
0

Make your own and enjoy.

Create a new class file and paste this code in: http://pastebin.com/cZ8xzTXX Then make a new class in the same file:

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

    }
}

As you study the code, you notice there are 3 main functions:

  • constructor
  • ColorHook()
  • PaintHook()

Constructor will define the variables.
ColorHook sets the variables ready to be used in PaintHook.
PaintHook is the function that draws all of your code.

I have also included close and minimize button. It is quite buggy when you move the form so I have restricted the window size in the PaintHook().

As you see in the Min/Close Classes there are MouseStates in order to change the Graphics on a MouseEvent:

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

A control will appear at the top of your toolbox.

于 2013-01-12T22:51:23.183 回答