Make ToolBar look like Windows Vista / 7 instead of classic

I want my application to look more like a native application than a .NET application, and I use .NET because of Visual Designer and C #.

I saw some native applications using the toolbar, which is very similar to the Vista / 7 menu.

See an example:

Windows Vista / 7 style

Some native applications, such as Notepad ++, Codeblocks, etc., use the same Vista / 7 style for toolbars. How can I do the same in C #? I know P / Invoke, so I need to know the methods to be used or an example.

I do not use ToolBarStrip, I use ToolBarbecause of naturalness. What can P / Invoke use to make the toolbar look like the one shown above (Vista / 7 look)?

EDIT: Based on this question , I need to do the same in P / Invoke instead of Win32.

+4
source share
3 answers

Notepad ++ uses both versions of its own toolbar elements in its source code. I would suggest that he chooses between them based on the version of Windows. You have already tried the .NET shell for the deprecated (ToolBar class), so that probably is not the one you like.

- Rebar control, "Coolbar". , Windows, () MSDN. .NET , . Codeproject.com, , , .

+3

, - . :  1.  2.  3.

, , ( , :)) , - !

:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;


public class Form_WOC : Form
{
    public enum LinePositions
    {
        TOP,
        BOTTOM,
        LEFT,
        RIGHT
    }
    private Rectangle TopGrip { get { return new Rectangle(0, 0, this.ClientSize.Width, _gripSize); } }
    private Rectangle LeftGrip { get { return new Rectangle(0, 0, _gripSize, this.ClientSize.Height); } }
    private Rectangle BottomGrip { get { return new Rectangle(0, this.ClientSize.Height - _gripSize, this.ClientSize.Width, _gripSize); } }
    private Rectangle RightGrip { get { return new Rectangle(this.ClientSize.Width - _gripSize, 0, _gripSize, this.ClientSize.Height); } }

    private Rectangle TopLeftGrip { get { return new Rectangle(0, 0, _gripSize, _gripSize); } }
    private Rectangle TopRightGrip { get { return new Rectangle(this.ClientSize.Width - _gripSize, 0, _gripSize, _gripSize); } }
    private Rectangle BottomLeftGrip { get { return new Rectangle(0, this.ClientSize.Height - _gripSize, _gripSize, _gripSize); } }
    private Rectangle BottomRightGrip { get { return new Rectangle(this.ClientSize.Width - _gripSize, this.ClientSize.Height - _gripSize, _gripSize, _gripSize); } }

    private List<Line> _lines = new List<Line>();

    private int _gripSize = 10;
    private const int
        HTLEFT = 10,
        HTRIGHT = 11,
        HTTOP = 12,
        HTTOPLEFT = 13,
        HTTOPRIGHT = 14,
        HTBOTTOM = 15,
        HTBOTTOMLEFT = 16,
        HTBOTTOMRIGHT = 17;

    protected override void WndProc(ref Message message)
    {
        base.WndProc(ref message);
        if (message.Msg == 0x84) // WM_NCHITTEST
        {
            var cursor = this.PointToClient(Cursor.Position);

            if (TopLeftGrip.Contains(cursor)) message.Result = (IntPtr)HTTOPLEFT;
            else if (TopRightGrip.Contains(cursor)) message.Result = (IntPtr)HTTOPRIGHT;
            else if (BottomLeftGrip.Contains(cursor)) message.Result = (IntPtr)HTBOTTOMLEFT;
            else if (BottomRightGrip.Contains(cursor)) message.Result = (IntPtr)HTBOTTOMRIGHT;

            else if (TopGrip.Contains(cursor)) message.Result = (IntPtr)HTTOP;
            else if (LeftGrip.Contains(cursor)) message.Result = (IntPtr)HTLEFT;
            else if (RightGrip.Contains(cursor)) message.Result = (IntPtr)HTRIGHT;
            else if (BottomGrip.Contains(cursor)) message.Result = (IntPtr)HTBOTTOM;
        }
    }
    public void drawLine(LinePositions pos, Color color, int point1, int point2)
    {
        _lines.Add(new Line(pos, color, point1, point2));
    }

    public void clearLines()
    {
        _lines.Clear();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        Pen pen = new Pen(Color.Red, 10);
        foreach (Line line in _lines)
        {
            pen.Color = line.Color;

            if (line.LinePosition == LinePositions.BOTTOM)
                e.Graphics.DrawLine(pen, line.X1, Height, line.X2, Height);
            else if (line.LinePosition == LinePositions.TOP)
                e.Graphics.DrawLine(pen, line.X1, 0, line.X2, 0);
            else if (line.LinePosition == LinePositions.RIGHT)       
                e.Graphics.DrawLine(pen, Width, line.Y1, Width, line.Y2);
            else
                e.Graphics.DrawLine(pen, 0, line.Y1, 0, line.Y2);
        }
    }

    public int GripSize
    {
        get { return _gripSize; }
        set { _gripSize = value; }
    }


    class Line
    {
        private int _x1;
        private int _x2;
        private int _y1;
        private int _y2;
        private Color _color;
        private LinePositions _positon;

        public Line(LinePositions position, Color color, int point1, int point2)
        {
            if (position == LinePositions.TOP || position == LinePositions.BOTTOM)
            {
                _x1 = point1;
                _x2 = point2;
            }
            else
            {
                _y1 = point1;
                _y2 = point2;
            }
            _color = color;
            _positon = position;
        }

        public Color Color { get { return _color; } }
        public int X1 { get { return _x1; } }
        public int X2 { get { return _x2; } }
        public int Y1 { get { return _y1; } }
        public int Y2 { get { return _y2; } }
        public LinePositions LinePosition { get { return _positon; } }
    }
}
-1

Source: https://habr.com/ru/post/1674924/


All Articles