Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Components

Posted on 2004-03-24
10
Medium Priority
?
152 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
9 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

783 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