Click here to Skip to main content
16,004,887 members
Home / Discussions / C#
   

C#

 
QuestionHelp required in dropdownlist Pin
kathiksourcecode29-Mar-07 3:11
kathiksourcecode29-Mar-07 3:11 
AnswerRe: Help required in dropdownlist Pin
Not Active29-Mar-07 4:04
mentorNot Active29-Mar-07 4:04 
QuestionRetrieve values into datagrid from database Pin
yaminilatha29-Mar-07 2:17
yaminilatha29-Mar-07 2:17 
AnswerRe: Retrieve values into datagrid from database Pin
Not Active29-Mar-07 4:33
mentorNot Active29-Mar-07 4:33 
QuestionSmart Custom Control Pin
Monty229-Mar-07 2:12
Monty229-Mar-07 2:12 
AnswerRe: Smart Custom Control Pin
Martin#29-Mar-07 2:35
Martin#29-Mar-07 2:35 
GeneralRe: Smart Custom Control Pin
Monty229-Mar-07 19:17
Monty229-Mar-07 19:17 
AnswerCustom Designer Pin
Patrick Etc.29-Mar-07 7:10
Patrick Etc.29-Mar-07 7:10 
What you need to do is create a custom designer for your control. Since a bit of code is worth a thousand words, I will stop talking and just post a drop dead simple example.

C#
<pre>using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms.Design;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.ComponentModel;

namespace WindowsApplication1
{
    [Designer(typeof(SomeControlDesigner))]
    public class SomeControl : Control
    {
        public SomeControl()
        {
            this.Size = new Size(100, 25);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            using (LinearGradientBrush brsh = new LinearGradientBrush(this.ClientRectangle,
                   Color.CornflowerBlue, Color.White, LinearGradientMode.Vertical))
            {
                e.Graphics.FillRectangle(brsh, e.ClipRectangle);
            }
        }
    }

    public class SomeControlDesigner : ControlDesigner
    {
        // This is the key step.  Using this override, you can pretty much completely
        // customize the way the control appears on the designer.  I've used this in my controls
        // to completely change the design-time appearance of controls to make their design 
        // capabilities more obvious.
        protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);
            using(SolidBrush brsh = new SolidBrush(Color.Red))
            {
                pe.Graphics.DrawString(this.Control.Location.ToString(), this.Control.Font, 
                                       brsh, pe.ClipRectangle.Location);
            }
        }
    }
}</pre> <br />
<br />
The OnPaint override is there just to make the point that this is a custom control.  You'll also need to add a reference to System.Design.dll.

GeneralRe: Custom Designer Pin
Monty229-Mar-07 19:18
Monty229-Mar-07 19:18 
GeneralRe: Custom Designer Pin
Martin#29-Mar-07 19:24
Martin#29-Mar-07 19:24 
QuestionC# Pin
munipax29-Mar-07 2:01
munipax29-Mar-07 2:01 
AnswerRe: C# Pin
Sathesh Sakthivel29-Mar-07 2:15
Sathesh Sakthivel29-Mar-07 2:15 
AnswerRe: C# Pin
dbrenth29-Mar-07 10:54
dbrenth29-Mar-07 10:54 
QuestionProperty grid Pin
sinosoidal29-Mar-07 1:56
sinosoidal29-Mar-07 1:56 
AnswerRe: Property grid Pin
netJP12L29-Mar-07 3:50
netJP12L29-Mar-07 3:50 
GeneralRe: Property grid Pin
sinosoidal29-Mar-07 3:58
sinosoidal29-Mar-07 3:58 
GeneralRe: Property grid Pin
netJP12L29-Mar-07 6:24
netJP12L29-Mar-07 6:24 
GeneralRe: Property grid Pin
sinosoidal29-Mar-07 6:28
sinosoidal29-Mar-07 6:28 
AnswerRe: Property grid Pin
visualhint16-Apr-07 3:31
visualhint16-Apr-07 3:31 
QuestionRemoving unknown event handlers - through Reflection? Pin
KeironN29-Mar-07 1:56
KeironN29-Mar-07 1:56 
QuestionHow to extract a particualar sub string from string in C# Pin
Mushtaque Nizamani29-Mar-07 1:00
Mushtaque Nizamani29-Mar-07 1:00 
AnswerRe: How to extract a particualar sub string from string in C# Pin
Martin#29-Mar-07 1:06
Martin#29-Mar-07 1:06 
AnswerRe: How to extract a particualar sub string from string in C# [modified, the link was for the italian page] Pin
CPallini29-Mar-07 1:41
mveCPallini29-Mar-07 1:41 
QuestionDatabase Pin
munipax29-Mar-07 0:49
munipax29-Mar-07 0:49 
AnswerRe: Database Pin
Sathesh Sakthivel29-Mar-07 1:45
Sathesh Sakthivel29-Mar-07 1:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.