• 締切済み

OutLookのメール受信通知 (C#)

教えてください。C#の勉強中でわからないところがあります。 [環境] C# 2.0 windowsXP Outlook2003 [内容] アプリケーションを起動後、 Outlookでメールを受信したら、アプリケーションでFormの表示のラベルを変更したいのでが、うまくいきません。教えてくださいませ。 ちなみに、下記のソースはMessageBoxで作成したものです。 MessageBoxだとうまくいくのですが・・・ using System; using System.Windows.Forms; using OutLook = Microsoft.Office.Interop.Outlook; [ソース] using System; using System.Windows.Forms; using OutLook = Microsoft.Office.Interop.Outlook; [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMessage());  MessageBox.Show("待機中"); MessageStand(); } /// <summary> /// OutLook待機処理 /// </summary> private static void OneSightMessageStand() { OutLook.ApplicationClass outLookApp = new OutLook.ApplicationClass(); outLookApp.NewMailEx += new OutLook.ApplicationEvents_11_NewMailExEventHandler(outLookApp_NewMailEx); } /// <summary> /// イベント処理 /// </summary> private static void outLookApp_NewMailEx(string EntryIDCollection) { MessageBox.Show("受信しました。" + EntryIDCollection, "NOTE", MessageBoxButtons.OK); # 通常ならメッセージボックスではなくイベントが発生したら、Formのラベルにメッセージを表示したい。 frmMessage objfm = new frmMessage(); objfm.label.txt = "受信しました。"; }

みんなの回答

  • gimmick
  • ベストアンサー率49% (134/270)
回答No.1

いまいち質問内容が理解できないのですが、メインのフォームのラベルにメッセージを表示したいのでしょうか? それでしたら、 this.label.Text = "受信しました。"; とするだけですが。それとも、メインのフォームとは別にフォームを表示したいのでしょうか? その場合は、 frmMessage objfm = new frmMessage(); objfm.label.Text = "受信しました。"; objfm.showDialog(); とでもしてください。

関連するQ&A

  • c#のプログラムについて。

    c#のプログラムについて。 お世話になります。 c#初心者です。 下記の様なコードを記述してますが、 「 Form1.Button1.Visible == false;」の部分で 「'WindowsFormApplication1.Form1'にButton1'の定義がありません。」 と言うエラーが出てしまいます。 どの様に定義して良いのかが分からず、悩んでいます。 どなたかお教え頂きたく宜しくお願い致します。        記 using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace WindowsFormsApplication3 { static class Program { /// <summary> /// アプリケーションのメイン エントリ ポイントです。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); string result = System.Environment.MachineName; if (result == "xxxxxxx") { Form1.Button1.Visible == false; } } } }

  • C#

    form2で入力した文字を form1で表示させたいのですが、上手くいきません。プログラムの(文字制限の為)一部だけ のせます。アドバイス よろしくお願いします。 まず、form1 public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.Label label1; private Form2 form2; /// <summary> /// 必要なデザイナ変数です。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows フォーム デザイナ サポートに必要です。 // InitializeComponent(); form2= new Form2(); label1.Text=string.Format("{0}",form2.s); // // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。 // } static void Main() { Application.Run(new Form1()); } private void menuItem2_Click(object sender, System.EventArgs e) { if (form2.ShowDialog(this) == DialogResult.OK) this.Refresh(); } } 次にform2です private void button1_Click(object sender, System.EventArgs e) { string s; s=(string)textBox1.Text; } public string s { get { return s; } }

  • C#からパワーポイントを表示

    C#でパワーポイントの資料を立ち上げて表示したいと思っていますが、 うまくいきません。 どうかアドバイスをよろしくお願いします。 使用している環境は Windows XP Office 2003 Visual Studio 2005 です。 私が書いたソースは下記の通りです。 これを実行すると、パワーポイントのからっぽのものが 立ち上がりpptpathでしているファイルの中身が表示されない 状態となります。 よろしくお願いいたします。 以下、内容------------------- 「参照」でMicrosoft Object Libraryを読み込んでおり、 また以下をusingで指定します。 using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Office.Interop.PowerPoint; using Microsoft.Office.Core; ・・・・以下が関数の該当部分です。 ApplicationClass app = new ApplicationClass(); app.Visible = MsoTriState.msoTrue; Presentation ppt = app.Presentations.Open(pptpath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); app.Activate(); よろしくお願いします。

  • Visual c# スレッド

    プログラム初心者です。 Visual c#にてスレッド関数を使ったプログラムを見よう見まねで 作りました。 スタートボタンを押すとピクチャーボックスの位置が 左から右へ移動し、ストップボタンを押すと止まる。 ピクチャーボックスの位置をテキストボックスに表示する。 というプログラムのつもりです。 デバックの状態でスタートボタンを押すとエラーメッセージが出て テキストボックスに位置を書き込むの関数のところが緑色にハイライトされます。エラーの内容は「有効でないスレッド間の操作」とありますが、どうしたら良いのか分かりません。 エラーの直し方を教えてください。 プログラムコードは以下です。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; namespace bit_map_08._1._ { public partial class Form1 : Form { private Thread thread; static private int Position = 0; static private int i; static bool BtnOnFig; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { thread = new System.Threading.Thread(newSystem.Threading.ThreadStart(MainThread)); thread.Start(); } private void PointMove() { if (i < 300) { i = i + 1; Position = Position + i; textBox1.Text = Convert.ToString(Position); pictureBox1.Left = (Position); } if (i == 300) { i = 0; } } private void MainThread() { while( true ) { Thread.Sleep(100); if (BtnOnFig == true) { PointMove(); } } } private void button1_Click(object sender, EventArgs e) { BtnOnFig = true; } private void button2_Click(object sender, EventArgs e) { BtnOnFig = false; } } }

  • C#プログラムにて

    C#プログラムにて お世話になります。 C#初心者です。 プログラムコードを書き始めで、早速行き 詰っています。 ステップでコードの動きを確認したところ、 program.csのMainから下記のForm1.csに 移りForm1のデザイナが表示されるのですが、 button3を押してもForm3が表れません。 また、ステップの黄色いカーソルと言いますか ステップの位置情報も消えています。 何がどう悪いのか分からなく困っています。 どなたかご親切な方、ご教授頂きたく 宜しくお願い致します。     記 using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { Form3 cForm3 = new Form3(); cForm3.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { DialogResult ans; ans = MessageBox.Show("最新のコード表を照会しますか?", "Microsoft Visual Studio", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (ans == DialogResult.OK) Application.Exit(); } private void button12_Click(object sender, EventArgs e) { Form4 cForm4 = new Form4(); cForm4.ShowDialog(); } } }

  • C#のタイマーについて

    タイマーのプログラムを作っています。 namespace WindowsApplication3 { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; protected System.Windows.Forms.Label label5; protected System.Windows.Forms.Label label6; protected System.Windows.Forms.Button button1; protected System.Windows.Forms.Button button2; protected DateTime dt; protected DateTime recTime; private System.Windows.Forms.GroupBox groupBox1; protected System.Windows.Forms.RadioButton radioButton1; protected System.Windows.Forms.RadioButton radioButton2; private System.Windows.Forms.Timer timer1; private System.ComponentModel.IContainer components; public Form1() { // // Windows フォーム デザイナ サポートに必要です。 // InitializeComponent(); DateTime dt; dt=DateTime.Now; string a="00"; string b=a; string c=a; label4.Text = string.Format("{0}時{1}分{2}秒", dt.Hour, dt.Minute,dt.Second); label5.Text = string.Format("{0}時{1}分{2}秒",a,b,c); label6.Text = string.Format("{0}時間{1}分{2}秒",a,b,c); // // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。 // dt=DateTime.Now; } /// <summary> /// 使用されているリソースに後処理を実行します。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows フォーム デザイナで生成されたコード /// <summary> /// デザイナ サポートに必要なメソッドです。このメソッドの内容を /// コード エディタで変更しないでください。 <<  文字数オーバーのため 省略>> /// <summary> /// アプリケーションのメイン エントリ ポイントです。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void button2_Click(object sender, System.EventArgs e) { Application.Exit(); } protected void timer1_Tick(object sender, System.EventArgs e) { DateTime dt; dt=DateTime.Now; label4.Text = string.Format("{0}時{1}分{2}秒", dt.Hour, dt.Minute,dt.Second); } protected void button1_Click(object sender, System.EventArgs e) { DateTime recTime; recTime=DateTime.Now; TimeSpan k; k=dt-recTime; label5.Text=string.Format("{0}時{1}分{2}秒",recTime.Hour,recTime.Minute,recTime.Second); label6.Text=string.Format("{0}秒",k.Seconds); } } } このプログラムでは ボタン1をクリックするとlabel6に経過時間 label5に記録時間を出力させたいのですが、TimeSpanクラスが上手く使えず、経過時間がマイナスになってしまいます。アドバイスお願いします。

  • VC2010プログラミング

    formの中に自作のクラスを定義して使用したいのですが、どこに定義すればよいのかわかりません。 #pragma once #include "XXX.h" namespace FileRename { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Form1 の概要 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: ここにコンストラクター コードを追加します // } protected: /// <summary> /// 使用中のリソースをすべてクリーンアップします。 /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ button1; XXX^ instance = gcnew XXX(); protected: private: /// <summary> /// 必要なデザイナー変数です。 /// </summary> System::ComponentModel::Container ^components;   ・   ・   ・ } XXXクラスはこの場所で定義するのは間違いなのでしょうか?

  • C# フォームを閉じてもプログラムが終了しない

    前略 ・C#の初心者です。 ・下記のようなプログラムを作りたいと思っています。プログラムは<作りたいプログラム>の仕様どうりに動作していますが、Form1のFormClosingイベントに Application.Exit()を追加しないと フォーム1で "X"(閉じる)をクリックしても(フォームは非表示になりますが)プログラムが終了しません。プログラムでどこかおかしな部分があると思っています。Application.Exit()を追加しないでもプログラムを終了する方法を教えてください。 <作りたいプログラム> (1)Form1 のbutton1をクリックすると新しいForm2が作成され表示される。Form2が表示されるとForm1は非表示となる。 (2)Form2 のbutton1をクリックするとForm2が非表示となりForm1が表示される。 (3)Form1 の "X"(閉じる)をクリックしてプログラムを終了する。 //Form1.cs 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; namespace formClose { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 form2 = new Form2(); form2.Show(); //フォーム2を表示 this.Hide(); //フォーム1を非表示 } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Application.Exit(); //アプリケーション終了 } } } //Form2.cs 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; namespace formClose { public partial class Form2 : Form { Form1 form1 = new Form1(); public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Close(); //フォーム2を閉じる } private void Form2_FormClosing(object sender, FormClosingEventArgs e) { form1.Show(); //フォーム1を表示する } } } 以上

  • C#の継承関係。

    すこし、疑問におもい質問いたします。 以下のようなコードなのですが using System; using System.Windows.Forms; public class MainClass{ public static void Main (){ Test01 obj01 , obj02; Test02 obj03 , obj04; obj01= new Test01(); obj01.method01(); obj03 = new Test02(); obj03.method02(); try{ obj02 = (Test01)obj03;(1) //obj02.methodp();(2) obj04 = (Test02)obj01;(3) }catch(Exception e){ MessageBox.Show(e.Message); } } } public class Test01{ public void method01(){ MessageBox.Show("スーパークラスメソッド"); } private void methodp (){ MessageBox.Show("スーパークラスプライベートメソッド"); } } public class Test02 : Test01{ public void method02(){ MessageBox.Show("サブクラスメソッド"); } } まず(1)の箇所ですが、これはTest02というTest01のクラスを継承したサブクラスを Test01という親クラスにキャストしてます。 これは、問題なく動いているようです。 ただ、その下の(2)の箇所でキャストしたインスタンスから親クラスのプライベートメソッドにアクセスしようとしたらコンパイル時にエラーとなりました。 サブクラスを親クラスにしても親クラスのプライベートメソッドって使えないのでしょうか?であれば親クラスへのキャストって何のためにあるのでしょうか? 次に(3)の箇所ですが、これはTest01という親クラスをTest02という子クラスにキャストしようとしていますが、どうも、親クラスから子クラスへキャストできないといいう例外が 発生するようです。 これはなぜなのでしょうか? 以上の点でご教授いただけませんでしょうか? よろしくお願いします。

  • C#でExcelを起動したい

    http://jeanne.wankuma.com/tips/csharp/excel/execute.html を参考に C#コードに // Excel.Application の新しいインスタンスを生成する Excel.Application xlApplication = new Excel.Application(); // Excel を表示する xlApplication.Visible = true; // 1000 ミリ秒 (1秒) 待機する System.Threading.Thread.Sleep(1000); // Excel を終了する xlApplication.Quit(); // COM オブジェクトの参照カウントを解放する (正しくは COM オブジェクトの参照カウントを解放する を参照) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication); を追加したのですが エラー CS0246: 型または名前空間名 'Excel' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足しています。 が出てしまいます。 以下の様にしているのですが、何のusingを追加すればよいのでしょうか? 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; namespace testproject { public partial class testproject: Form { public testproject() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Excel.Application の新しいインスタンスを生成する Excel.Application xlApplication = new Excel.Application(); // Excel を表示する xlApplication.Visible = true; // 1000 ミリ秒 (1秒) 待機する System.Threading.Thread.Sleep(1000); // Excel を終了する xlApplication.Quit(); // COM オブジェクトの参照カウントを解放する (正しくは COM オブジェクトの参照カウントを解放する を参照) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication); ImageViewer imgViewer = new ImageViewer(); imgViewer.Show();

専門家に質問してみよう