Loading...
Searching...
No Matches
Form1.cs
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using System.Runtime.InteropServices;
10
12{
23 public partial class Form1 : Form
24 {
25 private int WM_COPYDATA = 0x004A;
26
27 public Form1()
28 {
29 InitializeComponent();
30 }
31 public Form1(String title)
32 {
33 InitializeComponent();
34 this.Text = title;
35 this.Select();
36 }
37
38 public struct COPYDATASTRUCT
39 {
40 public IntPtr dwData;
41 public int cbData;
42 [MarshalAs(UnmanagedType.LPStr)]
43 public string lpData;
44 }
45
46 [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
47 protected override void WndProc(ref Message m)
48 {
49 if (m.Msg == WM_COPYDATA)
50 {
51 COPYDATASTRUCT mystr = new COPYDATASTRUCT();
52 Type mytype = mystr.GetType();
53 String text = ((COPYDATASTRUCT)m.GetLParam(mytype)).lpData;
54
55 if (text.ToLower().Trim().Equals("@CopyToClipboard".ToLower()))
56 {
57 CopyToClipboard();
58 }
59 else if (text.ToLower().Trim().StartsWith("@SaveAs".ToLower()))
60 {
61 String fileName = text.Split()[1];
62 SaveAs(fileName);
63 }
64 else if (text.ToLower().Trim().Equals("@Terminate".ToLower()))
65 {
66 this.Close();
67 }
68 else
69 {
70 this.richTextBox1.Text += DateTime.Now.ToString("HH:mm:ss tt") + ": " + text + Environment.NewLine;
71 this.richTextBox1.SelectionStart = this.richTextBox1.Text.Length;
72 this.richTextBox1.ScrollToCaret();
73 }
74 }
75 base.WndProc(ref m);
76 }
77
78 private void CopyToClipboard()
79 {
80 if (this.richTextBox1.Text != null && this.richTextBox1.Text != "")
81 Clipboard.SetText(this.richTextBox1.Text);
82 }
83
84 private void SaveAs(String fileName)
85 {
86 this.richTextBox1.SaveFile(fileName, RichTextBoxStreamType.PlainText);
87 }
88
89 private void button1_Click(object sender, EventArgs e)
90 {
91 CopyToClipboard();
92 }
93
94 private void button2_Click(object sender, EventArgs e)
95 {
96 SaveFileDialog sfd = new SaveFileDialog();
97 sfd.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
98 if (sfd.ShowDialog() == DialogResult.OK)
99 SaveAs(sfd.FileName);
100 }
101 }
102}
The little example demonstrates how to implement a custom visual log. From GAMS one can send messages...
Definition: Form1.cs:24