本文介绍了问题是什么? button5无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
button5有什么问题?当你点击什么都没有请帮助。
what is the problem at button5 ? When you click does nothing pls help .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OpenFileDialog ofd = new OpenFileDialog();
FolderBrowserDialog fbd = new FolderBrowserDialog();
private void button1_Click(object sender, EventArgs e)
{
ofd.Filter = "PNG files |*.png|JPG files|*.jpg|JPGE files|*.jpge|DOC files|*.doc|DOCX files|*.docx|MP3 files|*.mp3|PDF files |*.pdf";
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] fileNameAndPath = ofd.FileNames;
string[] filename = ofd.SafeFileNames;
for (int i = 0; i < ofd.SafeFileNames.Count(); i++)
{
listView1.Items.Add(filename[i]);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (fbd.ShowDialog() == DialogResult.OK)
{
string folderpath = fbd.SelectedPath;
string supportedExtensions = "*.jpg,*.png,*.jpge,*.doc,*.docx,*.mp3,*.pdf";
foreach (string f in Directory.GetFiles(folderpath, "*.*", SearchOption.AllDirectories).Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower())))
{
ListViewItem lvi = new ListViewItem();
listView1.Items.Add(Path.GetFileName((f)));
lvi.SubItems.Add(Path.GetFullPath((f)));
listView1.Items.Add(lvi);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
for (int i = 0; i < listView1.Items.Count; i++)
if (listView1.Items[i].Selected)
{
listView1.Items[i].Remove();
i--;
}
}
private void button4_Click(object sender, EventArgs e)
{
listView1.Items.Remove(listView1.SelectedItems[0]);
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void infoToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("lalala");
}
private void button5_Click(object sender, EventArgs e)
{
//face legatura cu al doile form
Form2 ff=new Form2();
ff.MdiParent=this;
//sortare
for (int j = 0;j< listView1.Items.Count - 1; j++)
{
string sc = Convert.ToString(listView1.Items[j].Text);
for (int j1 = 0; j1 < listView1.Items.Count; j1++)
if (String.CompareOrdinal(sc, Convert.ToString(listView1.Items[j1].Text)) < 0)
{
ListViewItem l = new ListViewItem(listView1.Items[j].Text,0);
l.SubItems.Add(Convert.ToString(listView1.Items[j].SubItems[1].Text));
listView1.Items.RemoveAt(j);
listView1.Items.Insert(j, listView1.Items[j1]);
listView1.Items.Insert(j1, l);
}
}
//foreach (ListViewItem item in listView1.Items)
// verifica daca au acelasi nume,tip,marime
for (int j = 0;j< listView1.Items.Count - 1; j++)
{
string str = Convert.ToString(listView1.Items[j].SubItems[1].Text);
string s = Path.GetFileName(str);
for (int j1 = 0; j1 < listView1.Items.Count; j1++)
{
string str2=Convert.ToString(listView1.Items[j1].SubItems[1].Text);
if (s.Equals(Path.GetFileName(str2)) )
{
FileInfo f = new FileInfo(str);
long s1 = f.Length;
FileInfo f2 = new FileInfo(str2);
long s2 = f2.Length;
if (s1.Equals(s2))
{//trimite catre form2
ff.valoaretransmisa = listView1.Items[j];
}
}
}
}
ff.ShowDialog();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private ListViewItem lvi;
public ListViewItem valoaretransmisa
{
get { return lvi; }
set { lvi=value;
listView1.Items.Add(lvi); }
}
private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Vrei sa stergi?","titlu", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
for (int i = 0; i < listView1.Items.Count; i++)
File.Delete(Convert.ToString(listView1.Items[i].SubItems[1].Text));
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}
推荐答案
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
如果您有Form1.cs,还会有
Form1.Designer.cs
If you have Form1.cs there will also be
Form1.Designer.cs
namespace WindowsFormsApplication2
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
}
}
自动生成并在例如自动更新时自动更新你将一个按钮
拖到Windows窗体并指定双击。
请检查所有按钮点击事件是否已连线。
例如this.button5.Click + = new System.EventHandler(this.button5_Click);
祝你好运,
Stephan
which is auto-generated and auto-updated when e.g. you drag a button
to the Windows Form and assign a double-click.
Please check if all button click events are wired up.
e.g. this.button5.Click += new System.EventHandler(this.button5_Click);
Best regards,
Stephan
这篇关于问题是什么? button5无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!