小编Rya*_*tes的帖子

更改嵌入式资源文件中的内容

我想更改从嵌入资源作为加载的文件的内容。

以下代码获取文件:

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 的情况下修改此文件?

c# text text-files

0
推荐指数
1
解决办法
3240
查看次数

将"Control"转换为文本框并为其指定值

我正在尝试创建一个表单.表单控件名称始终是相同的.但是控制的类型会改变.例如,我有一个名为"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)

c# asp.net controls

0
推荐指数
1
解决办法
2万
查看次数

.Net 1.1框架容器

我必须使用1.1 .NET版本Framework(c#).

我可以使用什么作为Vector,List(对象容器)?

我看到无法使用List或Vector

c# .net-1.1 list vector

0
推荐指数
1
解决办法
178
查看次数

如何将 Ultragroupbox 的文本居中?

我有一个包含UltraGroupBox的 Windows 窗体。

如何让 UltraGroupBox 上的文本居中?

现在它看起来像这样:

标题左对齐的表格图片

c# infragistics winforms

0
推荐指数
1
解决办法
546
查看次数

C#(Visual Studio 2010)未找到包含的引用

我正在尝试在不使用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)

我的Visual Studio的屏幕截图.

c# reference visual-studio-2010

0
推荐指数
1
解决办法
286
查看次数

地址簿教程

我一直在使用ac#tutorial为初学者创建一个地址簿.我按照说明操作,遇到了两个问题.

  1. 当我选择Listview框的属性时,缺少SelectedIndexChanged事件.我重新启动并刷新了几次程序.我直接写到文件,但它仍然不存在.

  2. 从列表中选择联系人时,文本框不会反映选择.我怀疑这与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)

c# visual-studio-2010

-1
推荐指数
1
解决办法
5283
查看次数

订购程序后调用几个方法关闭

我有一个WinForm连接Net.Sockets到另一个程序的应用程序.

当它被关闭X或者ALT+ F4或者其他什么时,应该处理几个例程,我需要保持网络连接直到它们完成.

我认为Application.ApplicationExit Handler可以做到这一点,但是一旦我发出命令,网络连接就会消失.其他重要的事情是无法做到的.

我的表格也是即时关闭的,我需要更长一点.

这是工作Application.ApplicationExit的正确工具吗?

我把它放在我的Form类中,它App.Runs来自Main方法,它位于不同的类中.

c# winforms

-1
推荐指数
1
解决办法
36
查看次数

按名称引用表单元素

我正在Visual C#2010中创建一个Windows窗体应用程序.

我有20个名为button1,...,button20的按钮和20个名为label1,...,label20的标签.如何更改label1的文本以响应对button1的单击,并且类似于每个按钮标签对而没有20个单独的事件处理函数?

c# winforms

-2
推荐指数
1
解决办法
99
查看次数