Custom Controls into one DLL

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I want to have some controls in one dll.
My code is this:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;

namespace JustusControls
{
public partial class btnControl : System.Windows.Forms.Label
{
public btnControl()
{
InitializeComponent();

this.Size = new Size(111, 33);
}




/* Rounded corners */

[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 override void OnMouseEnter(EventArgs e)
{
Graphics lol = this.CreateGraphics();
lol.SmoothingMode = SmoothingMode.AntiAlias;
LinearGradientBrush gradient = new LinearGradientBrush(new Rectangle(2, 1, this.Width + 1, this.Height + 1), Color.FromArgb(0, 191, 230), Color.FromArgb(0, 200, 255), LinearGradientMode.Vertical);
lol.FillRectangle(gradient, 1, 0, this.Width - 2, this.Height + 1);
lol.DrawString(this.Text, base.Font, new SolidBrush(base.ForeColor), this.Width / 5 - 3, Height / 4);
base.OnMouseEnter(e);
}


protected override void OnMouseLeave(EventArgs t)
{
Graphics lol2 = this.CreateGraphics();

base.ForeColor = Color.White;
lol2.SmoothingMode = SmoothingMode.AntiAlias;
LinearGradientBrush gradient = new LinearGradientBrush(new Rectangle(2, 1, this.Width + 1, this.Height + 1), Color.FromArgb(135, 206, 250), Color.FromArgb(0, 191, 255), LinearGradientMode.Vertical);
lol2.FillRectangle(gradient, 1, 0, this.Width - 2, this.Height + 1);
Pen pijl = new Pen(Color.Gray);
pijl.StartCap = LineCap.ArrowAnchor;
lol2.DrawString(this.Text, base.Font, new SolidBrush(base.ForeColor), this.Width / 5 - 3, Height / 4);
Pen pen = new Pen(Color.Transparent);
lol2.DrawRectangle(pen, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
base.OnMouseLeave(t);
}



protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
this.AutoSize = false;
base.ForeColor = Color.White;
this.Font = new Font("Arial", 11.0f);
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0,
Width - 2, Height - 2, 13, 13));
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
LinearGradientBrush gradient = new LinearGradientBrush(new Rectangle(2, 1, this.Width + 1, this.Height + 1), Color.FromArgb(135, 206, 250), Color.FromArgb(0, 191, 255), LinearGradientMode.Vertical);
e.Graphics.FillRectangle(gradient, 1, 0, this.Width - 2, this.Height + 1);
Pen pijl = new Pen(Color.Gray);
pijl.StartCap = LineCap.ArrowAnchor;
e.Graphics.DrawString(this.Text, base.Font, new SolidBrush(base.ForeColor), this.Width / 5 - 3, Height / 4);
Pen pen = new Pen(Color.Transparent);
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
}
}

public partial class frmControl : System.Windows.Forms.Form
{
public frmControl()
{
InitializeComponent();


}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen pen = new Pen(Color.Red);
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, this.Width - 2, this.Height - 2));
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.FromArgb(60, 179, 113), Color.FromArgb(46, 139, 87), LinearGradientMode.ForwardDiagonal);
e.Graphics.FillEllipse(brush, new Rectangle(0, 0, this.Width, this.Height));
}
}
}


And the designer code is this:namespace JustusControls
{
partial class btnControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();

}

#endregion
}

partial class frmControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();

}

#endregion
}
}


But when I apply the dll to the toolbox in a new project only the btnControl shows up??
How do I fix this. Thanks :)

View the full article
 
Back
Top