Tag: C#的

在C#中转换位图PixelFormats

我需要将PixelFormat.Format32bppRgb的位图转换为PixelFormat.Format32bppArgb 。 我希望能够使用Bitmap.Clone,但似乎没有工作。 Bitmap orig = new Bitmap("orig.bmp"); Bitmap clone = orig.Clone(new Rectangle(0,0,orig.Width,orig.Height), PixelFormat.Format24bppArgb); 如果我运行上面的代码,然后检查clone.PixelFormat它被设置为PixelFormat.Format32bppRgb 。 发生了什么/如何转换格式?

types是在未引用的程序集中定义的,如何find原因?

我知道这个错误信息很常见,关于这个错误还有很多问题,但是到目前为止还没有解决scheme帮助我,所以我决定提出这个问题。 与大多数类似的问题不同的是我使用App_Code目录。 错误信息: CS0012: The type 'Project.Rights.OperationsProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'Project.Rights, version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. 源文件: c:\inetpub\wwwroot\Test\Website\App_Code\Company\Project\BusinessLogic\Manager.cs 以下是在这里和这里的build议,我已经删除了C:\ Windows \ Microsoft.NET /*.*内的Project.Rights.dll的所有实例根据这个 ,我检查如果有问题的.cs文件生成操作设置为“编译” 。 他们是这样。 我也双重检查包含“Project.Rights.OperationsProvider”types的.cs文件部署到App_Code目录。 出于某种原因,应用程序不在App_Code目录中查找types。 由于我已经删除了Project.Rights.dll的所有实例(我知道),我不知道哪个程序集错误消息提及。

DbContext线程安全吗?

我想知道是否DbContext类是线程安全的,我假设它不是,因为我目前正在执行DbContext线程访问我的应用程序中的DbContext ,我得到了一大堆的lockingexception和其他东西看起来像他们可能是线程有关。 直到最近我没有得到任何错误…但直到最近我没有访问线程中的DbContext 。 如果我是对的,人们会提出什么样的解决scheme?

从C#窗体窗体应用程序中检索当前的URL

我一直在使用Visual C#devise一个程序,并遇到了一个问题,使我的程序与网页浏览器交互。 基本上我需要的是从networking浏览器(Internet Explorer,Firefox,Chrome等)检索URL地址。 我觉得这个任务不会太困难,但经过几天的研究和testing,看起来几乎是不可能的! 到目前为止,我遇到了这个… 获取Firefoxurl? 其中有以下代码: using NDde.Client; Class Test { public static string GetFirefoxURL() { DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo"); dde.Connect(); string url = dde.Request("URL", int.MaxValue); dde.Disconnect(); return url; } } 这是Firefox的完美,但由于某种原因,我不能让它与其他任何工作。 我已经将代码中的“Firefox”部分更改为“Iexplore”,就像我在互联网上发现的一样,并尝试其他forms的Internet Explorer,我得到以下错误: “客户端无法连接到”IExplorer | WWW_GetWindowInfo“,请确保服务器应用程序正在运行,并且它支持指定的服务名称和主题名称对” 任何有关这个问题的帮助将非常感激,因为它已成为一个相当的任务搞清楚。

关于vector增长

已经通过书籍:C ++入门书,第三版由斯坦利·李普曼,何塞·拉霍伊 直到现在发现了一个错误。 …在第6.3节中介绍的程序如何生成一个载体,这个程序错过了一个“<”在couts! 给出的scheme是: #include <vector> #include <iostream> int main(){ vector< int > ivec; cout < "ivec: size: " < ivec.size() < " capacity: " < ivec.capacity() < endl; for ( int ix = 0; ix < 24; ++ix ) { ivec.push_back( ix ); cout < "ivec: size: " < ivec.size() < " capacity: […]

我如何发送ctrl + c到c#中的进程?

我正在编写一个命令行可执行文件的包装类。 这个EXE接受来自stdin的input,直到我在命令提示符shell中按ctrl + c,在这种情况下,它将基于input的输出打印到标准输出。 我想模拟ctrl + c按c#代码,发送杀死命令到一个.Net过程对象。 我已经尝试过调用Process.kill(),但是在进程的StandardOutput StreamReader中似乎没有给我任何东西。 可能有什么我不正确的做法? 这是我正在尝试使用的代码: ProcessStartInfo info = new ProcessStartInfo(exe, args); info.RedirectStandardError = true; info.RedirectStandardInput = true; info.RedirectStandardOutput = true; info.UseShellExecute = false; Process p = Process.Start(info); p.StandardInput.AutoFlush = true; p.StandardInput.WriteLine(scriptcode); p.Kill(); string error = p.StandardError.ReadToEnd(); if (!String.IsNullOrEmpty(error)) { throw new Exception(error); } string output = p.StandardOutput.ReadToEnd(); 但是输出总是空的,即使我手动运行exe时从stdout中获取数据。 编辑:这是c#2.0顺便说一句

如何在控制台应用程序中处理按键事件

我想创build一个控制台应用程序,将显示在控制台屏幕上按下的键,我到目前为止的代码: static void Main(string[] args) { // this is absolutely wrong, but I hope you get what I mean PreviewKeyDownEventArgs += new PreviewKeyDownEventArgs(keylogger); } private void keylogger(KeyEventArgs e) { Console.Write(e.KeyCode); } 我想知道,我应该input什么,所以我可以打电话给那个事件?

findstring的通用前缀

我有4个string: "h:/a/b/c" "h:/a/b/d" "h:/a/b/e" "h:/a/c" 我想find这些string的通用前缀,即"h:/a" 。 如何find? 通常我会用分隔符'/'分隔string,并把它放在另一个列表中,依此类推。 有没有更好的方法来做到这一点?

?:当一个expression式为空时的三元条件运算符行为

我正在编写一个控制台应用程序,试图通过反复试验来“猜测”一个数字,它运行良好,但是所有这些都让我不知道我写了些什么, 代码是: #include <stdio.h> #include <stdlib.h> int main() { int x,i,a,cc; for(;;){ scanf("%d",&x); a=50; i=100/a; for(cc=0;;cc++) { if(x<a) { printf("%d was too big\n",a); a=a-((100/(i<<=1))?:1); } else if (x>a) { printf("%d was too small\n",a); a=a+((100/(i<<=1))?:1); } else { printf("%d was the right number\n—————–%d———————\n",a,cc); break; } } } return 0; } 更具体地说,困惑我的部分是 a=a+((100/(i<<=1))?:1); //Code, code a=a-((100/(i<<=1))?:1); 我使用((100/(i<<=1))?:1)确保如果100/(i<<=1)返回0(或false),整个expression式将评估为1 […]

CMake:如何设置Source,Library和CMakeLists.txt的依赖关系?

我有几个项目(全部使用来自同一个源代码树结构的CMake构build)都使用自己的混合数十个支持库。 所以我提出了如何在CMake中正确设置这个问题。 到目前为止,我只find了CMake如何正确创build目标之间的依赖关系,但我仍然在设置所有与全局依赖关系(项目级别都知道这一切)或与本地依赖关系(每个子级目标只处理自己的依赖)。 这里是我的目录结构和我目前使用CMake和本地依赖关系的例子(这个例子只显示了一个可执行项目App1 ,但实际上有更多的App2 , App3 ,…): Lib +– LibA +– Inc +– ah +– Src +– a.cc +– CMakeLists.txt +– LibB +– Inc +– bh +– Src +– b.cc +– CMakeLists.txt +– LibC +– Inc +– ch +– Src +– c.cc +– CMakeLists.txt App1 +– Src +– main.cc +– CMakeLists.txt LIB /力霸/的CMakeLists.txt include_directories(Inc […]