<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FGUI_Windows_Form%2FUser_Control</id>
		<title>Csharp/C Sharp/GUI Windows Form/User Control - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FGUI_Windows_Form%2FUser_Control"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/GUI_Windows_Form/User_Control&amp;action=history"/>
		<updated>2026-04-29T17:46:40Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/GUI_Windows_Form/User_Control&amp;diff=162&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/GUI_Windows_Form/User_Control&amp;diff=162&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/GUI_Windows_Form/User_Control&amp;diff=163&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/GUI_Windows_Form/User_Control&amp;diff=163&amp;oldid=prev"/>
				<updated>2010-05-26T11:33:42Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Creating an event for a component.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
public class CompoundControl : System.Windows.Forms.UserControl {&lt;br /&gt;
    public delegate Boolean ValueChangedEventHandler(int nValue);&lt;br /&gt;
    private System.Windows.Forms.Label label1;&lt;br /&gt;
    private System.Windows.Forms.ruboBox comboBox1;&lt;br /&gt;
    public event ValueChangedEventHandler Changed;&lt;br /&gt;
    public CompoundControl() {&lt;br /&gt;
        this.ruboBox1 = new System.Windows.Forms.ruboBox();&lt;br /&gt;
        this.label1 = new System.Windows.Forms.Label();&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        this.ruboBox1.DropDownWidth = 121;&lt;br /&gt;
        this.ruboBox1.Items.AddRange(new object[] {&amp;quot;A&amp;quot;,&amp;quot;B&amp;quot;,&amp;quot;C&amp;quot;,&amp;quot;F&amp;quot;,&amp;quot;G&amp;quot;,&amp;quot;N&amp;quot;});&lt;br /&gt;
        this.ruboBox1.Location = new System.Drawing.Point(24, 48);&lt;br /&gt;
        this.ruboBox1.Size = new System.Drawing.Size(200, 21);&lt;br /&gt;
        this.ruboBox1.Text = &amp;quot;comboBox1&amp;quot;;&lt;br /&gt;
        this.ruboBox1.SelectedIndexChanged += new System.EventHandler(this.OnSelectionIndexChange);&lt;br /&gt;
        this.label1.Location = new System.Drawing.Point(16, 24);&lt;br /&gt;
        this.label1.Text = &amp;quot;Select An Entry&amp;quot;;&lt;br /&gt;
        this.Controls.AddRange(new System.Windows.Forms.Control[] {&lt;br /&gt;
        this.ruboBox1,&lt;br /&gt;
        this.label1});&lt;br /&gt;
        this.Size = new System.Drawing.Size(240, 96);&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
    private void OnSelectionIndexChange(object sender,&lt;br /&gt;
        System.EventArgs e) {&lt;br /&gt;
        if (Changed != null)&lt;br /&gt;
            Changed(this.ruboBox1.SelectedIndex);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Form1 : System.Windows.Forms.Form {&lt;br /&gt;
    private System.ruponentModel.Container components = null;&lt;br /&gt;
    private CompoundControl compoundcomponent1 = null;&lt;br /&gt;
    public Form1() {&lt;br /&gt;
        this.rupoundcomponent1 = new CompoundControl();&lt;br /&gt;
        this.rupoundcomponent1.Location = new System.Drawing.Point(24, 50);&lt;br /&gt;
        this.rupoundcomponent1.Name = &amp;quot;compound1&amp;quot;;&lt;br /&gt;
        this.rupoundcomponent1.Size = new System.Drawing.Size(250, 100);&lt;br /&gt;
        this.rupoundcomponent1.Changed += new CompoundControl.ValueChangedEventHandler(OnChanged);&lt;br /&gt;
        this.ruponents = new System.ruponentModel.Container();&lt;br /&gt;
        this.Size = new System.Drawing.Size(300, 300);&lt;br /&gt;
        this.Controls.AddRange(new System.Windows.Forms.Control[]{this.rupoundcomponent1,});&lt;br /&gt;
    }&lt;br /&gt;
    private bool OnChanged(int nIndex) {&lt;br /&gt;
        MessageBox.Show(this, &amp;quot;New Index!&amp;quot; + nIndex);&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
    [STAThread]&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Application.Run(new Form1());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Define user control==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
public class Form1 : Form&lt;br /&gt;
{&lt;br /&gt;
    private ClockUserControl clockUserControl1;&lt;br /&gt;
  public Form1() {&lt;br /&gt;
        InitializeComponent();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
      private void InitializeComponent()&lt;br /&gt;
      {&lt;br /&gt;
         this.clockUserControl1 = new ClockUserControl();&lt;br /&gt;
         this.SuspendLayout();&lt;br /&gt;
         // &lt;br /&gt;
         // clockUserControl1&lt;br /&gt;
         // &lt;br /&gt;
         this.clockUserControl1.Location = new System.Drawing.Point(12, 12);&lt;br /&gt;
         this.clockUserControl1.Name = &amp;quot;clockUserControl1&amp;quot;;&lt;br /&gt;
         this.clockUserControl1.Size = new System.Drawing.Size(154, 74);&lt;br /&gt;
         this.clockUserControl1.TabIndex = 0;&lt;br /&gt;
         // &lt;br /&gt;
         // Clock&lt;br /&gt;
         // &lt;br /&gt;
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);&lt;br /&gt;
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;&lt;br /&gt;
         this.ClientSize = new System.Drawing.Size(178, 99);&lt;br /&gt;
         this.Controls.Add(this.clockUserControl1);&lt;br /&gt;
         this.Name = &amp;quot;Clock&amp;quot;;&lt;br /&gt;
         this.Text = &amp;quot;Clock&amp;quot;;&lt;br /&gt;
         this.ResumeLayout(false);&lt;br /&gt;
      }&lt;br /&gt;
  [STAThread]&lt;br /&gt;
  static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    Application.EnableVisualStyles();&lt;br /&gt;
    Application.Run(new Form1());&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class ClockUserControl : UserControl&lt;br /&gt;
{&lt;br /&gt;
      private System.Windows.Forms.Label displayLabel;&lt;br /&gt;
      private System.Windows.Forms.Timer clockTimer;&lt;br /&gt;
      &lt;br /&gt;
      public ClockUserControl() {&lt;br /&gt;
         InitializeComponent();&lt;br /&gt;
      }  &lt;br /&gt;
      private void clockTimer_Tick(object sender, EventArgs e) {&lt;br /&gt;
         displayLabel.Text = DateTime.Now.ToLongTimeString();&lt;br /&gt;
      }&lt;br /&gt;
      private void InitializeComponent()&lt;br /&gt;
      {&lt;br /&gt;
         this.displayLabel = new System.Windows.Forms.Label();&lt;br /&gt;
         this.clockTimer = new System.Windows.Forms.Timer( new System.ruponentModel.Container() );&lt;br /&gt;
         this.SuspendLayout();&lt;br /&gt;
         // &lt;br /&gt;
         // displayLabel&lt;br /&gt;
         // &lt;br /&gt;
         this.displayLabel.BackColor = System.Drawing.SystemColors.ActiveCaptionText;&lt;br /&gt;
         this.displayLabel.Font = new System.Drawing.Font( &amp;quot;Microsoft Sans Serif&amp;quot;, 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );&lt;br /&gt;
         this.displayLabel.Location = new System.Drawing.Point( 4, 10 );&lt;br /&gt;
         this.displayLabel.Name = &amp;quot;displayLabel&amp;quot;;&lt;br /&gt;
         this.displayLabel.Size = new System.Drawing.Size( 143, 52 );&lt;br /&gt;
         this.displayLabel.TabIndex = 0;&lt;br /&gt;
         this.displayLabel.Text = &amp;quot;12:55:55 AM&amp;quot;;&lt;br /&gt;
         this.displayLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;&lt;br /&gt;
         // &lt;br /&gt;
         // clockTimer&lt;br /&gt;
         // &lt;br /&gt;
         this.clockTimer.Enabled = true;&lt;br /&gt;
         this.clockTimer.Interval = 1000;&lt;br /&gt;
         this.clockTimer.Tick += new System.EventHandler( this.clockTimer_Tick );&lt;br /&gt;
         // &lt;br /&gt;
         // ClockUserControl&lt;br /&gt;
         // &lt;br /&gt;
         this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );&lt;br /&gt;
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;&lt;br /&gt;
         this.BackColor = System.Drawing.Color.White;&lt;br /&gt;
         this.Controls.Add( this.displayLabel );&lt;br /&gt;
         this.Name = &amp;quot;ClockUserControl&amp;quot;;&lt;br /&gt;
         this.Size = new System.Drawing.Size( 150, 72 );&lt;br /&gt;
         this.ResumeLayout( false );&lt;br /&gt;
      }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Draw a Custom Control==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
public class SimpleCustomControl : System.Windows.Forms.Control {&lt;br /&gt;
    public SimpleCustomControl() {&lt;br /&gt;
        InitializeComponent();&lt;br /&gt;
    }&lt;br /&gt;
    private void SimpleCustomControl_Paint(object sender, PaintEventArgs e) {&lt;br /&gt;
        Graphics g = e.Graphics;&lt;br /&gt;
        g.FillRectangle(Brushes.Yellow, ClientRectangle);&lt;br /&gt;
        g.DrawString(&amp;quot;Hello, world&amp;quot;, Font, Brushes.Black, 0, 0);&lt;br /&gt;
    }&lt;br /&gt;
    private void InitializeComponent() {&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.SimpleCustomControl_Paint);&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Form1 : Form {&lt;br /&gt;
    public Form1() {&lt;br /&gt;
        InitializeComponent();&lt;br /&gt;
    }&lt;br /&gt;
    private void InitializeComponent() {&lt;br /&gt;
        this.simpleCustomControl1 = new SimpleCustomControl();&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        this.simpleCustomControl1.Location = new System.Drawing.Point(12, 12);&lt;br /&gt;
        this.simpleCustomControl1.Size = new System.Drawing.Size(178, 110);&lt;br /&gt;
        this.simpleCustomControl1.Text = &amp;quot;simpleCustomControl1&amp;quot;;&lt;br /&gt;
        this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);&lt;br /&gt;
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;&lt;br /&gt;
        this.ClientSize = new System.Drawing.Size(292, 268);&lt;br /&gt;
        this.Controls.Add(this.simpleCustomControl1);&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
    private SimpleCustomControl simpleCustomControl1;&lt;br /&gt;
    [STAThread]&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Application.EnableVisualStyles();&lt;br /&gt;
        Application.Run(new Form1());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==subclass System.Windows.Forms.UserControl to create custom control==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
public class UserControl1 : System.Windows.Forms.UserControl {&lt;br /&gt;
    private System.ruponentModel.Container components = null;&lt;br /&gt;
    public UserControl1() {&lt;br /&gt;
        this.Name = &amp;quot;UserControl1&amp;quot;;&lt;br /&gt;
        this.Paint += new&lt;br /&gt;
         System.Windows.Forms.PaintEventHandler(this.OnPaint);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private void OnPaint(object sender,&lt;br /&gt;
         System.Windows.Forms.PaintEventArgs e) {&lt;br /&gt;
        e.Graphics.DrawString(&amp;quot;Hello world&amp;quot;, Font,&lt;br /&gt;
           new SolidBrush(Color.Blue), ClientRectangle);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Form1 : System.Windows.Forms.Form {&lt;br /&gt;
    private System.ruponentModel.Container components = null;&lt;br /&gt;
    private System.Windows.Forms.Label label1;&lt;br /&gt;
    private UserControl1 control1;&lt;br /&gt;
    public Form1() {&lt;br /&gt;
        this.control1 = new UserControl1();&lt;br /&gt;
        this.label1 = new System.Windows.Forms.Label();&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        this.control1.Location = new System.Drawing.Point(32, 48);&lt;br /&gt;
        this.control1.Size = new System.Drawing.Size(80, 24);&lt;br /&gt;
        this.label1.Location = new System.Drawing.Point(32, 24);&lt;br /&gt;
        this.label1.Size = new System.Drawing.Size(144, 24);&lt;br /&gt;
        this.label1.Text = &amp;quot;Custom Control:&amp;quot;;&lt;br /&gt;
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
        this.ClientSize = new System.Drawing.Size(292, 273);&lt;br /&gt;
        this.Controls.AddRange(new System.Windows.Forms.Control[] {&lt;br /&gt;
        this.label1,&lt;br /&gt;
        this.control1});&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
    [STAThread]&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Application.Run(new Form1());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The read-only property control.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
public class TimerCounter : System.Windows.Forms.UserControl {&lt;br /&gt;
    private System.Windows.Forms.Timer timer1;&lt;br /&gt;
    private System.ruponentModel.IContainer components;&lt;br /&gt;
    private int fCounter = 0;&lt;br /&gt;
    public int Counter {&lt;br /&gt;
        get {&lt;br /&gt;
            return fCounter;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public TimerCounter() {&lt;br /&gt;
        this.ruponents = new System.ruponentModel.Container();&lt;br /&gt;
        this.timer1 = new System.Windows.Forms.Timer(this.ruponents);&lt;br /&gt;
        this.timer1.Enabled = true;&lt;br /&gt;
        this.timer1.Interval = 1000;&lt;br /&gt;
        this.timer1.Tick += new System.EventHandler(this.OnTick);&lt;br /&gt;
        this.Name = &amp;quot;TimerCounter&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    private void OnTick(object sender, System.EventArgs e) {&lt;br /&gt;
        fCounter++;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Form1 : System.Windows.Forms.Form {&lt;br /&gt;
    private System.Windows.Forms.Label label1 = new System.Windows.Forms.Label();&lt;br /&gt;
    private System.Windows.Forms.Label CounterLabel;&lt;br /&gt;
    private System.Windows.Forms.Button Update;&lt;br /&gt;
    private System.ruponentModel.Container components = null;&lt;br /&gt;
    private TimerCounter counter;&lt;br /&gt;
    public Form1() {&lt;br /&gt;
        counter = new TimerCounter();&lt;br /&gt;
        this.CounterLabel = new System.Windows.Forms.Label();&lt;br /&gt;
        this.Update = new System.Windows.Forms.Button();&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        this.label1.Location = new System.Drawing.Point(32, 24);&lt;br /&gt;
        this.label1.Size = new System.Drawing.Size(48, 23);&lt;br /&gt;
        this.label1.Text = &amp;quot;Counter: &amp;quot;;&lt;br /&gt;
        this.CounterLabel.Location = new System.Drawing.Point(96, 24);&lt;br /&gt;
        this.CounterLabel.Size = new System.Drawing.Size(32, 23);&lt;br /&gt;
        this.Update.Location = new System.Drawing.Point(80, 72);&lt;br /&gt;
        this.Update.Text = &amp;quot;Update&amp;quot;;&lt;br /&gt;
        this.Update.Click += new System.EventHandler(this.Update_Click);&lt;br /&gt;
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
        this.ClientSize = new System.Drawing.Size(224, 133);&lt;br /&gt;
        this.Controls.AddRange(new System.Windows.Forms.Control[] {this.Update,this.CounterLabel,this.label1});&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
    [STAThread]&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Application.Run(new Form1());&lt;br /&gt;
    }&lt;br /&gt;
    private void Update_Click(object sender, System.EventArgs e) {&lt;br /&gt;
        CounterLabel.Text = counter.Counter.ToString();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>