Solved

C# Components

Posted on 2004-03-24
10
144 Views
Last Modified: 2010-04-15
Hi Guys,

im in need of writing a small component, but have no idea where to start i just to to create a small box, can anyone help?

0
Comment
Question by:ziwez0
  • 4
  • 4
10 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10665817
ASP.NET or Windows?
0
 
LVL 2

Author Comment

by:ziwez0
ID: 10665826
windows
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10665842
In your project right click, select Add new item, select to create a new custom or user control. The difference is that user controls are combination of already existing controls (just align them, make them act together, etc.) while the custom control is a control you should make yourself.

The user control inherits from the class UserControl in System.Windows.Forms namespace while the custom control inherits directly from the Control class in the same namespace.
0
 
LVL 2

Author Comment

by:ziwez0
ID: 10665897
ok, so i want to use the custom control,

i know that i have to use the System.Design , System.Drawing,

basicley i want to design my own rectangle box with the following properties
.ColumnWidth =100
.ColumnHeight =200
.BackColor = SystemColors.Desktop
.BorderColor = Colours.Ivory

then save it as a dll and to be able to use it with another piece of code where i can add it on to the contorl box



0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 20

Expert Comment

by:TheAvenger
ID: 10666337
You need to make the project a class library then and compile it to a dll. Then you can add the control to the toolbox.

You also need to override the OnPaint method of the Control class. For more info see Control.OnPaint in MSDN
0
 
LVL 2

Author Comment

by:ziwez0
ID: 10666397
yep done that

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;

namespace COM.PROJECT.MENU
{
      public class Structure : Control
      {
            private int mainoutlineColumnWidth;
            private int mainoutlineColumnHeight;
            private Color mainoutlineBackColor;
            private Color mainoutlineBorderColor;
      
            public Structure()
            {
                  SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |      ControlStyles.Opaque | ControlStyles.DoubleBuffer, true);
                  SetAllDefaultPropertyValues();
                  Enabled = true;
            }

            private void SetAllDefaultProperyValues()
            {
                  mainoutlineColumnWidth =150;
                  mainoutlineColumnHeight = 100;
                  mainoutlineBackColor = SystemColors.Desktop;
                  mainoutlineBorderColor = SystemColors.ControlDarkDark;

            }
            protected virtual void DrawAndFillControlRect(Graphics g)
            {
                  Brush b = new SolidBrush(BackColor);
                  try
                  {
                        Rectangle Rect = new Rectangle(0,0,ClientRectangle.Width -1,ClientRectangle.Height -1);
                        g.FillRectangle(b,Rect);
                  }
                  finally
                  {
                        b.Dispose();
                  }
            }
            protected virtual void DrawBorder(Graphics g)
            {
                  ControlPaint.DrawBorder(g,ClientRectangle,SystemColors.WindowFrame,ButtonBorderStyle.Solid);
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                  DrawControl(e.Graphics);
            }
            protected virtual void DrawHeader(Graphics g)
            {
                  
                  Brush b = new SolidBrush(mainoutline.BackColor);
                  try
                  {
                        Rectangle Rect = new Rectangle();
                        
                        g.FillRectangle(b,Rect);
                        g.DrawLine(mainoutlineColumnHeight);
                        g.DrawLine(mainoutlineColumnWidth);
                        
                  }
            }
      }
//im missing somehting tho
}
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10666718
I think you should call base.OnPaint before your own drawing (although I am not sure)

Why do you think you miss something?
0
 
LVL 2

Author Comment

by:ziwez0
ID: 10666884
protected override void OnPaint(PaintEventArgs e)
            {
                  DrawControl(e.Graphics);
            }

            protected virtual void DrawControl(Graphics g)
            {
                  Brush b = new SolidBrush(SystemColors.Desktop);
                  try
                  {
                        Rectangle Rect = new Rectangle(0,0,ClientRectangle.Width -1,ClientRectangle.Height -1);
                        g.FillRectangle(b,Rect);
                  }
                  finally
                  {
                        b.Dispose();
                  }

thanks but have sorted it
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 11266129
PAQed, with points refunded (200)

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now