Solved

C# Components

Posted on 2004-03-24
10
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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