Color Fill dialog : Dialog « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » DialogScreenshots 
Color Fill dialog
 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class ColorFillDialogBox: Form
{
     GroupBox grpbox = new GroupBox();
     CheckBox chkbox = new CheckBox();
   
     public ColorFillDialogBox()
     {
          string[] astrColor = "Black""Blue""Green""Cyan",   
                                 "Red""Magenta""Yellow""White"};
   
          grpbox.Parent   = this;
          grpbox.Text     = "Color";
          grpbox.Location = new Point(88);
          grpbox.Size     = new Size(9612 (astrColor.Length + 1));
   
          for (int i = 0; i < astrColor.Length; i++)
          {
               RadioButton radiobtn = new RadioButton();
               radiobtn.Parent      = grpbox;
               radiobtn.Text        = astrColor[i];
               radiobtn.Location    = new Point(812 (i + 1));
               radiobtn.Size        = new Size(8010);
          }
          chkbox.Parent   = this;
          chkbox.Text     = "Fill Ellipse";
          chkbox.Location = new Point(8, grpbox.Bottom + 4);
          chkbox.Size     = new Size(8010);
   
          Button btn   = new Button();
          btn.Parent   = this;
          btn.Text     = "OK";
          btn.Location = new Point(8, chkbox.Bottom + 4);
          btn.Size     = new Size(4016);
          btn.DialogResult = DialogResult.OK;
          AcceptButton = btn;
   
          btn  = new Button();
          btn.Parent   = this;
          btn.Text     = "Cancel";
          btn.Location = new Point(64, chkbox.Bottom + 4);
          btn.Size     = new Size(4016);
          btn.DialogResult = DialogResult.Cancel;
          CancelButton = btn;
   
          ClientSize = new Size(112, btn.Bottom + 8);
          AutoScaleBaseSize = new Size(48);
     }
     public Color Color
     {
          get 
          
               for (int i = 0; i < grpbox.Controls.Count; i++)
               {
                    RadioButton radiobtn = (RadioButtongrpbox.Controls[i];
                    if (radiobtn.Checked)
                         return Color.FromName(radiobtn.Text);
               }
               return Color.Black;
               
          }  
          set 
          
               for (int i = 0; i < grpbox.Controls.Count; i++)
               {
                    RadioButton radiobtn = (RadioButtongrpbox.Controls[i];
   
                    if (value == Color.FromName(radiobtn.Text))
                    {
                         radiobtn.Checked = true;
                         break;
                    }
               }
          }
     }
     public bool Fill
     {
          get return chkbox.Checked; }
          set chkbox.Checked = value; }
     }
}

   
class DrawOrFillEllipse: Form
{
     Color colorEllipse = Color.Red;
     bool  bFillEllipse = false;
   
     public static void Main()
     {
          Application.Run(new DrawOrFillEllipse());
     }
     public DrawOrFillEllipse()
     {
          ResizeRedraw = true;
          Menu = new MainMenu();
          Menu.MenuItems.Add("&Options");
          Menu.MenuItems[0].MenuItems.Add("&Color..."new EventHandler(MenuColorOnClick));
     }
     void MenuColorOnClick(object obj, EventArgs ea)
     {
          ColorFillDialogBox dlg = new ColorFillDialogBox();
   
          dlg.Color = colorEllipse;
          dlg.Fill  = bFillEllipse;
   
          if (dlg.ShowDialog() == DialogResult.OK)
          {
               colorEllipse = dlg.Color;
               bFillEllipse = dlg.Fill;
               Invalidate();
          }
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics  grfx = pea.Graphics;
          Rectangle rect = new Rectangle(005050);
          if(bFillEllipse)
               grfx.FillEllipse(new SolidBrush(colorEllipse), rect);
          else
               grfx.DrawEllipse(new Pen(colorEllipse), rect);
     }
}

 
Related examples in the same category
1.A dialog by user defined property
2.Color Scroll Dialog Box
3.Italic User Message Dialog: your own dialog
4.Use DialogResult property in Form
5.Define your own dialog box and get user inputDefine your own dialog box and get user input
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.