Oppure

Loading
11/10/16 16:49
Sevenjeak
Salve,

Sto cercando, da più di un giorno, anche cercando su internet, ma senza risultati, di creare un tema su file dll

Volendo creare un tema per il mio progetto, ho creato, nel progetto un file contenente questo codice:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace cnTheme
{
    abstract class cnControl : ContainerControl
    {
        protected Bitmap _Bitmap;
        protected Graphics _Graphics;

        protected SolidBrush brushTitle = new SolidBrush(Color.FromArgb(103, 112, 120));
        protected Color bgControl = Color.FromArgb(191, 203, 222);
        protected Color borderColor = SystemColors.ActiveBorder;
        protected Color borderColorActive = SystemColors.ActiveCaption;

        protected bool elementFocus, mouseHover, mousePress = false;
        protected int pointerX, pointerY;

        public cnControl()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }

        [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
        private static extern IntPtr CreateRoundRectRgn
        (
            int nLeftRect, // x-coordinate of upper-left corner
            int nTopRect, // y-coordinate of upper-left corner
            int nRightRect, // x-coordinate of lower-right corner
            int nBottomRect, // y-coordinate of lower-right corner
            int nWidthEllipse, // height of ellipse
            int nHeightEllipse // width Of ellipse
        );

        protected void DrawCorner(PaintEventArgs e, Border3DStyle style)
        {
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 10, 10));

            Rectangle borderCorner = ClientRectangle;

            ControlPaint.DrawBorder3D(e.Graphics, borderCorner, style);
        }
    }

    class cnForm : cnControl
    {
        private Point lastPoint;

        public cnForm()
        {
            Dock = DockStyle.Fill;
            BackColor = bgControl;
            Padding = new Padding(3, 25, 3, 3);
        }

        protected sealed override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            FindForm().BackColor = SystemColors.Control;
            FindForm().TransparencyKey = SystemColors.Control;
            FindForm().FormBorderStyle = 0;
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            this.lastPoint = e.Location;
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            pointerX = e.X;
            pointerY = e.Y;

            if (e.Button == MouseButtons.Left)
            {
                FindForm().Left += e.X - lastPoint.X;
                FindForm().Top += e.Y - lastPoint.Y;
            }

            Invalidate();
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);

            #region "Form Control Button"

            /* ---------------------- SET CLOSE BUTTON ------------------------ */
            Rectangle ButtonCloseRange = new Rectangle(Width - 23, 6, 15, 17);

            if (ButtonCloseRange.Contains(new Point(pointerX, pointerY)) && e.Button == MouseButtons.Left) FindForm().Close();

            /* ---------------------- SET MAXIMEZE BUTTON ------------------------ */
            Rectangle ButtonMinMaxRange = new Rectangle(Width - 52, 6, 13, 15);

            if (ButtonMinMaxRange.Contains(new Point(pointerX, pointerY)) && e.Button == MouseButtons.Left)
            {
                if (FindForm().WindowState == FormWindowState.Maximized)
                    FindForm().WindowState = FormWindowState.Normal;
                else
                    FindForm().WindowState = FormWindowState.Maximized;
            }

            /* ---------------------- SET MINIMEZE BUTTON ------------------------ */
            Rectangle ButtonMinRange = new Rectangle(Width - 76, 6, 13, 15);

            if (ButtonMinRange.Contains(new Point(pointerX, pointerY)) && e.Button == MouseButtons.Left) FindForm().WindowState = FormWindowState.Minimized;

            #endregion
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            _Bitmap = new Bitmap(Width, Height);
            _Graphics = Graphics.FromImage(_Bitmap);

            DrawCorner(e, Border3DStyle.Raised);

            _Graphics.DrawIcon(new Icon(FindForm().Icon, 10, 10), 10, 10);
            _Graphics.DrawString(FindForm().Text, new Font("arial", 10), brushTitle, 28, 10);

            #region "Control button"

            /* ---------------------- SET CLOSE BUTTON ------------------------ */
            Rectangle ButtonCloseRange = new Rectangle(Width - 26, 6, 13, 15);
            //_Graphics.DrawRectangle(New Pen(New SolidBrush(Color.Red)), ButtonCloseRange);

            if (ButtonCloseRange.Contains(new Point(pointerX, pointerY)))
                _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.close_hover), new Point(Width - 25, 9));
            else
                _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.close), new Point(Width - 25, 9));

            /* ---------------------- SET MAXIMEZE BUTTON -------------------- */
            Rectangle ButtonMinMaxRange = new Rectangle(Width - 52, 6, 13, 15);
            //_Graphics.DrawRectangle(New Pen(New SolidBrush(Color.Orange)), ButtonMinMaxRange);

            if (ButtonMinMaxRange.Contains(new Point(pointerX, pointerY)))
                _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.minmax_hover), new Point(Width - 50, 9));
            else
                _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.minmax), new Point(Width - 50, 9));


            /* ---------------------- SET MINIMEZE BUTTON -------------------- */
            Rectangle ButtonMinRange = new Rectangle(Width - 76, 6, 13, 15);
            //_Graphics.DrawRectangle(New Pen(New SolidBrush(Color.Orange)), ButtonMinRange);

            if (ButtonMinRange.Contains(new Point(pointerX, pointerY)))
                _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.minimeze_hover), new Point(Width - 75, 9));
            else
                _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.minimeze), new Point(Width - 75, 9));

            #endregion

            e.Graphics.DrawImage(_Bitmap, 0, 0);
            _Bitmap.Dispose();
            _Graphics.Dispose();
        }
    }

    class cnMainTabs : TabControl
    {
        private Bitmap _Bitmap = null;
        private Graphics _Graphics = null;

        public cnMainTabs()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

            Dock = DockStyle.Fill;
        }

        protected override void CreateHandle()
        {
            base.CreateHandle();

            Location = new Point(7, 30);
            Size = new Size(FindForm().Width - 13, FindForm().Height - 35);
            SizeMode = TabSizeMode.Fixed;
            ItemSize = new Size(212, 27);
            DrawMode = TabDrawMode.OwnerDrawFixed;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            _Bitmap = new Bitmap(Width, Height);
            _Graphics = Graphics.FromImage(_Bitmap);

            _Graphics.Clear(Color.FromArgb(191, 203, 222));

            Point CornerPoint = new Point(DisplayRectangle.X - 1, DisplayRectangle.Y - 1);
            Size CornerSize = new Size(DisplayRectangle.Width + 2, DisplayRectangle.Height + 2);

            _Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, 150, 150)), new Rectangle(CornerPoint, CornerSize));

            for (int i = 0; i < TabCount; i++)
            {

                if (i == SelectedIndex)
                    _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.header_tab), new Point(GetTabRect(i).X, GetTabRect(i).Y));
                else
                    _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.header_tab_inactive), new Point(GetTabRect(i).X, GetTabRect(i).Y));

                if (TabPages[i].Text != "")
                {
                    String tabText = "";

                    if (TabPages[i].Text.Length > 25)
                        tabText = TabPages[i].Text.Substring(0, 25);
                    else
                        tabText = TabPages[i].Text;

                    _Graphics.DrawString(tabText, new Font("Segoe UI", 9), new SolidBrush(Color.Gray), GetTabRect(i).X + 30, GetTabRect(i).Y + 5);
                }
                else
                {
                    _Graphics.DrawString("Nuova scheda", new Font("Segoe UI", 9), new SolidBrush(Color.Gray), GetTabRect(i).X + 30, GetTabRect(i).Y + 5);
                }
            }

            e.Graphics.DrawImage(_Bitmap, 0, 0);

            _Graphics.Dispose();
            _Bitmap.Dispose();
        }
    }

    class cnPageBar : cnControl
    {

        public cnPageBar()
        {
            Dock = DockStyle.Top;
            BackColor = Color.FromArgb(230, 230, 230);
            Size = new Size(968, 30);
        }

        protected override void OnPaint(PaintEventArgs e)
        {

        }
    }

    class cnBarButton : cnControl
    {
        private Image _image;

        public Image image
        {
            get
            {
                return _image;
            }
            set
            {
                _image = value;
                Invalidate();
            }
        }

        public cnBarButton()
        {
            Size = new Size(26, 23);
            BackColor = Color.FromArgb(230, 230, 230);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            _Bitmap = new Bitmap(Height, Width);
            _Graphics = Graphics.FromImage(_Bitmap);

            _Graphics.DrawImage(new Bitmap(_image, 16, 16), 3, 3);

            if (mouseHover && Enabled)
                DrawCorner(e, Border3DStyle.Raised);

            e.Graphics.DrawImage(_Bitmap, 0, 0);

            _Graphics.Dispose();
            _Bitmap.Dispose();
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseHover(e);

            mouseHover = true;
            Invalidate();
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            mouseHover = false;
            Invalidate();
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            BackColor = Color.FromArgb(220, 220, 220);
            mousePress = true;
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            BackColor = Color.FromArgb(230, 230, 230);
            mousePress = false;
        }
    }

    class cnAdressBar : cnControl
    {
        private Icon iconBar;
        public TextBox textBar = new TextBox();

        public Icon Icon
        {
            get
            {
                return iconBar;
            }
            set
            {
                iconBar = value;
                Invalidate();
            }
        }

        public override String Text
        {
            get
            {
                return textBar.Text;
            }
            set
            {
                textBar.Text = value;
            }
        }

        public cnAdressBar()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }

        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            textBar.Dock = DockStyle.Fill;

            Controls.Add(textBar);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            _Bitmap = new Bitmap(Width, Height);
            _Graphics = Graphics.FromImage(_Bitmap);

            e.Graphics.DrawImage(_Bitmap, 0, 0);

            _Graphics.Dispose();
            _Bitmap.Dispose();
        }
    }
}


Che funziona benissimo, infatti, una volta compilato il codice mi vengono visualizzati i due componenti da me creati nella barra degli strumenti.

Successivamente, siccome vorrei inserire i seguenti componenti anche in altri progetti, ho pensato, di inserire questo codice in una libreria di classi, successivamente compilato in un file DLL, ma, una volta inserito in altri progetti, tramite riferimento, non mi viene creato nessun nuovo elemento nella casella degli strumenti, anche dopo aver compilato il progetto, come mai?

Non so se mi sono spiegato.

EDIT:

Quando vado a selezionale la dll per aggiungere nuovi elementi nella barra degli strumenti, mi dice semplicemente che, la dll selezionato non ha nessun elemento da poter aggiungere alla barra degli strumenti.
Ultima modifica effettuata da Sevenjeak 13/10/16 9:51
aaa
14/10/16 6:39
Thejuster
Prova ad usare un componente.

Normalmente si dovrebbe creare un componente ed un Interfaccia.


Questo può esserti di aiuto
msdn.microsoft.com/en-us/library/…
mire.forumfree.it/ - Mire Engine
C# UI Designer
15/10/16 20:33
Sevenjeak
Non so se era quello che intendevi, ma ho provato ad aggiungere semplicemente l'interfaccia alla classe astratta cnControl, modificando la definizione della classe astratta in questo modo:

abstract class cnControl : ContainerControl, IComponent


Ma il risultato è lo stesso, non funziona.

Era quello che intendevi te? o intendevi modificare il codice in altro modo?

Ho provato anche ad implementare l'interfaccia direttamente nelle classi che estendono la classe astratta, anche se credo sia la stessa cosa, ed il risultato non cambia uguale.

Non saprei proprio come risolvere, ho provato a cercare su internet il codice sorgente di un thema su un file dll, ma niente, trovo solo temi da aggiungere il un file all'interno del progetto, che, come il mio, non funzionano, se inserito in una dll.
Ultima modifica effettuata da Sevenjeak 15/10/16 20:35
aaa
18/10/16 6:43
Thejuster
La cosa è molto strana concordo.

Ho provato anche io a fare un qualcosa del genere.
Ma i controlli container nella libreria non vengono visualizzati nella barra degli strumenti.
cosa al quanto strana. e non poco..
mire.forumfree.it/ - Mire Engine
C# UI Designer
19/10/16 8:42
Sevenjeak
In effetti si, anche perché la classe cnMainTabs estende la classe TabControl, il qui elemento è già presente nella casella degli strumenti.

Ho provato anche creando un nuovo progetto libreria di classi aggiungendo all'interno dei Controlli utenti, creando cosi il tutto utilizzando l'interfaccia grafica è no da codice, utilizzando la stessa procedura che si vede in questo video:

youtube.com/…

ma niente, proprio non va, eppure, il tema, fin quando sta nel progetto me lo applica, è quando esporto il tutto in un file dll è che non funziona.

Non saprei che dire, intanto sto cercando altre soluzione su internet, è possibile che sia l'ide che uso? uso Visual Studio Express 2015, in particolare la dll è scritta con Visual C# 2015
Ultima modifica effettuata da Sevenjeak 19/10/16 8:46
aaa
19/10/16 12:23
Thejuster
no io ho vs2010 è ho lo stesso e medesimo problema.

inserendo il file come classe all'interno di un progetto funziona.
Ma esportandolo come libreria non funziona.

forse serve qualche parametro durante la compilazione non saprei.
E' la prima volta che mi capita qualcosa del genere 8-|
mire.forumfree.it/ - Mire Engine
C# UI Designer
28/10/16 10:25
Sevenjeak
Navigando su internet, ho trovato questo progetto:

github.com/IgnaceMaes/…

Premetto che ancora non ho visto bene tutto il codice, ma sto cercando di capire cosa sbaglio nel mio codice analizzando lo skin nel link qui sopra, spero di capirci qualche cosa :)

RISOLTO:

A Quando pare il codice andava benissimo, infatti aggiungendo il tema linkato qui sopra nello stesso modo ( tasto destro su la toolbox > seleziona elemento ) non mi funziona, ma se, trascino la dll ( drag and drop ) direttamente sulla toolbook mi funziona benissimo, lo stesso vale per la libreria fatta da me ( senza aver dovuto mettere mano sul codice ), qualcuno di voi sa spiegare come mai con il drag and drop funzioni e dal menu seleziona elementi non funzioni?

In ogni caso, grazie a tutti per le risposte.
Ultima modifica effettuata da Sevenjeak 03/11/16 8:52
aaa