frmAddItem.cs
上传用户:jiupin
上传日期:2022-04-21
资源大小:1525k
文件大小:3k
源码类别:

ListView/ListBox

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace WinListViewQQ
  9.     public partial class frmAddItem : Form
  10.     {
  11.         private string itemInfo = string.Empty;//保存项的key,text,imageIndex信息
  12.         /// <summary>
  13.         /// 保存项的key,text,imageIndex信息
  14.         /// </summary>
  15.         public string ItemInfo
  16.         {
  17.             get { return itemInfo; }
  18.             set { itemInfo = value; }
  19.         }
  20.         private int intflag;//组标志
  21.         /// <summary>
  22.         /// 组标志位
  23.         /// </summary>
  24.         public int Intflag
  25.         {
  26.             get { return intflag; }
  27.             set { intflag = value; }
  28.         }
  29.     
  30.         public frmAddItem()
  31.         {
  32.             InitializeComponent();
  33.             //图片存放的相对路径         
  34.             string strImagePath = Application.StartupPath.Substring(0) + "\images";//**************************************************
  35.             //设置窗体图标
  36.             this.Icon = System.Drawing.Icon.ExtractAssociatedIcon(strImagePath + "\ico.ico");
  37.           
  38.             
  39.         }
  40.         /// <summary>
  41.         /// 选择程序路径+名 
  42.         /// </summary>
  43.         /// <param name="sender"></param>
  44.         /// <param name="e"></param>
  45.         private void btnSelectPath_Click(object sender, EventArgs e)
  46.         {
  47.             OpenFileDialog dlg = new OpenFileDialog();
  48.             dlg.ShowDialog();
  49.             txtPath.Text = dlg.FileName.ToString().Trim();
  50.              txtInfo.Text=txtPath.Text.Substring(txtPath.Text.LastIndexOf('\')+1);
  51.         }
  52.       
  53.       #region 添加项 按钮事件
  54.         private void btnAddItem_Click(object sender, EventArgs e)
  55.         {
  56.             string key=txtPath.Text;//键
  57.             if (key.Length < 0 || !key.EndsWith("exe"))
  58.             {
  59.                 MessageBox.Show("请输入完整的程序路径");
  60.                 return;
  61.             }
  62.             string text=string.Empty;
  63.             int imageIndex=0;
  64.             if (txtInfo.Text.Trim() == "")
  65.             {
  66.                 text = key.Substring(key.LastIndexOf('\') + 1);//值
  67.             }
  68.             else
  69.             {
  70.                 text = txtInfo.Text.Trim();
  71.             }
  72.    
  73.             //
  74.            clsXMl.AddXmlNode(key,text,imageIndex,Intflag);
  75.            //
  76.             itemInfo = key + "|" + text + "|" + imageIndex.ToString();
  77.             MessageBox.Show("ok");
  78.             this.Close();
  79.             this.Dispose();
  80.             return;
  81.         }
  82.    #endregion
  83.         #region 取消
  84.         private void btnCancel_Click(object sender, EventArgs e)
  85.         {
  86.             this.Close();
  87.             this.Dispose();
  88.         }
  89.         #endregion
  90.     }
  91. }