Click here to Skip to main content
16,011,120 members
Home / Discussions / C#
   

C#

 
GeneralRe: Color Names Pin
AB777116-Feb-06 22:05
AB777116-Feb-06 22:05 
GeneralRe: Color Names Pin
Joshua Quick16-Feb-06 22:45
Joshua Quick16-Feb-06 22:45 
Questionhow to get the hostname of a client pc in my network Pin
batmanAgen16-Feb-06 18:40
batmanAgen16-Feb-06 18:40 
AnswerRe: how to get the hostname of a client pc in my network Pin
fang_eric16-Feb-06 21:23
fang_eric16-Feb-06 21:23 
Questionuser control is not getting loaded Pin
sasire1816-Feb-06 18:31
sasire1816-Feb-06 18:31 
AnswerRe: user control is not getting loaded Pin
nandank8116-Feb-06 18:59
nandank8116-Feb-06 18:59 
QuestionQuestion about create simple image in c# Pin
Yanshof16-Feb-06 18:18
Yanshof16-Feb-06 18:18 
QuestionClipboard Issues Pin
nemnesic16-Feb-06 17:14
nemnesic16-Feb-06 17:14 
Hello there!
I am trying to write a simple app that will monitor and save any changes in clipboard into some kind of an array.
I found some clipboard monitor examples online and they work great monitoring clipboard; however, when i try to save a string each time it is changed the program freaks out.
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace ClipboardMonitor<br />
{<br />
	/// <summary><br />
	/// Summary description for Form1.<br />
	/// </summary><br />
	public class Form1 : System.Windows.Forms.Form<br />
	{<br />
		[DllImport("User32.dll")]<br />
		protected static extern int SetClipboardViewer(int hWndNewViewer);<br />
<br />
		[DllImport("User32.dll", CharSet=CharSet.Auto)]<br />
		public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);<br />
<br />
		[DllImport("user32.dll", CharSet=CharSet.Auto)]<br />
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);<br />
<br />
		private System.Windows.Forms.RichTextBox richTextBox1;<br />
<br />
		IntPtr nextClipboardViewer;<br />
		string dummy = "";<br />
		int n = 0;<br />
		string[] str_data = new string[50];<br />
		private System.Windows.Forms.Button button1;<br />
		private System.Windows.Forms.Button button2;<br />
<br />
		/// <summary><br />
		/// Required designer variable.<br />
		/// </summary><br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public Form1()<br />
		{<br />
			//<br />
			// Required for Windows Form Designer support<br />
			//<br />
			InitializeComponent();<br />
			nextClipboardViewer = (IntPtr)SetClipboardViewer((int) this.Handle);<br />
<br />
			//<br />
			// TODO: Add any constructor code after InitializeComponent call<br />
			//<br />
		}<br />
<br />
		/// <summary><br />
		/// Clean up any resources being used.<br />
		/// </summary><br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			ChangeClipboardChain(this.Handle, nextClipboardViewer);<br />
			if( disposing )<br />
			{<br />
				if (components != null) <br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
<br />
		#region Windows Form Designer generated code<br />
		/// <summary><br />
		/// Required method for Designer support - do not modify<br />
		/// the contents of this method with the code editor.<br />
		/// </summary><br />
		private void InitializeComponent()<br />
		{<br />
			this.richTextBox1 = new System.Windows.Forms.RichTextBox();<br />
			this.button1 = new System.Windows.Forms.Button();<br />
			this.button2 = new System.Windows.Forms.Button();<br />
			this.SuspendLayout();<br />
			// <br />
			// richTextBox1<br />
			// <br />
			this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;<br />
			this.richTextBox1.Location = new System.Drawing.Point(16, 16);<br />
			this.richTextBox1.Name = "richTextBox1";<br />
			this.richTextBox1.ReadOnly = true;<br />
			this.richTextBox1.Size = new System.Drawing.Size(544, 88);<br />
			this.richTextBox1.TabIndex = 0;<br />
			this.richTextBox1.Text = "richTextBox1";<br />
			this.richTextBox1.WordWrap = false;<br />
			this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);<br />
			// <br />
			// button1<br />
			// <br />
			this.button1.Location = new System.Drawing.Point(184, 176);<br />
			this.button1.Name = "button1";<br />
			this.button1.TabIndex = 1;<br />
			this.button1.Text = "button1";<br />
			this.button1.Click += new System.EventHandler(this.button1_Click);<br />
			// <br />
			// button2<br />
			// <br />
			this.button2.Location = new System.Drawing.Point(360, 176);<br />
			this.button2.Name = "button2";<br />
			this.button2.TabIndex = 2;<br />
			this.button2.Text = "button2";<br />
			this.button2.Click += new System.EventHandler(this.button2_Click);<br />
			// <br />
			// Form1<br />
			// <br />
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
			this.ClientSize = new System.Drawing.Size(568, 273);<br />
			this.Controls.Add(this.button2);<br />
			this.Controls.Add(this.button1);<br />
			this.Controls.Add(this.richTextBox1);<br />
			this.Name = "Form1";<br />
			this.Text = "Clipboard Monitor Example";<br />
			this.ResumeLayout(false);<br />
<br />
		}<br />
		#endregion<br />
<br />
		/// <summary><br />
		/// The main entry point for the application.<br />
		/// </summary><br />
		[STAThread]<br />
		static void Main() <br />
		{<br />
			Application.Run(new Form1());<br />
		}<br />
<br />
		protected override void WndProc(ref System.Windows.Forms.Message m)<br />
		{<br />
			// defined in winuser.h<br />
			const int WM_DRAWCLIPBOARD = 0x308;<br />
			const int WM_CHANGECBCHAIN = 0x030D;<br />
<br />
			switch(m.Msg)<br />
			{<br />
				case WM_DRAWCLIPBOARD:<br />
					//MessageBox.Show("call it");<br />
					DisplayClipboardData();<br />
					//MessageBox.Show("called!");<br />
					store_data(n);<br />
					n++;<br />
					if(n == 50)<br />
					{<br />
						MessageBox.Show("STOP!");<br />
					}<br />
					SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam);<br />
					break;<br />
<br />
				case WM_CHANGECBCHAIN:<br />
					if (m.WParam == nextClipboardViewer)<br />
						nextClipboardViewer = m.LParam;<br />
					else<br />
						SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam);<br />
					break;<br />
<br />
				default:<br />
					base.WndProc(ref m);<br />
					break;<br />
			}	<br />
			<br />
		}<br />
<br />
		void DisplayClipboardData()		<br />
		{<br />
			try<br />
			{<br />
				IDataObject iData = new DataObject();  <br />
				iData = Clipboard.GetDataObject();<br />
<br />
				if (iData.GetDataPresent(DataFormats.Rtf)) <br />
					richTextBox1.Rtf = (string)iData.GetData(DataFormats.Rtf);<br />
				else if (iData.GetDataPresent(DataFormats.Text))<br />
					richTextBox1.Text = (string)iData.GetData(DataFormats.Text);<br />
				else<br />
					richTextBox1.Text = "[Clipboard data is not RTF or ASCII Text]";<br />
			}<br />
			catch(Exception e)<br />
			{<br />
				MessageBox.Show(e.ToString());<br />
			}<br />
		}<br />
		<br />
		public void store_data(int n)<br />
		{<br />
			if(n!=0)<br />
			{<br />
				if(str_data[n - 1] == str_data[n])<br />
				{<br />
					n--;<br />
				<br />
				}<br />
				else<br />
				{<br />
					str_data[n] = richTextBox1.Text;<br />
				}<br />
			}<br />
			<br />
<br />
		}<br />
<br />
		private void richTextBox1_TextChanged(object sender, System.EventArgs e)<br />
		{<br />
		<br />
		}<br />
<br />
		private void button1_Click(object sender, System.EventArgs e)<br />
		{<br />
			MessageBox.Show(str_data[0] + "\n" +<br />
				str_data[1] + "\n" +<br />
				str_data[2] + "\n" +<br />
				str_data[3] + "\n" +<br />
				str_data[4] + "\n" +<br />
				str_data[5] + "\n" +<br />
				str_data[6] + "\n" +<br />
				str_data[7] + "\n" +<br />
				str_data[8] + "\n" +<br />
				str_data[9] + "\n" +<br />
				str_data[10] + "\n" +<br />
				str_data[11] + "\n" +<br />
				str_data[12] + "\n" +<br />
				str_data[13] + "\n" +<br />
				str_data[14]+ "\n" +<br />
				str_data[15] + "\n" +<br />
				str_data[16] + "\n" +<br />
				str_data[17] + "\n" +<br />
				str_data[18] + "\n" +<br />
				str_data[19] + "\n" +<br />
				str_data[20] + "\n" +<br />
				str_data[21] + "\n" +<br />
				str_data[22] + "\n" +<br />
				str_data[23] + "\n" +<br />
				str_data[24] + "\n" +<br />
				str_data[25] + "\n" +<br />
				str_data[26] + "\n" +<br />
				str_data[27] + "\n" +<br />
				str_data[28] + "\n" +<br />
				str_data[29] + "\n");<br />
<br />
			MessageBox.Show(str_data[30] + "\n" +<br />
				str_data[31] + "\n" +<br />
				str_data[32] + "\n" +<br />
				str_data[33] + "\n" +<br />
				str_data[34] + "\n" +<br />
				str_data[35] + "\n" +<br />
				str_data[36] + "\n" +<br />
				str_data[37] + "\n" +<br />
				str_data[38] + "\n" +<br />
				str_data[39] + "\n" +<br />
				str_data[40] + "\n");<br />
<br />
		}<br />
<br />
		private void button2_Click(object sender, System.EventArgs e)<br />
		{<br />
			<br />
        IDataObject d = Clipboard.GetDataObject();<br />
        if(d.GetDataPresent(DataFormats.Bitmap)) <br />
<br />
		{<br />
            MessageBox.Show("Bitmap data is Contained in the clipboard.");<br />
        } <br />
		else if(d.GetDataPresent(DataFormats.Text)) <br />
		{<br />
            MessageBox.Show("Text data is Contained in the clipboard.");<br />
        } <br />
		else {<br />
			MessageBox.Show("Some other format of data is Contained in the clipboard.");<br />
        }<br />
		}<br />
	}<br />
}<br />
<br />


please help.
Also, you know how Excel has that clipboard where you can copy up to 12 items. How can i Access those items?

thanks

nnn
QuestionC# 2005 - Datagrid and comboBoxes, How do I ... ? Pin
JC Carmo16-Feb-06 17:08
JC Carmo16-Feb-06 17:08 
QuestionC# 2005 - childForm setting MDIParent of another childForm Pin
JC Carmo16-Feb-06 17:06
JC Carmo16-Feb-06 17:06 
AnswerRe: C# 2005 - childForm setting MDIParent of another childForm Pin
nandank8116-Feb-06 19:10
nandank8116-Feb-06 19:10 
AnswerRe: C# 2005 - childForm setting MDIParent of another childForm Pin
AB777116-Feb-06 19:12
AB777116-Feb-06 19:12 
QuestionWebBrowser Control Callbacks Pin
Twisty McGee16-Feb-06 15:04
Twisty McGee16-Feb-06 15:04 
QuestionShow ContextMenu Automatically Pin
jgallen2316-Feb-06 14:16
jgallen2316-Feb-06 14:16 
AnswerRe: Show ContextMenu Automatically Pin
nandank8116-Feb-06 19:14
nandank8116-Feb-06 19:14 
GeneralRe: Show ContextMenu Automatically Pin
jgallen2317-Feb-06 5:32
jgallen2317-Feb-06 5:32 
QuestionModal Dialogs Pin
Tyrus18216-Feb-06 14:01
Tyrus18216-Feb-06 14:01 
AnswerRe: Modal Dialogs Pin
Joshua Quick16-Feb-06 14:28
Joshua Quick16-Feb-06 14:28 
AnswerRe: Modal Dialogs Pin
Dave Kreskowiak16-Feb-06 14:30
mveDave Kreskowiak16-Feb-06 14:30 
QuestionDataList Pin
Sean8916-Feb-06 13:53
Sean8916-Feb-06 13:53 
News[Message Deleted] Pin
Ahmad Mahmoud [candseeme]16-Feb-06 13:33
Ahmad Mahmoud [candseeme]16-Feb-06 13:33 
GeneralRe: Startup Edit Pin
Christian Graus16-Feb-06 15:49
protectorChristian Graus16-Feb-06 15:49 
GeneralRe: Startup Edit Pin
Ahmad Mahmoud [candseeme]18-Feb-06 22:20
Ahmad Mahmoud [candseeme]18-Feb-06 22:20 
GeneralRe: Startup Edit Pin
Christian Graus19-Feb-06 7:45
protectorChristian Graus19-Feb-06 7:45 
QuestionImplementing a .NET IDE Designer-like Application Pin
Pink Floyd16-Feb-06 12:50
Pink Floyd16-Feb-06 12:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.