Color Scroll Dialog Box : 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.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » GUI Windows Form » Dialog 




Color Scroll Dialog Box
  
using System;
using System.Drawing;
using System.Windows.Forms;
   
class ColorScrollDialogBox: Form
{
     Label[]      alabelName  = new Label[3];
     Label[]      alabelValue = new Label[3];
     VScrollBar[] avscroll    = new VScrollBar[3];
   
     public event EventHandler Changed;
   
     public ColorScrollDialogBox()
     {
          Color[] acolor = Color.Red, Color.Green, Color.Blue };
   
          for (int i = 0; i < 3; i++)
          {
               alabelName[inew Label();
               alabelName[i].Parent = this;
               alabelName[i].ForeColor = acolor[i];
               alabelName[i].Text = "&" + acolor[i].ToKnownColor();
               alabelName[i].TextAlign = ContentAlignment.MiddleCenter;
   
               avscroll[inew VScrollBar();
               avscroll[i].Parent = this;
               avscroll[i].SmallChange = 1;
               avscroll[i].LargeChange = 16;
               avscroll[i].Minimum  = 0;
               avscroll[i].Maximum = 255 + avscroll[i].LargeChange - 1;
               avscroll[i].ValueChanged +=  new EventHandler(ScrollOnValueChanged);
               avscroll[i].TabStop = true;
   
               alabelValue[inew Label();
               alabelValue[i].Parent = this;
               alabelValue[i].TextAlign = ContentAlignment.MiddleCenter;
          }
   
          OnResize(EventArgs.Empty);
     }
     public Color Color
     {
          get 
          
               return Color.FromArgb(avscroll[0].Value,
                                     avscroll[1].Value,
                                     avscroll[2].Value)
          }
          set 
          {
               avscroll[0].Value = value.R;
               avscroll[1].Value = value.G;
               avscroll[2].Value = value.B;
          }
     }
     protected override void OnResize(EventArgs ea)
     {
          base.OnResize(ea);
   
          int cx = ClientSize.Width;
          int cy = ClientSize.Height;
          int cyFont = Font.Height;
   
          for (int i = 0; i < 3; i++)
          {
               alabelName[i].Location = new Point(i * cx / 3, cyFont / 2);
               alabelName[i].Size = new Size(cx / 3, cyFont);
               avscroll[i].Location = new Point((* i + 1* cx / 12,* cyFont);
               avscroll[i].Size = new Size(cx / 6, cy - * cyFont);
               alabelValue[i].Location = new Point(i * cx / 3,cy - * cyFont / 2);
               alabelValue[i].Size = new Size(cx / 3, cyFont);
          }
     }
     void ScrollOnValueChanged(Object obj, EventArgs ea)
     {
          for (int i = 0; i < 3; i++)
               if((VScrollBarobj == avscroll[i])
                    alabelValue[i].Text = avscroll[i].Value.ToString();
          if (Changed != null)
               Changed(this, new EventArgs());
     }
}

   
class ModelessColorScroll: Form
{
     public static void Main()
     {
          Application.Run(new ModelessColorScroll());
     }
     public ModelessColorScroll()
     {
          ColorScrollDialogBox dlg = new ColorScrollDialogBox();
          
          dlg.Owner = this;
          dlg.Color = BackColor;
          dlg.Changed += new EventHandler(ColorScrollOnChanged);
          dlg.Show();
     }
     void ColorScrollOnChanged(object obj, EventArgs ea)
     {
          ColorScrollDialogBox dlg = (ColorScrollDialogBoxobj;
   
          BackColor = dlg.Color;
     }
}

   
  














Related examples in the same category
1.A dialog by user defined property
2.Color Fill dialog
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
6.Microsoft.Win32.OpenFileDialog/SaveFileDialog
7.Get a list of files from a folder based on the result of a FolderBrowserDialog
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.