Background.
I have a very simple picture box on which I am streaming video using expression encoder sdk 4.
Problem:
I am unable to get a double click event on it.
deviceSource.PreviewWindow = new PreviewWindow(new HandleRef(PicBox, PicBox.Handle));
PicBox.MouseDoubleClick += new System.EventHandler(this.PicBox_DoubleClick);
private void PicBox_DoubleClick(object sender, EventArgs e)
{MessageBox.Show("");
}
What am I missing ?
You need to specify what event you wish the DoubleClick function to be called for
PicBox += new System.EventHandler(this.PicBox_DoubleClick);
Should be
PicBox.MouseDoubleClick += new System.EventHandler(this.PicBox_DoubleClick);
Related
Morning all,
I have a c# app where if you press a start button a dialog box will open and the OK button will be automatically pressed. The problem is I don't know how to do this.
The code is below:
private void Start_Click(object sender, EventArgs e)
{
if (captureDevice.ShowDialog(this) == DialogResult.OK)
{
var videoSource = captureDevice.VideoDevice;
FinalVideo = captureDevice.VideoDevice;
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
}
}
I have tried:
Removing the if statement to directly run whats inside it
Put DialogResult.OK = true before the if statement
CaptureDevice.DialogResult.OK = true before the if statement;
Image shows the dialogbox when start is pressed
This dialog let you select the source capturing device. If you want to bypass this dialog you should specify source device in your code. if you use AForge.Net this link help you. if not search for appropriate solution in documentation of component or library you use.
Add a new button to your form. Call it "Settings". In the event handler for this button, you roughly put the first half of what you have now for the Start button. Create a Settings object in your MainForm in which you will store the camera chosen.
private void Settings_Click(object sender, EventArgs e)
{
if (captureDevice.ShowDialog(this) == DialogResult.OK)
{
settings.VideoSource = captureDevice.VideoDevice;
}
}
private void Start_Click(object sender, EventArgs e)
{
FinalVideo = settings.VideoSource;
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
}
Hope this helps.
I have sort of found a solution to the question and it was to use:
SendKeys.Send("{ENTER}");
I used it before the if statement and it works with the Start_Click method but when i use it in a method called Start_Vid(), I get the error:
'SendKeys cannot run inside this application because the application is not handling Windows messages. Either change the application to handle messages, or use the SendKeys.SendWait method'
I have no idea why it should not work and what the error message means so should I be creating another question to have this answered or can it be solved in here do you think?
Someone knows, why double tap event won't fire on MediaElement, while in full window mode? Simple as that, when in FullWindow Double Tapped event won't trigger! Windows 10 Universal App!
private void MediaElement_DoubleTapped(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
{
mediaElement.IsFullWindow = !mediaElement.IsFullWindow;
}
Ok found a way to make this work, in place of mediaelement.DoubleTapped use
mediaElement.TransportControls.DoubleTapped += TransportControls_DoubleTapped;
private void TransportControls_DoubleTapped(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
{
mediaElement.IsFullWindow = !mediaElement.IsFullWindow;
}
But there is a problem, you can double tap on controls and it will work!
I have a canvas ,inside it an image control which has events ManipulationDelta Event , Click Event etc etc.
I have an ADD button which add an image control to the canvas
Image image = new Image();
string url = "ms-appx:///Assets/992829_484663934955807_859212711_n.jpg";
BitmapImage bm = new BitmapImage();
bm.UriSource = new Uri(url, UriKind.Absolute);
image.Source = bm;
image.Height = 100;
image.Width = 100;
MyCanvas.Children.Add(image);
Now I want to create same events for this controls and many other also dynamically so that they have their own ManipulationDelta and Click events . How to achieve that ? Should I use Anonymous methods,Lambda Expressions etc. Just a hint which will guide me??
subscribe event like this
image.ManipulationDelta += image_ManipulationDelta;
image.Tapped += image_Tapped;
void image_Tapped(object sender, TappedRoutedEventArgs e)
{
//do something
}
void image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
//do somthing
}
in Visual Studio .. just type image.ManipulationDelta += and then press Tab 2 times. It will create event handler method automatically
also you can create event handler by using Anonymous method
image.ManipulationDelta += (sender, e) =>
{
//do something
};
I looking for some solutions, but find nothing about it. I would like to simply create buttons from code behind and modify them how i wants. The idea is to create a button which can use "Tapped" or "Clicked" method.
But when i want to add the method "Tapped" I can't find how. Have you any ideas ?
button = new Image { Width = 100 , Height = 100 };
button.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:/Assets/image.png"));
Canvas.SetLeft(button, width);
Canvas.SetTop(button, height);
canvasPlan.Children.Add(button);
I found this thing, but i don't know how to use it :
button.Tapped += .. ?
Thanks for your time,
Regards.
button.Tapped += is an event. You'll need to assign an event-handler using the += syntax.
The event-handler is a method that has the signature public void EventHandler(object sender, TappedRoutedEventArgs e).
You'll need to define what is to happen in the body of the method:
public void EventHandler(object sender, TappedRoutedEventArgs e){
//determine what happens here
}
See the Button-Control and MSDN
I am working on a piano in C#. I have encountered a small problem.
I have a piano keyboard which, when pressed, displays the relevant note on the staff.
The notes created are stored in an array of type PictureBox, called picBox. I have constructed the following event handler, however it is not working.
private void pictureBox_Click(object sender, MouseEventArgs e)
{
picBox[0].MouseDown += new MouseEventHandler(pic_Click); //testing for first location
}
private void pic_Click(object sender, MouseEventArgs e)
{
ClickedTextBox.Text = "I was clicked";
}
I am just testing to see if the first note was clicked. Why is this not working?
Here is the method which adds the picturebox (containing the note) to the staff (panel3).
public void addPictureBox(int x, int y, Image image)
{
picBox[cnt] = new PictureBox();
picBox[cnt].Image = image;
picBox[cnt].Location = new Point(x, y);
picBox[cnt].BackColor = Color.Transparent;
panel3.Controls.Add(picBox[cnt]);
picBox[cnt].BringToFront();
cnt++;
}
What is wrong with my event handler please? Also, what can I do to identify the location in the array of the picturebox clicked? Thank you
As said in the first comment, you subscribe to the event in a wrong location.
Also use the sender parameter of your event handler to know which picturebox is clicked (it'll contain an instance of the picturebox).