将位图设置为MP3的封面

我一直试图将位图设置为MP3的封面艺术,但我似乎无法让它工作。 它没有抛出任何错误,但是当我播放MP3时,位图没有显示。 这就是我目前所拥有的: TagLib.File f = TagLib.File.Create(“song.mp3”); Image currentImage = getAlbumArt(result.passedAlbumID); Picture pic = new Picture(); pic.Type = PictureType.FrontCover; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Description = “Cover”; MemoryStream ms = new MemoryStream(); currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); ms.Position = 0; pic.Data = ByteVector.FromStream(ms); f.Tag.Pictures = new IPicture[1] { pic }; pictureBox1.Image = currentImage; //testing the image is correct f.Save(); ms.Close();

如何从Windows Phone应用程序启动IE7?

如何从应用程序启动IE实例? 用浏览器窗口寻呼到窗口是否更好?

使用C#发送POST数据

这是我尝试用来将POST数据发送到URL并恢复其响应的方法: public string sendPOST(string URL, string postData) { byte[] byteArray; Stream webpageStream; StreamReader webpageReader; String webpageContent; byteArray = Encoding.UTF8.GetBytes(postData); _webRequest = WebRequest.Create(URL); _webRequest.Method = “POST”; _webRequest.ContentType = “application/x-www-form-urlencoded”; _webRequest.ContentLength = byteArray.Length; webpageStream = _webRequest.GetResponse().GetResponseStream(); webpageStream.Write(byteArray, 0, byteArray.Length); webpageStream.Close(); webpageReader = new StreamReader(webpageStream); webpageContent = webpageReader.ReadToEnd(); return webpageContent; } 我从MSDN网页上获得了很多这样的代码,所以我知道我大致走在正确的轨道上……但是当我使用以下方法调用该方法时: string test = webHelper.sendPOST(“http://google.com”, “var=1”); MessageBox.Show(test); […]

一般枚举.Net控件的项目(MenuStrip,ToolStrip,StatusStrip)

我有一些代码,通常会在表单中获取所有控件并将它们放在列表中。 这是一些代码: private List GetControlList(Form parentForm) { List controlList = new List(); AddControlsToList(parentForm.Controls, controlList); return controlList; } private void AddControlsToList(Control.ControlCollection rootControls, List controlList) { foreach (Control c in rootControls) { controlList.Add(c); if (c.HasChildren) AddControlsToList(c.Controls, controlList); // } } 所以我只能使用c.HasChildren检查并查看是否还有来自此根控件的子控件。 menuStrip,toolStrip和statusStrip怎么样? 如何获得这些控件中的所有控件? 例如:MenuStripItem 我知道我可以尝试测试c.GetType()== typeof(MenuStrip),但我希望不必进行特定的类型测试。 如果我需要提供更多信息,请询问。 谢谢你们

如何在defaultProxy配置设置中传递凭据?

客户端无法使用我的webpart,因为他位于代理服务器后面,他们需要指定用户名和密码才能通过代理。 我现在在配置文件中有这个: 有没有办法为这个代理设置提供用户名和密码?

听取浏览器的请求

使用以下代码: HttpListener listener = new HttpListener(); //listener.Prefixes.Add(“http://*:80/”); listener.Prefixes.Add(“http://*:8080/”); listener.Prefixes.Add(“http://*:8081/”); listener.Prefixes.Add(“http://*:8082/”); listener.Start(); HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; 该程序挂起在GetContext(); 尽管在IE和Firefox中加载了http(而不是https)页面。 当我取消注释第一行时,我收到错误: 无法侦听前缀’http:// *:80 /’,因为它与计算机上的现有注册冲突。 那么我该如何收听浏览器的请求呢?

给定C#类型,获取其基类和实现的接口

我正在研究C#中的游戏引擎。 我正在研究的课程名为CEntityRegistry ,它的工作是跟踪游戏中CEntity的许多实例。 我的目标是能够使用给定类型查询CEntityRegistry ,并获取该类型的每个CEntity的列表。 因此,我想做的是维护一张地图: private IDictionary<Type, HashSet> m_TypeToEntitySet; 并因此更新注册表: private void m_UpdateEntityList() { foreach (CEntity theEntity in m_EntitiesToRemove.dequeueAll()) { foreach (HashSet set in m_TypeToEntitySet.Values) { if (set.Contains(theEntity)) set.Remove(theEntity); } } foreach (CEntity theEntity in m_EntitiesToAdd.dequeueAll()) { Type entityType = theEntity.GetType(); foreach (Type baseClass in entityType.GetAllBaseClassesAndInterfaces()) m_TypeToEntitySet[baseClass].Add(theEntity); } } 我Type.GetAllBaseClassesAndInterfaces的问题是没有函数Type.GetAllBaseClassesAndInterfaces – 我将如何编写它?

使用控制台应用程序在C#中使用GenerateConsoleCtrlEvent

我正在努力让这个工作变得更加困难,希望你们其中一个人之前做过这件事。 我有一个C#控制台应用程序正在运行一个inheritance其控制台的子进程。 我希望外部应用程序捕获的ctrl-c被传递到内部应用程序,以便它有机会很好地关闭。 我有一些非常简单的代码。 我启动一个进程,然后使用WaitForExit(10)进行轮询。 我还注册了一个CancelKeyPress处理程序,它在触发时将bool设置为true。 轮询循环也检查这个,当它为真时,它调用GenerateConsoleCtrlEvent()(我通过pinvoke映射)。 我已经尝试了很多params组合到GenerateConsoleCtrlEvent()。 第一个参数为0或1,第二个参数为0或子进程的ID。 似乎没什么用。 有时我得到一个假回来,Marshal.GetLastWin32Error()返回0,有时我得到回来。 但没有一个导致子应用程序接收ctrl-c。 为了绝对肯定,我编写了一个测试C#应用程序作为子应用程序,打印出它正在发生的事情,并validation在运行时手动输入ctrl-c正确导致它退出。 几个小时以来,我一直在反对这个问题。 谁能给我一些关于去哪里的指示?

以编程方式在.NET中使用制表符?

有没有办法在Environment类中使用制表符如新行字符,而不是使用”\t” ?

当UserControl具有DataContext时,UserControl的DependencyProperty为null

我已经向我的View添加了DependencyProperty,绑定到DependencyProperty工作,但前提是我还没有设置DataContext。 GenericView.xaml GenericView.xaml.cs public partial class GenericView : UserControl { // The DependencyProperty for VMFactory. public static readonly DependencyProperty VMFactoryProperty = DependencyProperty.Register(“VMFactory”, typeof(VMFactoryViewModel), typeof(GenericView)); public VMFactoryViewModel VMFactory { get { return (VMFactoryViewModel)GetValue(VMFactoryProperty); } set { SetValue(VMFactoryProperty, value); } } public GenericView() { InitializeComponent(); } } 在这里,我创建了两个视图来说明手头的问题。 第一个视图中的VMFactory绑定将失败,因为我已设置DataContext。 第二种观点会成功,这种行为的原因是什么? MainPage.xaml中