using System; using System.Collections.Generic; using System.Text; using System.Resources; using System.Drawing; class Program { static void Main(string[] args) { ResXResourceWriter rw = new ResXResourceWriter("Demo.resx"); using (Image image = Image.FromFile("logo.gif")) { rw.AddResource("WroxLogo", image); rw.AddResource("Title", "C#"); rw.AddResource("Chapter", "L"); rw.AddResource("Author", "C"); rw.AddResource("Publisher", "W"); rw.Close(); } } }
Author: coder
Paste Image to RichTextBox
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; using System.Drawing.Text; public class Form1 : Form { private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.ToolStrip toolStrip1; private System.Windows.Forms.ToolStripButton cmdUnderline; private System.Windows.Forms.ToolStripButton cmdBold; private System.Windows.Forms.ToolStripButton cmdItalic; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripDropDownButton lstColors; private System.Windows.Forms.ToolStripDropDownButton lstFonts; private System.Windows.Forms.ToolStripDropDownButton lstZoom; private System.Windows.Forms.ToolStripDropDownButton lstFontSize; private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; private System.Windows.Forms.Button cmdAddImage; public Form1() { InitializeComponent(); } private void richTextBox1_SelectionChanged(object sender, EventArgs e) { if (richTextBox1.SelectionFont != null) { cmdBold.Checked = richTextBox1.SelectionFont.Bold; cmdItalic.Checked = richTextBox1.SelectionFont.Italic; cmdUnderline.Checked = richTextBox1.SelectionFont.Underline; } } private void cmdBold_Click(object sender, EventArgs e) { if (richTextBox1.SelectionFont == null) { return; } FontStyle style = richTextBox1.SelectionFont.Style; if (richTextBox1.SelectionFont.Bold) { style &= ~FontStyle.Bold; } else { style |= FontStyle.Bold; } richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, style); } private void cmdItalic_Click(object sender, EventArgs e) { if (richTextBox1.SelectionFont == null) { return; } FontStyle style = richTextBox1.SelectionFont.Style; if (richTextBox1.SelectionFont.Italic) { style &= ~FontStyle.Italic; } else { style |= FontStyle.Italic; } richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, style); } private void cmdUnderline_Click(object sender, EventArgs e) { if (richTextBox1.SelectionFont == null) { return; } FontStyle style = richTextBox1.SelectionFont.Style; if (richTextBox1.SelectionFont.Underline) { style &= ~FontStyle.Underline; } else { style |= FontStyle.Underline; } richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, style); } private void Form1_Load(object sender, EventArgs e) { lstColors.DropDown.Items.Add("Red"); lstColors.DropDown.Items.Add("Blue"); InstalledFontCollection fonts = new InstalledFontCollection(); foreach (FontFamily family in fonts.Families) { lstFonts.DropDown.Items.Add(family.Name); } lstZoom.DropDown.Items.Add("300%"); lstZoom.DropDown.Items.Add("200%"); lstZoom.DropDown.Items.Add("100%"); lstFontSize.DropDown.Items.Add("8"); lstFontSize.DropDown.Items.Add("10"); lstFontSize.DropDown.Items.Add("12"); } private void lstColors_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { KnownColor selectedColor; selectedColor = (KnownColor)System.Enum.Parse(typeof(KnownColor), e.ClickedItem.Text); richTextBox1.SelectionColor = Color.FromKnownColor(selectedColor); } private void lstFonts_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (richTextBox1.SelectionFont == null) { richTextBox1.SelectionFont = new Font(e.ClickedItem.Text, richTextBox1.Font.Size); } richTextBox1.SelectionFont = new Font(e.ClickedItem.Text, richTextBox1.SelectionFont.Size); } private void lstZoom_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { float zoomPercent = Convert.ToSingle(e.ClickedItem.Text.Trim('%')); richTextBox1.ZoomFactor = zoomPercent / 100; } private void lstFontSize_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (richTextBox1.SelectionFont == null) { return; } richTextBox1.SelectionFont =new Font(richTextBox1.SelectionFont.FontFamily, Convert.ToInt32(e.ClickedItem.Text), richTextBox1.SelectionFont.Style); } private void cmdAddImage_Click(object sender, EventArgs e) { Image img = Image.FromFile("winter.jpg"); Clipboard.SetImage(img); richTextBox1.SelectionStart = 0; richTextBox1.Paste(); Clipboard.Clear(); } private void InitializeComponent() { this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.cmdBold = new System.Windows.Forms.ToolStripButton(); this.cmdItalic = new System.Windows.Forms.ToolStripButton(); this.cmdUnderline = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.lstColors = new System.Windows.Forms.ToolStripDropDownButton(); this.lstFonts = new System.Windows.Forms.ToolStripDropDownButton(); this.lstFontSize = new System.Windows.Forms.ToolStripDropDownButton(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.lstZoom = new System.Windows.Forms.ToolStripDropDownButton(); this.cmdAddImage = new System.Windows.Forms.Button(); this.toolStrip1.SuspendLayout(); this.SuspendLayout(); // // richTextBox1 // this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.richTextBox1.BulletIndent = 5; this.richTextBox1.Location = new System.Drawing.Point(12, 37); this.richTextBox1.Margin = new System.Windows.Forms.Padding(5); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(317, 197); this.richTextBox1.TabIndex = 0; this.richTextBox1.Text = "adfasdf"; this.richTextBox1.SelectionChanged += new System.EventHandler(this.richTextBox1_SelectionChanged); // // toolStrip1 // this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.cmdBold, this.cmdItalic, this.cmdUnderline, this.toolStripSeparator1, this.lstColors, this.lstFonts, this.lstFontSize, this.toolStripSeparator2, this.lstZoom}); this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Size = new System.Drawing.Size(341, 25); this.toolStrip1.TabIndex = 1; this.toolStrip1.Text = "toolStrip1"; // // cmdBold // this.cmdBold.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.cmdBold.ImageTransparentColor = System.Drawing.Color.Magenta; this.cmdBold.Name = "cmdBold"; this.cmdBold.Size = new System.Drawing.Size(31, 22); this.cmdBold.Text = "Bold"; this.cmdBold.Click += new System.EventHandler(this.cmdBold_Click); // // cmdItalic // this.cmdItalic.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.cmdItalic.ImageTransparentColor = System.Drawing.Color.Magenta; this.cmdItalic.Name = "cmdItalic"; this.cmdItalic.Size = new System.Drawing.Size(34, 22); this.cmdItalic.Text = "Italic"; this.cmdItalic.Click += new System.EventHandler(this.cmdItalic_Click); // // cmdUnderline // this.cmdUnderline.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.cmdUnderline.ImageTransparentColor = System.Drawing.Color.Magenta; this.cmdUnderline.Name = "cmdUnderline"; this.cmdUnderline.Size = new System.Drawing.Size(56, 22); this.cmdUnderline.Text = "Underline"; this.cmdUnderline.Click += new System.EventHandler(this.cmdUnderline_Click); // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25); // // lstColors // this.lstColors.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.lstColors.ImageTransparentColor = System.Drawing.Color.Magenta; this.lstColors.Name = "lstColors"; this.lstColors.Size = new System.Drawing.Size(45, 22); this.lstColors.Text = "Color"; this.lstColors.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.lstColors_DropDownItemClicked); // // lstFonts // this.lstFonts.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.lstFonts.ImageTransparentColor = System.Drawing.Color.Magenta; this.lstFonts.Name = "lstFonts"; this.lstFonts.Size = new System.Drawing.Size(42, 22); this.lstFonts.Text = "Font"; this.lstFonts.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.lstFonts_DropDownItemClicked); // // lstFontSize // this.lstFontSize.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.lstFontSize.ImageTransparentColor = System.Drawing.Color.Magenta; this.lstFontSize.Name = "lstFontSize"; this.lstFontSize.Size = new System.Drawing.Size(39, 22); this.lstFontSize.Text = "Size"; this.lstFontSize.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.lstFontSize_DropDownItemClicked); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25); // // lstZoom // this.lstZoom.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.lstZoom.ImageTransparentColor = System.Drawing.Color.Magenta; this.lstZoom.Name = "lstZoom"; this.lstZoom.Size = new System.Drawing.Size(46, 22); this.lstZoom.Text = "Zoom"; this.lstZoom.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.lstZoom_DropDownItemClicked); // // cmdAddImage // this.cmdAddImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.cmdAddImage.Location = new System.Drawing.Point(12, 237); this.cmdAddImage.Name = "cmdAddImage"; this.cmdAddImage.Size = new System.Drawing.Size(154, 23); this.cmdAddImage.TabIndex = 2; this.cmdAddImage.Text = "Insert Image"; this.cmdAddImage.UseVisualStyleBackColor = true; this.cmdAddImage.Click += new System.EventHandler(this.cmdAddImage_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(341, 266); this.Controls.Add(this.cmdAddImage); this.Controls.Add(this.toolStrip1); this.Controls.Add(this.richTextBox1); this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "Form1"; this.Text = "RichTextBox Test"; this.Load += new System.EventHandler(this.Form1_Load); this.toolStrip1.ResumeLayout(false); this.toolStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); } }
RadioButton With Img
/* Professional Windows GUI Programming Using C# by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, Zach Greenvoss, Shripad Kulkarni, Neil Whitlow Publisher: Peer Information ISBN: 1861007663 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace RadioButtonWithImg { /// <summary> /// Summary description for RadioButtonWithImg. /// </summary> public class RadioButtonWithImg : System.Windows.Forms.Form { private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.RadioButton radioButton1; private System.Windows.Forms.RadioButton radioButton2; private System.Windows.Forms.RadioButton radioButton3; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public RadioButtonWithImg() { // // 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.groupBox1 = new System.Windows.Forms.GroupBox(); this.radioButton3 = new System.Windows.Forms.RadioButton(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] { this.radioButton3, this.radioButton2, this.radioButton1}); this.groupBox1.Location = new System.Drawing.Point(8, 16); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(160, 120); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "Group 1"; // // radioButton3 // this.radioButton3.Appearance = System.Windows.Forms.Appearance.Button; this.radioButton3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255))); this.radioButton3.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.radioButton3.Location = new System.Drawing.Point(16, 88); this.radioButton3.Name = "radioButton3"; this.radioButton3.Size = new System.Drawing.Size(120, 24); this.radioButton3.TabIndex = 2; this.radioButton3.Text = "Option3"; // // radioButton2 // this.radioButton2.Appearance = System.Windows.Forms.Appearance.Button; this.radioButton2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192))); this.radioButton2.Location = new System.Drawing.Point(16, 56); this.radioButton2.Name = "radioButton2"; this.radioButton2.Size = new System.Drawing.Size(120, 24); this.radioButton2.TabIndex = 1; this.radioButton2.Text = "Option2"; this.radioButton2.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // radioButton1 // this.radioButton1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192))); this.radioButton1.Location = new System.Drawing.Point(16, 24); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(120, 24); this.radioButton1.TabIndex = 0; this.radioButton1.Text = "Option1"; this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged); // // RadioButton // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(184, 149); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.groupBox1}); this.Name = "RadioButton"; this.Text = "Radio Button"; this.Load += new System.EventHandler(this.RadioButtonWithImg_Load); this.groupBox1.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new RadioButtonWithImg()); } private void RadioButtonWithImg_Load(object sender, System.EventArgs e) { // Select the Image for the button Image img = Image.FromFile("EYE.ICO"); // Assign the Image to the button radioButton1.Image = img ; // Align the image radioButton1.ImageAlign = ContentAlignment.MiddleRight; // Select the Image for the button img = Image.FromFile("WRENCH.ICO"); // Assign the Image to the button radioButton2.Image = img ; // Align the image radioButton2.ImageAlign = ContentAlignment.MiddleLeft; } private void radioButton1_CheckedChanged(object sender, System.EventArgs e) { if (radioButton1.Checked) MessageBox.Show("Checked!"); else MessageBox.Show("Not checked!"); } } } RadioButton.zip( 30 k)
Radio Group
/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Peaks
{
///
///
public class Peaks : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.RadioButton radioButton4;
private System.Windows.Forms.RadioButton radioButton5;
private System.Windows.Forms.RadioButton radioButton6;
private System.Windows.Forms.RadioButton radioButton7;
private System.Windows.Forms.RadioButton radioButton8;
private System.Windows.Forms.RadioButton radioButton9;
private System.Windows.Forms.RadioButton radioButton10;
private System.Windows.Forms.RadioButton radioButton11;
private System.Windows.Forms.RadioButton radioButton12;
Point[] pnts = { new Point(20, 90), new Point(55, 70),
new Point(80, 80), new Point(105, 40),
new Point(130, 90)};
///
///
private System.ComponentModel.Container components = null;
public Peaks()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.radioButton1.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton2.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton3.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton4.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton5.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton6.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton7.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton8.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton9.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton10.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton11.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton12.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton6 = new System.Windows.Forms.RadioButton();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.radioButton7 = new System.Windows.Forms.RadioButton();
this.radioButton9 = new System.Windows.Forms.RadioButton();
this.radioButton8 = new System.Windows.Forms.RadioButton();
this.radioButton10 = new System.Windows.Forms.RadioButton();
this.radioButton12 = new System.Windows.Forms.RadioButton();
this.radioButton11 = new System.Windows.Forms.RadioButton();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioButton1,
this.radioButton2,
this.radioButton3,
this.radioButton6,
this.radioButton5,
this.radioButton4,
this.radioButton7,
this.radioButton9,
this.radioButton8,
this.radioButton10,
this.radioButton12,
this.radioButton11});
this.groupBox1.Location = new System.Drawing.Point(200, 8);
this.groupBox1.Name = “groupBox1”;
this.groupBox1.Size = new System.Drawing.Size(304, 120);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = “Primitives”;
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(16, 24);
this.radioButton1.Name = “radioButton1”;
this.radioButton1.Size = new System.Drawing.Size(88, 16);
this.radioButton1.TabIndex = 0;
this.radioButton1.Text = “4xLine”;
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(112, 24);
this.radioButton2.Name = “radioButton2”;
this.radioButton2.Size = new System.Drawing.Size(56, 16);
this.radioButton2.TabIndex = 0;
this.radioButton2.Text = “Lines”;
//
// radioButton3
//
this.radioButton3.Location = new System.Drawing.Point(184, 24);
this.radioButton3.Name = “radioButton3”;
this.radioButton3.Size = new System.Drawing.Size(80, 16);
this.radioButton3.TabIndex = 0;
this.radioButton3.Text = “Polygon”;
//
// radioButton6
//
this.radioButton6.Location = new System.Drawing.Point(184, 48);
this.radioButton6.Name = “radioButton6”;
this.radioButton6.Size = new System.Drawing.Size(80, 16);
this.radioButton6.TabIndex = 0;
this.radioButton6.Text = “Curve 1.1”;
//
// radioButton5
//
this.radioButton5.Location = new System.Drawing.Point(112, 48);
this.radioButton5.Name = “radioButton5”;
this.radioButton5.Size = new System.Drawing.Size(88, 16);
this.radioButton5.TabIndex = 0;
this.radioButton5.Text = “Curve 0.6”;
//
// radioButton4
//
this.radioButton4.Location = new System.Drawing.Point(16, 48);
this.radioButton4.Name = “radioButton4”;
this.radioButton4.Size = new System.Drawing.Size(88, 16);
this.radioButton4.TabIndex = 0;
this.radioButton4.Text = “Curve 0”;
//
// radioButton7
//
this.radioButton7.Location = new System.Drawing.Point(16, 72);
this.radioButton7.Name = “radioButton7”;
this.radioButton7.Size = new System.Drawing.Size(88, 16);
this.radioButton7.TabIndex = 0;
this.radioButton7.Text = “2xBezier”;
//
// radioButton9
//
this.radioButton9.Location = new System.Drawing.Point(184, 72);
this.radioButton9.Name = “radioButton9”;
this.radioButton9.Size = new System.Drawing.Size(112, 16);
this.radioButton9.TabIndex = 0;
this.radioButton9.Text = “ClosedCurve 1.1”;
//
// radioButton8
//
this.radioButton8.Location = new System.Drawing.Point(112, 72);
this.radioButton8.Name = “radioButton8”;
this.radioButton8.Size = new System.Drawing.Size(88, 16);
this.radioButton8.TabIndex = 0;
this.radioButton8.Text = “Beziers”;
//
// radioButton10
//
this.radioButton10.Location = new System.Drawing.Point(16, 96);
this.radioButton10.Name = “radioButton10”;
this.radioButton10.Size = new System.Drawing.Size(88, 16);
this.radioButton10.TabIndex = 0;
this.radioButton10.Text = “2xBezier”;
//
// radioButton12
//
this.radioButton12.Location = new System.Drawing.Point(184, 96);
this.radioButton12.Name = “radioButton12”;
this.radioButton12.Size = new System.Drawing.Size(88, 16);
this.radioButton12.TabIndex = 0;
this.radioButton12.Text = “Curve”;
//
// radioButton11
//
this.radioButton11.Location = new System.Drawing.Point(112, 96);
this.radioButton11.Name = “radioButton11”;
this.radioButton11.Size = new System.Drawing.Size(88, 16);
this.radioButton11.TabIndex = 0;
this.radioButton11.Text = “Beziers”;
//
// Peaks
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(504, 133);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox1});
this.Name = “Peaks”;
this.Text = “Two Peaks”;
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
///
[STAThread]
static void Main()
{
Application.Run(new Peaks());
}
private void RBs_CheckedChanged(object sender, System.EventArgs e)
{
this.Refresh();
}
protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(this.BackColor);
if (this.radioButton1.Checked) Ex01_4xLine(g);
if (this.radioButton2.Checked) Ex02_Lines(g);
if (this.radioButton3.Checked) Ex03_Polygon(g);
if (this.radioButton4.Checked) Ex04_Curve0(g);
if (this.radioButton5.Checked) Ex05_Curve1(g);
if (this.radioButton6.Checked) Ex06_Curve2(g);
if (this.radioButton7.Checked) Ex07_2xBezier(g);
if (this.radioButton8.Checked) Ex08_Beziers(g);
if (this.radioButton9.Checked) Ex09_ClosedCurve(g);
if (this.radioButton10.Checked) Ex10_2xBezier_2(g);
if (this.radioButton11.Checked) Ex11_Beziers_2(g);
if (this.radioButton12.Checked) Ex11_Curve_2(g);
g.Dispose();
}
protected void Ex01_4xLine(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawLine(pn, 20, 90, 55, 70);
g.DrawLine(pn, 55, 70, 80, 80);
g.DrawLine(pn, 80, 80,105, 40);
g.DrawLine(pn,105, 40,130, 90);
}
protected void Ex02_Lines(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawLines(pn, pnts);
}
protected void Ex03_Polygon(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawPolygon(pn, pnts);
}
protected void Ex04_Curve0(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawCurve(pn, pnts, 0.0f);
}
protected void Ex05_Curve1(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawCurve(pn, pnts, 0.6f);
}
protected void Ex06_Curve2(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawCurve(pn, pnts, 1.1f);
}
protected void Ex07_2xBezier(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawBezier(pn, 20, 90, 50, 70, 60, 70, 80, 80);
g.DrawBezier(pn, 80, 80,100, 40,110, 40,130, 90);
}
protected void Ex08_Beziers(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
Point[] pnts = {new Point(20, 90), new Point(50, 70),
new Point(60, 70), new Point(80, 80),
new Point(100, 40), new Point(110, 40),
new Point(130, 90)};
g.DrawBeziers(pn, pnts);
}
protected void Ex09_ClosedCurve(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
Point[] pnts = {new Point( 20, 90), new Point( 55, 70),
new Point( 80, 80), new Point(105, 40),
new Point(130, 90)};
g.DrawClosedCurve(pn, pnts, 1.1f, System.Drawing.Drawing2D.FillMode.Winding);
}
protected void Ex10_2xBezier_2(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawBezier(pn, 20, 90, 50, 70, 60, 70, 80, 80);
g.DrawBezier(pn, 80, 80,100,120,110,120,130, 90);
}
protected void Ex11_Beziers_2(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
int[,] xy = { { 20, 90}, { 50, 70},
{ 60, 70}, { 80, 80},
{100,120}, {110,120},
{130, 90}};
int ii = xy.GetLength(0);
Point[] pnts = new Point[ii];
for(int i = 0; i < ii; i++)
{
pnts[i].X = xy[i, 0];
pnts[i].Y = xy[i, 1];
}
g.DrawBeziers(pn, pnts);
}
protected void Ex11_Curve_2(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
Point[] pnts = {new Point( 20, 90), new Point( 55, 70),
new Point( 80, 80), new Point(105,120),
new Point(130, 90)};
g.DrawCurve(pn, pnts, 0.0f);
}
}
}
[/csharp]
Reading from a String Resource
using System; using System.Drawing; using System.Windows.Forms; using System.Resources; using System.Reflection; public class MainForm { public static void Main() { ResourceManager FormResources = new ResourceManager("StringTable", Assembly.GetExecutingAssembly()); string Message; Message = FormResources.GetString("Message"); MessageBox.Show(Message); } }
Reading resources
using System;
using System.Resources;
using System.Collections;
public class MainClass {
public static void DumpResources(string resName) {
ResourceReader reader = new ResourceReader(resName);
IDictionaryEnumerator en = reader.GetEnumerator();
while (en.MoveNext()) {
Console.WriteLine(“Resource Name: [{0}] = {1}”, en.Key, en.Value);
}
reader.Close();
}
public static void DumpAResource(string resName, string keyName) {
try {
ResourceManager rMgr = new ResourceManager(resName,
System.Reflection.Assembly.GetExecutingAssembly());
Console.WriteLine(“Resource: {0}”, rMgr.GetString(keyName));
} catch (Exception e) {
Console.WriteLine(“Exception creating manager {0}”, e);
return;
}
}
public static void Main(string[] args) {
for (int i = 0; i < args.Length; ++i)
DumpAResource("English", args[i]);
DumpResources("English1.resources");
}
}
[/csharp]
Check the key in a .resources file
using System; using System.Resources; using System.Collections; public class MainClass { public static void DisplayGreeting(string resName) { try { ResourceReader reader = new ResourceReader(resName + ".resources"); IDictionaryEnumerator dict = reader.GetEnumerator(); while (dict.MoveNext()) { string s = (string)dict.Key; if (s == "Greeting") Console.WriteLine("{0}", dict.Value); } } catch (Exception e) { Console.WriteLine("Exception creating manager {0}", e); return; } } public static void Main(string[] args) { DisplayGreeting(args[0]); } }