DragDrop event not raised - drag-and-drop

This is kind of a stupid question... I'm trying to drag and drop a picturebox onto a panel. I followed some exemples, but it doesn't work. The DragDrop event of the panel is never raised. I searched thi site for a solution andfound two topics over a year old, but their solutions did not work. I created a new project, with only this code :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
panel1.DragDrop +=new DragEventHandler(panel1_DragDrop);
panel1.DragOver +=new DragEventHandler(panel1_DragOver);
}
private void panel1_DragOver(object sender, DragEventArgs e)
{
Console.WriteLine("DragOver");
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
Console.WriteLine("DragDrop");
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Console.WriteLine("Mouse");
pictureBox1.DoDragDrop(pictureBox1.Text, DragDropEffects.All);
}
}
I also set the AllowDrop of the panel and the form to true. DragOver and MouseDown are raised. Also, when I drag the picturebox, the cursor become a barred circled, like it was an operation that wasn't allowed. Is there a way that the cursor becomes the image in the picture box? I don't want the picturebox to move, only to add an item to the panel.

The problem is easy to solve.
You must just set in DragEnter appropriate Effect:
private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
After that DragDrop event is fired correctly.

Richard, the problem is that drag and drop is not as simple operation as you have coded here. Here you haven't started the drag movement which should start with code and you can read more about it here... http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dodragdrop(v=VS.90).aspx
If you just want to move the PictureBox... dragging picturebox inside winform on runtime
And finally Drag and Drop between Instances of the same Windows Forms Application
Hope this helps.

Related

How to use WebView.Reload() within SizeChanged event in .NET MAUI?

I need to refresh webView control when the ui size changed. I used SizeChanged event in some controls like Border, WebView, etc SizeChanged event. But I got this system.invalidoperationexception 'a method was called at an unexpected time error. I got this error at the beginning of running the application. The way I used:
<WebView x:Name="webView" SizeChanged="OnSizeChanged" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<WebView.Source>
...
</WebView.Source>
</WebView>
private void OnSizeChanged(object sender, EventArgs e)
{
webView.Reload();
}
Probably I used it in wrong way, or could it be a bug?
I solved the problem when I used Reload method in try-catch:
private void OnSizeChanged(object sender, EventArgs e)
{
try
{
webView.Reload();
}
catch(Exception ex)
{
}
}

Calling C# click event without actually clicking the button not working

I have below code written inside C# Form application where I am trying to get x,y and z co-ordinates from Leap Motion device.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//controller.EventContext = WindowsFormsSynchronizationContext.Current;
button1.Click += new EventHandler(button1_Click);
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
// Initialize the Controller object which connects to the Leap motion service
// and captures the hand tracking data
Controller controller = new Controller();
//Get the most recent tracking data using the Frame object
Frame frame = controller.Frame();
for (int h = 0; h < frame.Hands.Count; h++)
{
// Initialize the Hand in the given frame
Hand leapHand = frame.Hands[h];
// Get the "Pointer" finger of current hand which refers to where a person is pointing
Finger leapFinger = leapHand.Fingers[1];
// Prepare a vector which will store the co-ordinate values of the tip of the pointer
Vector currentPosition = leapFinger.StabilizedTipPosition;
textBox1.Text = Convert.ToString(currentPosition.x);
textBox2.Text = Convert.ToString(currentPosition.y);
textBox3.Text = Convert.ToString(currentPosition.z);
}
}
}
However, I need to explicitly click the button1 to display.
Any idea what's wrong ?
Here is an overly simple example of one way to do it. I'm not saying it's the best way, but you should be able to modify this sample code with your code.
In this example, there is a simple "HelloWorld" method that is called when the form is initialized as well as whenever you press the button. Let me know if this gets you close to what you're after.
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
HelloWorldTest();
}
private void button1_Click(object sender, EventArgs e)
{
HelloWorldTest();
}
private void HelloWorldTest()
{
MessageBox.Show("Hello World!");
}
}
}
For what it's worth, I didn't use your code because I don't have the Leap libraries installed and if there was a typo, I wouldn't be much help to resolve it. Nonetheless, hopefully it gets you going down the right path.

Instead of LoadLevel, how do i use SceneManager

I super new in coding and I couldn't find the right answer on the web. All I want is just change scene in my game. I've already had the buttons etc. But i can't choose the "menu" script from the On click function menus.
All answer is welcome!
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class Menu : MonoBehaviour {
public void ChangeScene(string sceneName)
{
SceneManager.LoadScene("sceneName");
}
}
Several problems here. First, the function "ChangeScene"
public void ChangeScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
}
Then, you may have a problem in your scripts since you can't add any listener to the OnClick delegate. Fix every problem thrown by the console. A strange thing is that the name of the Menu script does not appear in the Menu component. Make sure the filename is "Menu.cs"
Finally, drag & drop the button into the field under "Runtime Only" and select "Menu > ChangeScene"
You can't just plug in the Menu script to the left slot.
You have to attache Menu to a GameObject then plug that GameObject to the left slot.You will then be able to chose which script and function to send the event to on the right.
The Image below shows the wrong way to do this(This is how you are currently doing it):
The is the correct way to do it:
You can also do this from code:
public class Menu : MonoBehaviour
{
public Button playButton;
void Start()
{
//Add Button Event
playButton.onClick.AddListener(() => buttonCallBack(playButton));
}
public void ChangeScene(string sceneName)
{
SceneManager.LoadScene("sceneName");
}
private void buttonCallBack(Button buttonPressed)
{
if (buttonPressed == playButton)
{
ChangeScene("myscene");
}
}
}

how to refresh a ILPanel by clicking a button...?

i am a Student and just startet programming and try out ILNumerics.
Here is my question:
How can i refresh or replot a IlPanal after changing colormap or userdata?
I want to refresh the Surfacegraph by clicking on a button. I guess the answer is very easy, but i tried a lot the last two days... i'm a noob ;)
For example:
private void ilPanel_3D_Load(object sender, EventArgs e)
{
var scene = new ILScene();
var pc = scene.Add(new ILPlotCube(twoDMode: false));
var sf = pc.Add(new ILSurface(Z));
ilPanel_3D.Scene = scene;
}
private void button1_Click(object sender, EventArgs e)
{
// dont know what to put in here...
}
thanks
For such interactive actions you will have to access the 'synchronized copy' which every driver internally maintains of the global scene. Since a scene may get displayed by many drivers at the same time, this internal copy only reflects all changes due to user interaction / modifications.
private void button1_Click(object sender, EventArgs e) {
ilPanel_3D.GetCurrentScene().First<ILSurface>().Colormap = Colormaps.Summer;
ilPanel_3D.Refresh();
}
PS: no need to wait for two days the next time ... ! ;)
#Edit2: Actually, the update works just fine on the global scene also. But in order to broadcast the change to the ilPanel1 driver, you will have to add a call to Configure() at the end of your modifications. Configure can be called once for all changed nodes on one of their common parent nodes. So, you might simply call Configure() on the scene:
private void button1_Click(object sender, EventArgs e) {
ilPanel_3D.Scene.First<ILSurface>().Colormap = Colormaps.Summer;
ilPanel_3D.Scene.Configure();
ilPanel_3D.Refresh();
}

Silverlight 5 + AutoCompleteBox = Bug

Just installed SL5 and the toolkit, that were released few days ago.
The bug happens when you set the Text property of the AutoCompleteBox to string.Empty. It causes the AutoCompleteBox to be in a buggy state. To reproduce the bug:
add an AutoCompleteBox and a Button to the main page. Register to the TextChanged and Click events. This is the code-behind:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
auto.Text = string.Empty;
}
private void auto_TextChanged(object sender, RoutedEventArgs e)
{
// Put a break point here.
}
}
In runtime:
1) type "aa" into the autobox.
2) click the button.
3) type "q". ( TextChanged is still invoked).
4) erase the "q" - TextChanged is not invoked.
5) type "q" again - TextChanged is not invoked.
6) and so on, until you pick a new letter. And then it's starts over.
I found a workaround for this strange behavior. You need a control derived from AutoCompleteBox and overrride OnApplyTemplate method to find inner TextBox of AutoCompleteBox.
When inner TextBox TextChanged event fires you need to fire TextChanged event of AutoCompleteBox control manually.
public class CustomAutoComplete : AutoCompleteBox
{
TextBox mytext;
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
mytext = GetTemplateChild("Text") as TextBox;
mytext.TextChanged += new System.Windows.Controls.TextChangedEventHandler(mytext_TextChanged);
}
void mytext_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
this.Text = mytext.Text;
OnTextChanged(new RoutedEventArgs());
}
}