[C#] Aiuto esportazione tema su libreria di classe ( dll )

Sevenjeak

Utente Attivo
27 Nov 2012
81
2
8
36
sevenjeak.altervista.org
Salve,

Sto, da qualche giorno, rifacendo un mio browser multi scheda, che tempo fa, quando era ancora aperto megaupload, avevo realizzato in vb.net.

Ora, piuttostoc che ripartire dal browser che avevo fatto in vb.net, ne sto progettando un'altro da zero, ma in c#, con un tema personalizzato, quindi, ho subito iniziato a generare il tema del mio programma, in un file contenuto nello stesso progetto, posto qui sotto il codice del tema, almeno quello che ho realizzato fino ad ora:

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;

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(CrossNet.Properties.Resources.close_hover), new Point(Width - 25, 9));
    else
            _Graphics.DrawImage(new Bitmap(CrossNet.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(CrossNet.Properties.Resources.minmax_hover), new Point(Width - 50, 9));
    else
            _Graphics.DrawImage(new Bitmap(CrossNet.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(CrossNet.Properties.Resources.minimeze_hover), new Point(Width - 75, 9));
    else
            _Graphics.DrawImage(new Bitmap(CrossNet.Properties.Resources.minimeze), new Point(Width - 75, 9));

    #endregion

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


}
}

Premettendo che, il codice lo scritto personalmente io, escluso la parte del DLLImport, quello lo presa da internet.

Cmq, il codice qui sopra non mi da nessun problema, fino a quando rimane nello stesso progetto, ma se, voglio inserirlo in una libreria di classe mi restituisce alcuni errori, che vi allego in un file di testo qui sotto, visto che non me le fa postare, mi dice che il messaggio che vi elenco in questo link:

https://mega.nz/#!NwExWYZR!i6IopcLbINDpjSUakNLQCqOq5cxbLvvNE2o4ZBy4f1Q

Dato che, scrivendoli nella discussione non mi fa postare il tutto per la lunghezza del messaggio.

Non so se ho spiegato bene il mio problema, ma come potrei risolvere tutto ciò?
 

Discussioni simili