Form1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:6k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- namespace SimpleListView
- {
- /// <summary>
- /// Summary description for Form1.
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.ListView lvCountries;
- private System.Windows.Forms.ImageList imgLarge;
- private System.Windows.Forms.ImageList imgSmall;
- private System.Windows.Forms.ComboBox cbView;
- private System.Windows.Forms.Label lblAbbreviation;
- private System.ComponentModel.IContainer components;
- public Form1()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- lvCountries.Items.Add(new CountryItem("United States", "US", "Dollar"));
- lvCountries.Items[0].ImageIndex = 0;
- lvCountries.Items.Add(new CountryItem("Great Britain", "GB", "Pound"));
- lvCountries.Items[1].ImageIndex = 1;
- lvCountries.Items.Add(new CountryItem("Canada", "CA", "Dollar"));
- lvCountries.Items[2].ImageIndex = 2;
- lvCountries.Items.Add(new CountryItem("Japan", "JP", "Yen"));
- lvCountries.Items[3].ImageIndex = 3;
- lvCountries.Items.Add(new CountryItem("Germany", "GM", "Deutch Mark"));
- lvCountries.Items[4].ImageIndex = 4;
- cbView.Items.Add(View.LargeIcon);
- cbView.Items.Add(View.SmallIcon);
- cbView.Items.Add(View.List);
- cbView.Items.Add(View.Details);
- cbView.SelectedIndex = 0;
- lvCountries.Columns.Add("Country",100, HorizontalAlignment.Left);
- lvCountries.Columns.Add("Currency",100, HorizontalAlignment.Left);
- }
- /// <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();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
- this.lvCountries = new System.Windows.Forms.ListView();
- this.imgLarge = new System.Windows.Forms.ImageList(this.components);
- this.imgSmall = new System.Windows.Forms.ImageList(this.components);
- this.cbView = new System.Windows.Forms.ComboBox();
- this.lblAbbreviation = new System.Windows.Forms.Label();
- this.SuspendLayout();
- //
- // lvCountries
- //
- this.lvCountries.LargeImageList = this.imgLarge;
- this.lvCountries.Location = new System.Drawing.Point(24, 72);
- this.lvCountries.Name = "lvCountries";
- this.lvCountries.Size = new System.Drawing.Size(256, 248);
- this.lvCountries.SmallImageList = this.imgSmall;
- this.lvCountries.TabIndex = 0;
- this.lvCountries.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvCountries_MouseUp);
- //
- // imgLarge
- //
- this.imgLarge.ImageSize = new System.Drawing.Size(48, 48);
- this.imgLarge.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgLarge.ImageStream")));
- this.imgLarge.TransparentColor = System.Drawing.Color.Transparent;
- //
- // imgSmall
- //
- this.imgSmall.ColorDepth = System.Windows.Forms.ColorDepth.Depth16Bit;
- this.imgSmall.ImageSize = new System.Drawing.Size(16, 16);
- this.imgSmall.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgSmall.ImageStream")));
- this.imgSmall.TransparentColor = System.Drawing.Color.Transparent;
- //
- // cbView
- //
- this.cbView.Location = new System.Drawing.Point(32, 32);
- this.cbView.Name = "cbView";
- this.cbView.Size = new System.Drawing.Size(128, 21);
- this.cbView.TabIndex = 1;
- this.cbView.SelectedIndexChanged += new System.EventHandler(this.cbView_SelectedIndexChanged);
- //
- // lblAbbreviation
- //
- this.lblAbbreviation.Location = new System.Drawing.Point(176, 32);
- this.lblAbbreviation.Name = "lblAbbreviation";
- this.lblAbbreviation.Size = new System.Drawing.Size(48, 23);
- this.lblAbbreviation.TabIndex = 2;
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(312, 339);
- this.Controls.Add(this.lblAbbreviation);
- this.Controls.Add(this.cbView);
- this.Controls.Add(this.lvCountries);
- this.Name = "Form1";
- this.Text = "Form1";
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
- private void cbView_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- lvCountries.View = (View)cbView.SelectedItem;
- }
- private void lvCountries_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if(lvCountries.View != View.Details)
- lblAbbreviation.Text = ((CountryItem)lvCountries.GetItemAt(e.X, e.Y)).CountryAbbreviation;
- else
- lblAbbreviation.Text = ((CountryItem)lvCountries.GetItemAt(5, e.Y)).CountryAbbreviation;
- }
-
- }
- }