Tag: 添加

如何正确处理添加新项目到字典?

我有一个ASP.NET应用程序,我使用静态类作为缓存。 在静态类中是内部字典,它包含缓存的对象。 当然,在静态类中有添加/删除/清除等方法…它看起来如下: public static class CacheManager { private static Dictionary cacheItems = new Dictionary(); private static ReaderWriterLockSlim locker = new ReaderWriterLockSlim(); public static Dictionary CacheItems { get { return cacheItems; } } public static void AddCacheItem(string key, object data) { locker.EnterWriteLock(); try { cacheItems.Add(key, data); } finally { locker.ExitWriteLock(); } } … } ASP.NET应用程序运行时,项目已添加到缓存(字典)中。 […]

在Google电子表格中添加一行

我正在尝试向Google电子表格添加一行。 他们提供了一个来源https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row这个来源对我来说不起作任何人都可以告诉我,请问有什么错误的行女巫包括名称“行”。 “错误11当前上下文中不存在名称’row’” using System; using System.Collections.Generic; using System.Linq; using System.Text; using Google.GData.Client; using Google.GData.Spreadsheets; namespace Google_test3 { class Program { static void Main(string[] args) { string USERNAME = “test”; string PASSWORD = “test”; SpreadsheetsService service = new SpreadsheetsService(“MySpreadsheetIntegration-v1”); service.setUserCredentials(USERNAME, PASSWORD); // Instantiate a SpreadsheetQuery object to retrieve spreadsheets. SpreadsheetQuery query = new SpreadsheetQuery(); // […]

如何以编程方式替换.NET程序集中的嵌入资源?

我正在尝试使用C#代码替换exe(.NET,C#)文件的资源。 我找到了这篇文章并制作了这段代码(使用Mono.Cecil 0.6): AssemblyDefinition asdDefinition = AssemblyFactory.GetAssembly(“C:\\File.exe”); EmbeddedResource erTemp = new EmbeddedResource(“encFile”, ManifestResourceAttributes.Public); erTemp.Data = myNewFileBytes; asdDefinition.MainModule.Resources.RemoveAt(0); asdDefinition.MainModule.Resources.Add(erTemp); AssemblyFactory.SaveAssembly(asdDefinition, “C:\\newFile.exe”); 代码实际上是删除资源,然后添加一个具有相同名称的新资源。 资源名称为encFile并存储为encFile.exe (同时尝试)。 我测试了代码,删除工作(我可以通过文件的大小来判断)和添加,但是新文件崩溃就像我用仅删除创建的文件(用于测试) – 它就像他一样看不到被替换的资源。 我该怎么做才能解决这个问题? 可能在编辑的EXE文件中有一些变化? EXE文件以这种方式读取其资源: byte[] buffer = ProjectName.Properties.Resources.encFile;

C#将控件添加到循环中的面板

我希望为文件中的每一行添加一个按钮。 到目前为止我的代码是: StreamReader menu = new StreamReader(“menu.prefs”); int repetition = 0; while(!menu.EndOfStream) { Button dynamicbutton = new Button(); dynamicbutton.Click += new System.EventHandler(menuItem_Click); dynamicbutton.Text = menu.ReadLine(); dynamicbutton.Visible = true; dynamicbutton.Location = new Point(4+repetition*307, 4); dynamicbutton.Height = 44; dynamicbutton.Width = 203; dynamicbutton.BackColor = Color.FromArgb(40,40,40); dynamicbutton.ForeColor = Color.White; dynamicbutton.Font = new Font(“Lucida Console”, 16); dynamicbutton.Show(); menuPanel.Controls.Add(dynamicbutton); repetition++; MessageBox.Show(dynamicbutton.Location.ToString()); […]

c#从form2添加标签

Form2代码: public void button2_Click(object sender, EventArgs e) { Form1 form1form = new Form1(); Label asd = new Label(); asd.Text = “asdasasdasdasd”; form1form.Controls.Add(asd); Form2 form2form = new Form2(); form2form.close(); } 我想在form2上的form1上添加新的标签和按钮 怎么做的? 谢谢

在c#中添加数字

我有一个数字文本框,我需要将它的值添加到我尝试过此代码的另一个数字 String add = (mytextbox.Text + 2) 但它将数字2添加为另一个字符,如果我的文本框的值为13,则结果将变为132

如何将图像添加到System.Windows.Forms.ListBox?

我正在使用C#开发聊天程序,我使用ListBox管理昵称列表。 但是,客户有昵称和州(在线,离开) 所以,为了管理状态,我想在ListBox中添加图像(在线 – 绿色圆圈,远离红色圆圈)(这是我的想法) 如何将图像添加到ListBox? 请帮我。 谢谢。