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:
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.
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