这是一个用C#编写的WinForm.假设我在我选择的目录中生成一个随机命名的文本文件.当第一次单击该按钮时,我将文本框中包含的数据写入该文本文件.如果用户想要对文本框中的不同数据执行相同的操作,则单击按钮应将新数据写入文本文件而不会丢失旧数据.就像保存日志一样,这可能吗?
我的代码是这样的:
private readonly Random setere = new Random();
private const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private string RandomString()
{
char[] buffer = new char[5];
for (int i = 0; i < 5; i++)
{
buffer[i] = chars[setere.Next(chars.Length)];
}
return new string(buffer);
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dia = MessageBox.Show("Wanna continue?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dia == DialogResult.Yes)
{
StreamWriter wFile = new StreamWriter("C:\\Users\\Ece\\Documents\\Testings\\" + RandomString() + ".txt");
wFile.WriteLine("Name Surname:" + text1.Text + text2.Text);
wFile.WriteLine("Other:" + text3.Text …Run Code Online (Sandbox Code Playgroud) 我有多个yield返回的生成器对象.准备调用这台发电机是相当费时的操作.这就是我想多次重用发生器的原因.
y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
Run Code Online (Sandbox Code Playgroud)
当然,我正在考虑将内容复制到简单的列表中.
为什么在JSP中我们将属性名称作为文件写入include指令,但作为页面 标准操作?
内联函数只是对编译器的请求,这些编译器在使用该函数的代码中的每个位置插入内联函数的完整主体.
但是编译器如何决定是否应该插入它?它使用哪种算法/机制来决定?
谢谢,
纳文
当我尝试使用py2exe中的一个py2exe示例时,我收到此错误.
File "setup.py", line 22, in ?
import py2exe
ImportError: no module named py2exe
Run Code Online (Sandbox Code Playgroud)
我用安装程序安装了py2exe,并使用python 2.6.我从网站上下载了正确的安装程序(python 2.6 one.)
我的路径设置为C:\ Python26,我可以在命令提示符下运行普通的python脚本.
知道该怎么办?
谢谢.
编辑:我先安装了python 3.1但之后删除了它.这可能是问题吗?
我有一个像这样的XML文档:
<wii>
<game>
<type genre="arcade" />
<type genre="sport" />
</game>
<game>
<type genre="platform" />
<type genre="arcade" />
</game>
</wii>
Run Code Online (Sandbox Code Playgroud)
如何仅使用XPath列出所有类型而不重复?
谢谢.
我有一个目录,其中有大约50个wav文件,我需要转换为caf,因为AudioServicesCreateSystemSoundID()为其中一些(但不是全部)返回错误.
以下是我成功用于单个文件的命令示例:
afconvert -f caff -d LEI16@44100 -c 1 whistle.wav whistle.caf
Run Code Online (Sandbox Code Playgroud)
如何快速完成此操作 - 不是每个文件一个接一个?
我通常使用perl one line而不是grep来搜索文件.
例如,以下打印包含的所有位置 #include <stdio.h>
perl -ne "print if(/#include\s*[\"<]stdio.h/)" */*.[ch]
Run Code Online (Sandbox Code Playgroud)
但我找不到打印获取这些行的文件名的方法.我试着打印$ARGV[0]但没有用.
那么,如何打印包含这些行的文件名?
我试图通过创建一个程序来改进我的C++,该程序将需要1到10 ^ 6之间的大量数字.将在每次传递中存储数字的存储桶是一个节点数组(其中node是我创建的包含值和下一个节点属性的结构).
根据最低有效值将数字排序到桶中后,我将一个桶的末尾指向另一个桶的开头(这样我可以快速获取存储的数字而不会中断订单).我的代码没有错误(编译或运行时),但我已经找到了解决剩下的6次迭代的问题(因为我知道数字的范围).
我遇到的问题是,最初这些数字是以int数组的形式提供给radixSort函数的.在排序的第一次迭代之后,数字现在存储在结构数组中.有没有什么方法可以重新编写我的代码,以便我只有一个for循环进行7次迭代,或者我需要一个for循环,它将运行一次,而另一个循环下面将运行6次,然后返回完全排序清单?
#include <iostream>
#include <math.h>
using namespace std;
struct node
{
int value;
node *next;
};
//The 10 buckets to store the intermediary results of every sort
node *bucket[10];
//This serves as the array of pointers to the front of every linked list
node *ptr[10];
//This serves as the array of pointer to the end of every linked list
node *end[10];
node *linkedpointer;
node *item;
node *temp;
void append(int value, int n)
{
node *temp;
item=new …Run Code Online (Sandbox Code Playgroud) 我希望在ListBox中的某个项被鼠标单击时得到通知,无论它是否已被选中.
我搜索并发现了这个:(http://kevin-berridge.blogspot.com/2008/06/wpf-listboxitem-double-click.html查看评论)
private void AddDoubleClickEventStyle(ListBox listBox, MouseButtonEventHandler mouseButtonEventHandler)
{
if (listBox.ItemContainerStyle == null)
listBox.ItemContainerStyle = new Style(typeof(ListBoxItem));
listBox.ItemContainerStyle.Setters.Add(new EventSetter()
{
Event = MouseDoubleClickEvent,
Handler = mouseButtonEventHandler
});
}
//Usage:
AddDoubleClickEventStyle(listView1, new MouseButtonEventHandler(listView1_MouseDoubleClick));
Run Code Online (Sandbox Code Playgroud)
这是有效的,但它是为了它DoubleClick.虽然我不能让它工作一次.我试过MouseLeftButtonDownEvent- 因为似乎没有MouseClick事件,但它没有被调用.
一个更普遍的侧面问题:我怎样才能看到哪些事件确实存在,哪些处理程序与它们对应以及何时实际执行某些操作?例如,什么告诉我,MouseDoubleClickEvent我需要一个MouseButtonEventHandler?也许对于MouseLeftButtonDownEvent我需要一些其他处理程序,这就是为什么它不起作用?
我也尝试了子类化ListBoxItem和覆盖OnMouseLeftButtonDown- 但它也没有被调用.
渣