我想更改从嵌入资源作为流加载的文件的内容。
以下代码获取文件:
Stream theFile = Assembly.GetExecutingAssembly().GetManifestResourceStream("_3LinksFourmTool.Resources.fourmlinks.txt");
Run Code Online (Sandbox Code Playgroud)
我创建了一个方法,该方法采用提供的Stream 中存在的文本字符串。该字符串将使用新内容重写到Stream。
public static void WriteNewTextToFile(string text, Stream theFile)
{
string fileText = GetAllTextFromFile(theFile);
ArrayList fileLIst = populateListFromText(fileText);
using (StreamWriter fileWriter = new StreamWriter(theFile))
{
fileWriter.Write("");
for (int i = 0; i < fileLIst.Count; i++)
{
fileWriter.WriteLine(fileLIst[i].ToString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出System.ArgumentException。
此异常与文本文件是Embedded Resource?
如何在不抛出System.ArgumentException 的情况下修改此文件?
我正在尝试创建一个表单.表单控件名称始终是相同的.但是控制的类型会改变.例如,我有一个名为"first_name"的控件.页面初始化时,它从数据库中检索数据,说明控件的类型(TextBox,DropDownList或CheckBox); 然后在页面上动态创建表单.为了保持视图状态,我在OnInit方法中创建了控件.
protected override void OnInit(EventArgs e)
{
Control first_name;
string ControlType = GridView1.Rows[0].Cells[1].Text;
switch (ControlType)
{
case("TextBox"):
first_name = new Control() as TextBox; first_name.ID = "first_name"; this.Controls.Add(first_name);
break;
case("DropDownList"):
first_name = new Control() as DropDownList; first_name.ID = "first_name"; this.Controls.Add(first_name);
break;
case("CheckBox"):
first_name = new Control() as CheckBox; first_name.ID = "first_name"; this.Controls.Add("first_name");
break;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将控件呈现给页面.
protected override void Render(HtmlTextWriter writer)
{
writer.Write("first_name: ");
first_name.RenderControl(writer);
}
Run Code Online (Sandbox Code Playgroud)
接下来,我尝试为控件赋值.这是我遇到问题的地方.我知道当它被全局声明时,它被声明为一个控件并保存这些值.
有没有办法在函数内全局声明它,或者在全局声明后更改控件的类型?
protected void Page_Load(object sender, EventArgs e)
{
switch (first_name.GetType().ToString())
{
case ("TextBox"): …Run Code Online (Sandbox Code Playgroud) 我必须使用1.1 .NET版本Framework(c#).
我可以使用什么作为Vector,List(对象容器)?
我看到无法使用List或Vector
我正在尝试在不使用MS Designer的情况下为表单编写代码.
当我编译时,我总是得到同样的错误:
System.ComponentModel.*类型在未引用的程序集中定义.
这将出现在IComponent,ISynchronizeInvoke和Component中.我想我已经引用了它.
我已经尝试删除引用并重新应用它,并切换到早期版本的.net.它必须是我环境中的东西,但我找不到它.
using System;
using System.ComponentModel;
using System.Windows.Forms;
public class EmptyForm : System.Windows.Forms.Form
{
public EmptyForm()
{
}
public static int Main()
{
Application.Run(new EmptyForm());
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)

我一直在使用ac#tutorial为初学者创建一个地址簿.我按照说明操作,遇到了两个问题.
当我选择Listview框的属性时,缺少SelectedIndexChanged事件.我重新启动并刷新了几次程序.我直接写到文件,但它仍然不存在.
从列表中选择联系人时,文本框不会反映选择.我怀疑这与ui中缺少SelectedIndexChanged事件有关.即使我在代码中设置SelectedIndexChanged事件,这仍然存在.
非常感谢所有的帮助.我的代码如下
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;
using System.Web;
namespace AddressBook
{
public partial class AddressBook : Form
{
public AddressBook()
{
InitializeComponent();
}
List<Person> people = new List<Person>();
private void AddressBook_Load(object sender, EventArgs e)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (!Directory.Exists(path + "\\Address Book - Joe"))
Directory.CreateDirectory(path + "\\Address Book - Joe");
if (!File.Exists(path + "\\Address …Run Code Online (Sandbox Code Playgroud) 我有一个WinForm连接Net.Sockets到另一个程序的应用程序.
当它被关闭X或者ALT+ F4或者其他什么时,应该处理几个例程,我需要保持网络连接直到它们完成.
我认为Application.ApplicationExit Handler可以做到这一点,但是一旦我发出命令,网络连接就会消失.其他重要的事情是无法做到的.
我的表格也是即时关闭的,我需要更长一点.
这是工作Application.ApplicationExit的正确工具吗?
我把它放在我的Form类中,它App.Runs来自Main方法,它位于不同的类中.
我正在Visual C#2010中创建一个Windows窗体应用程序.
我有20个名为button1,...,button20的按钮和20个名为label1,...,label20的标签.如何更改label1的文本以响应对button1的单击,并且类似于每个按钮标签对而没有20个单独的事件处理函数?