Using GroupBoxes and Panels to hold buttons

image_pdfimage_print


   

   using System;
   using System.Drawing;
   using System.Collections;
   using System.ComponentModel;
   using System.Windows.Forms;
   using System.Data;

   public class GroupBoxPanelExample : System.Windows.Forms.Form
   {
      private System.Windows.Forms.Button hiButton;
      private System.Windows.Forms.Button byeButton;
      private System.Windows.Forms.Button leftButton;
      private System.Windows.Forms.Button rightButton;

      private System.Windows.Forms.GroupBox mainGroupBox;
      private System.Windows.Forms.Label messageLabel;
      private System.Windows.Forms.Panel mainPanel;

      public GroupBoxPanelExample()
      {
         InitializeComponent();
      }
      private void InitializeComponent()
      {
         this.messageLabel = new System.Windows.Forms.Label();
         this.byeButton = new System.Windows.Forms.Button();
         this.mainGroupBox = new System.Windows.Forms.GroupBox();
         this.hiButton = new System.Windows.Forms.Button();
         this.mainPanel = new System.Windows.Forms.Panel();
         this.rightButton = new System.Windows.Forms.Button();
         this.leftButton = new System.Windows.Forms.Button();
         this.mainGroupBox.SuspendLayout();
         this.mainPanel.SuspendLayout();
         this.SuspendLayout();

         this.messageLabel.Location = new System.Drawing.Point( 24, 144 );
         this.messageLabel.Name = "messageLabel";
         this.messageLabel.Size = new System.Drawing.Size( 176, 32 );
         this.messageLabel.TabIndex = 2;

         this.byeButton.Location = new System.Drawing.Point( 96, 48 );
         this.byeButton.Name = "byeButton";
         this.byeButton.Size = new System.Drawing.Size( 72, 32 );
         this.byeButton.TabIndex = 0;
         this.byeButton.Text = "B";

         this.byeButton.Click += new System.EventHandler( this.byeButton_Click );

         this.mainGroupBox.Controls.AddRange( new System.Windows.Forms.Control[] {
            this.byeButton, this.hiButton } );
         this.mainGroupBox.Location = new System.Drawing.Point( 24, 24 );
         this.mainGroupBox.Name = "mainGroupBox";
         this.mainGroupBox.Size = new System.Drawing.Size( 176, 104 );
         this.mainGroupBox.TabIndex = 0;
         this.mainGroupBox.TabStop = false;
         this.mainGroupBox.Text = "Main GroupBox";

         this.hiButton.Location = new System.Drawing.Point( 8, 48 );
         this.hiButton.Name = "hiButton";
         this.hiButton.Size = new System.Drawing.Size( 72, 32 );
         this.hiButton.TabIndex = 0;
         this.hiButton.Text = "A";
         this.hiButton.Click += new System.EventHandler(this.hiButton_Click );

         this.mainPanel.AutoScroll = true;
         this.mainPanel.BorderStyle =System.Windows.Forms.BorderStyle.FixedSingle;

         this.mainPanel.Controls.AddRange(new System.Windows.Forms.Control[] {
            this.rightButton,this.leftButton } );
         this.mainPanel.Location =new System.Drawing.Point( 24, 192 );
         this.mainPanel.Name = "mainPanel";
         this.mainPanel.Size =new System.Drawing.Size( 176, 112 );
         this.mainPanel.TabIndex = 1;

         this.rightButton.Location =new System.Drawing.Point( 264, 40 );
         this.rightButton.Name = "rightButton";
         this.rightButton.Size =new System.Drawing.Size( 80, 40 );
         this.rightButton.TabIndex = 0;
         this.rightButton.Text = "Far Right";
         this.rightButton.Click += new System.EventHandler(this.rightButton_Click );

         this.leftButton.Location =new System.Drawing.Point( 8, 40 );
         this.leftButton.Name = "leftButton";
         this.leftButton.Size =new System.Drawing.Size( 80, 40 );
         this.leftButton.TabIndex = 0;
         this.leftButton.Text = "Far Left";
         this.leftButton.Click +=new System.EventHandler( this.leftButton_Click );

         this.AutoScaleBaseSize =new System.Drawing.Size( 5, 13 );
         this.ClientSize =new System.Drawing.Size( 224, 317 );
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
               this.messageLabel,this.mainPanel,this.mainGroupBox } );
         this.Name = "GroupBoxPanelExample";
         this.Text = "GroupBoxPanelExample";
         this.mainGroupBox.ResumeLayout( false );
         this.mainPanel.ResumeLayout( false );
         this.ResumeLayout( false );

      }
      [STAThread]
      static void Main() 
      {
         Application.Run( new GroupBoxPanelExample() );
      }

      private void hiButton_Click( object sender, System.EventArgs e )
      {
         messageLabel.Text= "A pressed";
      }

      private void byeButton_Click(object sender, System.EventArgs e )
      {
         messageLabel.Text = "B pressed";
      }

      private void leftButton_Click(object sender, System.EventArgs e )
      {
         messageLabel.Text = "Far left pressed";
      }

      private void rightButton_Click( 
         object sender, System.EventArgs e )
      {
         messageLabel.Text = "Far right pressed";
      }
   }



           
          


CheckBox inside GroupBox

image_pdfimage_print


   

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Group
{
  /// <summary>
  /// Summary description for FormGroup.
  /// </summary>
  public class FormGroup : System.Windows.Forms.Form
  {
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.CheckBox checkBox1;
    private System.Windows.Forms.CheckBox checkBox2;
    private System.Windows.Forms.CheckBox checkBox3;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public FormGroup()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
      Application.Idle += new System.EventHandler (OnIdle);

    }

    private void OnIdle (object sender, EventArgs e)
    {
      groupBox1.Enabled = checkBox3.Checked;
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.checkBox3 = new System.Windows.Forms.CheckBox();
      this.checkBox2 = new System.Windows.Forms.CheckBox();
      this.textBox1 = new System.Windows.Forms.TextBox();
      this.groupBox1 = new System.Windows.Forms.GroupBox();
      this.checkBox1 = new System.Windows.Forms.CheckBox();
      this.groupBox1.SuspendLayout();
      this.SuspendLayout();
      // 
      // checkBox3
      // 
      this.checkBox3.Location = new System.Drawing.Point(24, 120);
      this.checkBox3.Name = "checkBox3";
      this.checkBox3.Size = new System.Drawing.Size(184, 16);
      this.checkBox3.TabIndex = 1;
      this.checkBox3.Text = "checkBox3";
      // 
      // checkBox2
      // 
      this.checkBox2.Location = new System.Drawing.Point(136, 56);
      this.checkBox2.Name = "checkBox2";
      this.checkBox2.Size = new System.Drawing.Size(104, 16);
      this.checkBox2.TabIndex = 2;
      this.checkBox2.Text = "checkBox2";
      // 
      // textBox1
      // 
      this.textBox1.Location = new System.Drawing.Point(16, 24);
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new System.Drawing.Size(232, 20);
      this.textBox1.TabIndex = 0;
      this.textBox1.Text = "textBox1";
      // 
      // groupBox1
      // 
      this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                          this.checkBox2,
                                          this.checkBox1,
                                          this.textBox1});
      this.groupBox1.Location = new System.Drawing.Point(16, 16);
      this.groupBox1.Name = "groupBox1";
      this.groupBox1.Size = new System.Drawing.Size(264, 96);
      this.groupBox1.TabIndex = 0;
      this.groupBox1.TabStop = false;
      this.groupBox1.Text = "groupBox1";
      // 
      // checkBox1
      // 
      this.checkBox1.Location = new System.Drawing.Point(16, 56);
      this.checkBox1.Name = "checkBox1";
      this.checkBox1.Size = new System.Drawing.Size(104, 16);
      this.checkBox1.TabIndex = 1;
      this.checkBox1.Text = "checkBox1";
      // 
      // FormGroup
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.checkBox3,
                                      this.groupBox1});
      this.Name = "FormGroup";
      this.Text = "FormGroup";
      this.groupBox1.ResumeLayout(false);
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new FormGroup());
    }
  }
}



           
          


Help Test

image_pdfimage_print



   

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace HelpTest
{
  /// <summary>
  /// Summary description for HelpTest.
  /// </summary>
  public class HelpTest : System.Windows.Forms.Form
  {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public HelpTest()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null) 
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      // 
      // HelpTest
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(528, 434);
      this.IsMdiContainer = true;
      this.Name = "HelpTest";
      this.Text = "HelpTest";
      this.Load += new System.EventHandler(this.HelpTest_Load);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new HelpTest());
    }

    private void HelpTest_Load(object sender, System.EventArgs e)
    {
      FormBased frm1 = new FormBased();
      FrameBased frm2 = new FrameBased();
      ControlBased frm3 = new ControlBased();
      
      frm1.MdiParent = this;
      frm2.MdiParent = this;
      frm3.MdiParent = this;
      
      frm1.Show();
      frm2.Show();
      frm3.Show();
    }
  }
}


//===============================================================
//===============================================================

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace HelpTest
{
  /// <summary>
  /// Summary description for ControlBased.
  /// </summary>
  public class ControlBased : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.TextBox TextBox1;
    internal System.Windows.Forms.ListBox ListBox1;
    internal System.Windows.Forms.Label label1;
    internal System.Windows.Forms.HelpProvider HelpProvider1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public ControlBased()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.TextBox1 = new System.Windows.Forms.TextBox();
      this.ListBox1 = new System.Windows.Forms.ListBox();
      this.label1 = new System.Windows.Forms.Label();
      this.HelpProvider1 = new System.Windows.Forms.HelpProvider();
      this.SuspendLayout();
      // 
      // TextBox1
      // 
      this.TextBox1.Location = new System.Drawing.Point(30, 135);
      this.TextBox1.Name = "TextBox1";
      this.TextBox1.Size = new System.Drawing.Size(208, 20);
      this.TextBox1.TabIndex = 11;
      this.TextBox1.Text = "TextBox1";
      // 
      // ListBox1
      // 
      this.ListBox1.Location = new System.Drawing.Point(26, 19);
      this.ListBox1.Name = "ListBox1";
      this.ListBox1.Size = new System.Drawing.Size(112, 95);
      this.ListBox1.TabIndex = 10;
      // 
      // label1
      // 
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.label1.Location = new System.Drawing.Point(30, 179);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(236, 68);
      this.label1.TabIndex = 9;
      this.label1.Text = "Select a control and press F1 here for a control-based help topic.";
      // 
      // ControlBased
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 266);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.TextBox1,
                                      this.ListBox1,
                                      this.label1});
      this.Name = "ControlBased";
      this.Text = "ControlBased";
      this.Load += new System.EventHandler(this.ControlBased_Load);
      this.ResumeLayout(false);

    }
    #endregion

    private void ControlBased_Load(object sender, System.EventArgs e)
    {
      HelpProvider1.HelpNamespace = "sample.chm";
      HelpProvider1.SetHelpKeyword(TextBox1, "1007.html");
      HelpProvider1.SetHelpNavigator(TextBox1, HelpNavigator.Topic);
      HelpProvider1.SetHelpKeyword(ListBox1, "1006.html");
      HelpProvider1.SetHelpNavigator(ListBox1, HelpNavigator.Topic);
    }
  }
}



           
          


HelpTest.zip( 58 k)

Help icon

image_pdfimage_print



   

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace ExtenderProviderHost
{
  /// <summary>
  /// Summary description for HelpIconProviderHost.
  /// </summary>
  public class HelpIconProviderHost : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.TextBox TextBox2;
    internal System.Windows.Forms.TextBox TextBox1;
    private ExtenderProviderControls.HelpIconProvider helpIconProvider1;
    private System.ComponentModel.IContainer components;

    public HelpIconProviderHost()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.components = new System.ComponentModel.Container();
      this.TextBox2 = new System.Windows.Forms.TextBox();
      this.TextBox1 = new System.Windows.Forms.TextBox();
      this.helpIconProvider1 = new ExtenderProviderControls.HelpIconProvider(this.components);
      this.SuspendLayout();
      // 
      // TextBox2
      // 
      this.TextBox2.Location = new System.Drawing.Point(24, 48);
      this.TextBox2.Name = "TextBox2";
      this.TextBox2.Size = new System.Drawing.Size(148, 20);
      this.TextBox2.TabIndex = 3;
      this.TextBox2.Text = "";
      // 
      // TextBox1
      // 
      this.TextBox1.Location = new System.Drawing.Point(24, 16);
      this.TextBox1.Name = "TextBox1";
      this.TextBox1.Size = new System.Drawing.Size(104, 20);
      this.TextBox1.TabIndex = 2;
      this.TextBox1.Text = "";
      // 
      // helpIconProvider1
      // 
      this.helpIconProvider1.HelpFile = null;
      // 
      // HelpIconProviderHost
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 150);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.TextBox2,
                                      this.TextBox1});
      this.Name = "HelpIconProviderHost";
      this.Text = "HelpIconProviderHost";
      this.Load += new System.EventHandler(this.HelpIconProviderHost_Load);
      this.ResumeLayout(false);

    }
    #endregion

    private void HelpIconProviderHost_Load(object sender, System.EventArgs e)
    {
      helpIconProvider1.HelpFile = "myhelp.hlp";
      helpIconProvider1.SetHelpID(TextBox1, "10001");
      helpIconProvider1.SetHelpID(TextBox2, "10002");
      helpIconProvider1.SetHelpID(TextBox1,"");
    }

    
    static void Main() 
    {
      Application.Run(new HelpIconProviderHost());
    }
  }
}


//=============================================================
//=============================================================

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections;
using System.Drawing;

namespace ExtenderProviderControls
{
[ProvideProperty("HelpID", typeof(string))]
public class HelpIconProvider : Component, IExtenderProvider
{

  private System.ComponentModel.Container components = null;

  public HelpIconProvider(System.ComponentModel.IContainer container)
  {
    /// <summary>
    /// Required for Windows.Forms Class Composition Designer support
    /// </summary>
    container.Add(this);
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
  }

  public HelpIconProvider()
  {
    /// <summary>
    /// Required for Windows.Forms Class Composition Designer support
    /// </summary>
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
  }

    #region Component Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(HelpIconProvider));
    this.pictureBox1 = new System.Windows.Forms.PictureBox();
    // 
    // pictureBox1
    // 
    this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
    this.pictureBox1.Location = new System.Drawing.Point(17, 17);
    this.pictureBox1.Name = "pictureBox1";
    this.pictureBox1.TabIndex = 0;
    this.pictureBox1.TabStop = false;

  }
    #endregion


    private Hashtable contextID = new Hashtable();
  private Hashtable pictures = new Hashtable();
  private System.Windows.Forms.PictureBox pictureBox1;
    private string helpFile;

    public bool CanExtend(object extendee)
    {
        if (extendee.GetType() == typeof(Control))
        {
            // Ensure the control is attached to a form.
            if (((Control)extendee).FindForm() == null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            return false;
        }
    }

    public string HelpFile
  {
    get
        {
            return helpFile;
        }
        set
        {
            helpFile = value;
        }
    }

    public void SetHelpID(object extendee, string value)
    {
        Control ctrl = (Control)extendee;

        // Specifying an empty value removes the extension.
        if (value == "")
        {
            contextID.Remove(extendee);

      // Remove the picture.
      PictureBox pic = (PictureBox)pictures[extendee];
      pic.DoubleClick -= new EventHandler(PicDoubleClick);

      pic.Parent.Controls.Remove(pic);
      pictures.Remove(extendee);
        }
        else
        {
            contextID[extendee] = value;

            // Create new icon.
            PictureBox pic = new PictureBox();
            pic.Image = pictureBox1.Image;
            
            // Store a reference to the related control in the PictureBox.
            pic.Tag = extendee;

            pic.Size = new Size(16, 16);
            pic.Location = new Point(ctrl.Right + 10, ctrl.Top);
            ctrl.Parent.Controls.Add(pic);

            // Register for DoubleClick event.
            pic.DoubleClick += new EventHandler(PicDoubleClick);

      // Store a reference to the help icon so we can remove it later.
      pictures[extendee] = pic;
        }
    }

    public string GetHelpID(object extendee)
    {
        if (contextID[extendee] != null)
        {
            return contextID[extendee].ToString();
        }
        else
        {
            return String.Empty;
        }
    }

    public void PicDoubleClick(object sender, EventArgs e)
    {
        // Invoke help for control.
        Control ctrlRelated = (Control)((Control)sender).Tag;

    // Debug message.
    MessageBox.Show("Help triggered.");

        Help.ShowHelp(ctrlRelated, helpFile, HelpNavigator.Topic, 
          contextID[ctrlRelated].ToString());
    }

}

}


           
          


HelpIconProviderHost.zip( 72 k)

Add to and get Image from Image List

image_pdfimage_print

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

public class Form1 : Form
{
private System.Windows.Forms.Button cmdFillImageList;
private System.Windows.Forms.Button cmdPaintImages;
private System.Windows.Forms.ImageList iconImages;

public Form1() {
InitializeComponent();
}

private void cmdFillImageList_Click(object sender, EventArgs e)
{
iconImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
iconImages.ImageSize = new System.Drawing.Size(16, 16);

string[] iconFiles = Directory.GetFiles(Application.StartupPath, “*.ico”);

foreach (string iconFile in iconFiles)
{
Icon newIcon = new Icon(iconFile);
iconImages.Images.Add(newIcon);
}
}

private void cmdPaintImages_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();

for (int i = 0; i < iconImages.Images.Count; i++) { iconImages.Draw(g, 30 + i * 30, 30, i); } g.Dispose(); } private void InitializeComponent() { this.cmdFillImageList = new System.Windows.Forms.Button(); this.cmdPaintImages = new System.Windows.Forms.Button(); this.iconImages = new System.Windows.Forms.ImageList(new System.ComponentModel.Container()); this.SuspendLayout(); // // cmdFillImageList // this.cmdFillImageList.Location = new System.Drawing.Point(29, 217); this.cmdFillImageList.Name = "cmdFillImageList"; this.cmdFillImageList.Size = new System.Drawing.Size(118, 23); this.cmdFillImageList.TabIndex = 0; this.cmdFillImageList.Text = "Fill Image List"; this.cmdFillImageList.UseVisualStyleBackColor = true; this.cmdFillImageList.Click += new System.EventHandler(this.cmdFillImageList_Click); // // cmdPaintImages // this.cmdPaintImages.Location = new System.Drawing.Point(153, 217); this.cmdPaintImages.Name = "cmdPaintImages"; this.cmdPaintImages.Size = new System.Drawing.Size(112, 23); this.cmdPaintImages.TabIndex = 1; this.cmdPaintImages.Text = "Paint Images"; this.cmdPaintImages.UseVisualStyleBackColor = true; this.cmdPaintImages.Click += new System.EventHandler(this.cmdPaintImages_Click); // // iconImages // this.iconImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.iconImages.ImageSize = new System.Drawing.Size(16, 16); this.iconImages.TransparentColor = System.Drawing.Color.Transparent; // // ImageListTest // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.cmdPaintImages); this.Controls.Add(this.cmdFillImageList); this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "ImageListTest"; this.Text = "ImageListTest"; this.ResumeLayout(false); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); } } [/csharp]

Demonstrates creating a form in a console program

image_pdfimage_print


   

/*
C# Programming Tips &amp; Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

// Form.cs -- Demonstrates creating a form in a console program
//
//            Compile this program with the following command line:
//                C:>csc Form.cs
using System;
using System.Windows.Forms;

namespace nsForm
{
    public class clsMainForm
    {
        static public void Main ()
        {
            Application.Run(new Form());
        }
    }
}


           
          


AutoScrollPosition

image_pdfimage_print

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

public class Form1 : Form {
private Rectangle rectangleBounds = new Rectangle(new Point(0, 0), new Size(200, 200));
private Rectangle ellipseBounds = new Rectangle(new Point(50, 200), new Size(200, 150));
private Pen bluePen = new Pen(Color.Blue, 3);
private Pen redPen = new Pen(Color.Red, 2);
private Brush solidAzureBrush = Brushes.Azure;
private Brush solidYellowBrush = new SolidBrush(Color.Yellow);
static private Brush brickBrush = new HatchBrush(HatchStyle.DiagonalBrick,Color.DarkGoldenrod, Color.Cyan);
private Pen brickWidePen = new Pen(brickBrush, 10);

public Form1() {
}

protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
Graphics dc = e.Graphics;
Point scrollOffset = this.AutoScrollPosition;
dc.TranslateTransform(scrollOffset.X, scrollOffset.Y);
if (e.ClipRectangle.Top + scrollOffset.X < 350 || e.ClipRectangle.Left + scrollOffset.Y < 250) { dc.DrawRectangle(bluePen, rectangleBounds); dc.FillRectangle(solidYellowBrush, rectangleBounds); dc.DrawEllipse(redPen, ellipseBounds); dc.FillEllipse(solidAzureBrush, ellipseBounds); dc.DrawLine(brickWidePen, rectangleBounds.Location,ellipseBounds.Location + ellipseBounds.Size); } } public static void Main() { Application.Run(new Form1()); } } [/csharp]