Tag: c# 2.0

无法转换COM对象 – Microsoft Outlook和C#

我已编写此代码以查看Outlook邮箱中的未读项目,以下是代码: Microsoft.Office.Interop.Outlook.Application app; Microsoft.Office.Interop.Outlook.Items items; Microsoft.Office.Interop.Outlook.NameSpace ns; Microsoft.Office.Interop.Outlook.MAPIFolder inbox; Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application(); app = application; ns = application.Session; inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); items = inbox.Items; foreach (Microsoft.Office.Interop.Outlook.MailItem mail in items) { if (mail.UnRead == true) { MessageBox.Show(mail.Subject.ToString()); } } 但在foreach循环中我收到此错误: “无法将’System .__ ComObject’类型的COM对象强制转换为接口类型’Microsoft.Office.Interop.Outlook.MailItem’。此操作失败,因为QueryInterface调用COM组件为IID'{00063034-0000- 0000-C000-000000000046}’由于以下错误而失败:不支持此类接口(HRESULTexception:0x80004002(E_NOINTERFACE))。 你能帮我解决一下这个错误吗?

从非托管c ++调用托管c#函数

如何从非托管c ++调用托管c#函数

在运行时保存并重新加载app.config(applicationSettings)

我已经在app.config中存储了我的应用程序的配置,通过Visual Studio我已经在项目属性对话框的设置选项卡上创建了一些应用程序密钥,然后我在应用程序级别设置了此密钥(不是在用户级别)。 Visual Studio自动生成以下xml文件(app.config): Test.s3db 现在我想在运行时保存并重新加载设置,这是我的代码,允许在配置文件中保存值DatabasePath : Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSectionGroup applicationSectionGroup = config.GetSectionGroup(“applicationSettings”); ConfigurationSection applicationConfigSection = applicationSectionGroup.Sections[“AleTest.Properties.Settings”]; ClientSettingsSection clientSection = (ClientSettingsSection)applicationConfigSection; //Database Configuration Setting SettingElement applicationSetting = clientSection.Settings.Get(“DatabasePath”); applicationSetting.Value.ValueXml.InnerXml = this.textBoxPath.Text.Trim(); applicationConfigSection.SectionInformation.ForceSave = true; config.Save(); 问题是,使用此代码,在重新启动应用程序之前,应用程序不会加载新设置; 有没有办法在运行时重新加载配置设置? 我还想用一个变量值替换applicationSettings部分(AleTest.Properties.Settings)名称的固定值,在框架中存在一个变量,假定这个值(AleTest.Properties.Settings)?

C#Xml序列化和反序列化

我试图序列化一个对象并将其保存到Sql server 2008 xml字段中。 我还有一些反序列化代码,可以重新保存对象。 我能够将对象序列化并保存到数据库中,但是会出现“Root element missing”exception。 [XmlRoot(“Patient”)] public class PatientXml { private AddressXml _address = null; private EmergencyContactXml _emergencyContact = null; private PersonalXml _personal = null; [XmlElement] public PersonalXml Personal { get { return _personal; } set { _personal = value; } } [XmlElement] public AddressXml Address { get { return _address; } […]

如何防止打印屏幕

我要求我正在处理的应用程序阻止用户轻松捕获屏幕内容。 我已经说过没有可行的方法可以完全防止这种情况发生,但我正在寻找方法来为这个过程引入一些障碍。 我正在使用C#/ .NET 2.0和WinForms

使用C#MethodInvoker.Invoke()获取GUI应用程序……这样好吗?

使用C#2.0和MethodInvoker委托,我有一个GUI应用程序从GUI线程或工作线程接收一些事件。 我使用以下模式处理表单中的事件: private void SomeEventHandler(object sender, EventArgs e) { MethodInvoker method = delegate { uiSomeTextBox.Text = “some text”; }; if (InvokeRequired) BeginInvoke(method); else method.Invoke(); } 通过使用这种模式,我不会复制实际的UI代码,但我不确定的是这种方法是否合适。 特别是这条线 method.Invoke() 它是否使用另一个线程进行调用,或者它是否有点转换为直接调用GUI线程上的方法?

在Windows窗体中嵌入DOS控制台

是否可以在Windows窗体或C#2.0中的用户控件中嵌入DOS控制台? 我们有一个我的Windows应用程序必须与之交互的遗留DOS产品,并且已经请求遗留产品的实例应该在Windows应用程序中运行。 目前,我正在使用user32.dll找到运行DOS产品的窗口,最小化然后最大化窗口,并在窗口中键入字符。 这不是解决问题的非常好的解决方案,因为这意味着我的应用程序必须将窗口名称存储在应用程序设置中,并且要求用户在使用交互function之前返回到DOS应用程序的正确页面。 编辑:更多信息 遗留应用程序需要对用户可见,但不能在单独的窗口中显示。 我已经尝试了TimothyP的答案并且它运行得很好,但它是否可以实现相同的function,但DOS窗口可视化地嵌入在窗体或用户控件中而不是弹出它自己的窗口? 最好采用ShowDialog()方式,以便用户无法与应用程序进行交互,可以说它们处于“传统模式”。

C#:DataGridView控件中的多行文本

DataGridView控件是否可以在单元格中显示多行文本? 我正在使用Visual Studio 2005和C#。