wan't to write a outlook add-in which manipulate the email message when the user want to save the file local on the desk via drag and drop.
At the moment I'm not able to get the MouseDown event of the window. Is there an specific Windows Message which i can observe?
And is there any way to manipulate the data which is currently in the drag event?
Many thanks for you help!
I've already tried
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
Outlook.Explorer explorer;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = Application.ActiveExplorer();
explorer.BeforeItemCopy += new Outlook.ExplorerEvents_10_BeforeItemCopyEventHandler(Explorer_BeforeItemCopy);
}
private void OnDragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
MessageBox.Show("OnDragEnter");
}
void Explorer_BeforeItemCopy(ref bool cancel)
{
MessageBox.Show("copied");
}
}
}
There is no need to use Windows Messages, nor MouseDown event for this. You are simply using the wrong event. What you need to handle is:
DragEnter
DragOver
DragDrop
DragLeave
See this sample:
https://www.codeproject.com/articles/9017/a-simple-drag-and-drop-how-to-example
Related
This question already has answers here:
Process.Start to open an URL, getting an Exception?
(4 answers)
Closed 1 year ago.
I am very interested in C# winforms. I decided to make it open a browser window once I click on a link label with the default browser. I searched on the internet and found the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
try
{
VisitLink();
}
catch (Exception ex)
{
MessageBox.Show("Unable to open link that was clicked.");
}
}
private void VisitLink()
{
// Change the color of the link text by setting LinkVisited
// to true.
linkLabel1.LinkVisited = true;
//Call the Process.Start method to open the default browser
//with a URL:
System.Diagnostics.Process.Start("http://www.microsoft.com");
}
}
}
When I tried it in my code, I clicked on the link but nothing shows up. Not even an exception pops up, which made me confused. Can anyone help me? Thanks!
The link is correctly marked as visited after the click ? If not, the event is probably not even got fired. Check if you correctly add the callback on the click event
Just recently began tinkering with Awesomium, it's very cool and much better than the stock webBrowser for WinForms.
However, when I use the _LoadingFrameComplete method to determine if the page has loaded, it seems to be firing 10+ times (when used on Facebook, 2 times when navigating to google.com)
I am trying to get the comparable method of webBrowser1_DocumentCompleted (which only fires one time, after the document has completed).
Is this a 'me' problem, or am I using the wrong methods to check whether the website has finished loading completely.
I'm using Visual C# 2010 Edition
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 Debugging_Problems
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string searchURL = textBox1.Text;
webControl1.Source = new Uri(searchURL);
}
private void Awesomium_Windows_Forms_WebControl_LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
richTextBox1.AppendText("Completed.\n");
}
}
}
You need to use IsMainFrame
private void Awesomium_Windows_Forms_WebControl_LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
if (e.IsMainFrame)
{
richTextBox1.AppendText("Completed.\n");
}
}
Try putting if(e.IsMainFrame) { .... } inside your LoadingFrameComplete event handler and only put your code in there. – Jon
That was the answer. Thank you.
Question... why does this code only produce a message box "Down"? I'm not getting the Up. If I block down code, the up works.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mouse
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show("Up");
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
MessageBox.Show("Down");
}
}
}
Because you are showing a MessageBox
Whenever a mouse down event happened a MessageBox will popup. The MessageBox Will be in foreground and the up event will be on the MessageBox instead of the form. Thus the up event in the form doesn't fire
Just do a Console.WriteLine instead of MessageBox and it should work as expected
They will both fire if you remove the message box call. this is interferring with the mouse events because your loosing focus on the form. Instead of using message box try using...
Console.WriteLine("MouseUp");
This will display in the ouput window and not interfere with the events
I created a form with just 2 textboxes and a button. In the first one I type a temperature in Fahrenheit and when I press the button "Convert", the program calculates and puts the temperature in Celsius in the other TextBox. It's working fine.
Now I want the program to clear the second TextBox when I start typing in the first TextBox. Below I show just a part of the code, which didn't work. Can anybody help me?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Conv_Temp
{
public partial class Frm_Principal : Form
{
public Frm_Principal()
{
InitializeComponent();
}
public event EventHandler Leave;
private void Tb_Temp_Leave(object sender, EventArgs e)
{
MessageBox.Show("Leaving TB Tb_Temp");
Tb_Result.Text="";
}
}
}
I think you are almost there.
Try adding this under InitializeComponent();
this.Tb_Temp.TextChanged += new System.EventHandler(this.Tb_Temp_Leave);
Add new Event handler in your form designer code.
this.textBox1.TextChanged += new System.EventHandler(this.ModifyTextBox1);
and implement this event in above form.cs file(Form_Principal )
private void ModifyTextBox1(object sender, EventArgs e)
{
textBox2.Text = String.Empty;
}
Please follow good convention for writing codes this is just a demo.
Could someone explain the reason why the code below does not work?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Speaker
{ public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("bravo you did it");
}
}
}
The window I have designed that corresponds to this code is a single window with a single button. I have the intention to do quite an extented program, but encountering problems, I decided to start with a small sample to see what's wrong, and I see neither this simple code works. Any suggestions? When I press the button1, nothing happens at all.
Make sure attached the event Click with your button. You can do it by going to designer, double click the button, it will create the event handler for you in the code. You can also attach the event handler in your Form Constructor like:
public Form1()
{
InitializeComponent();
button1.Click += button1_Click;
}
You can go to the designer, right click on Button1, click properties, Got to events and there you can attach the event handler:
You need to bind the button click to the event of button click! :)
button1.Click += button1_Click;