How to implement double click to a button in C# - c#-4.0

how to implement double click event for a button in C# window application
strong text

Add an event handler
btn.doubleClick += btn_doubleClick;
Then, define
private void btn_doubleClick ( object sender, EventArgs e )
{
// do stuff
}

Related

UWP mediaelement fullscreen window object not receiving event handlers

Here is the code which I am using to simply toggle fullscreen in UWP media element:
private void SingleMediaElement_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
SingleMediaElement.IsFullWindow = !SingleMediaElement.IsFullWindow;
}
I can make it fullscreen by double clicking, but I am not able to exit fullscreen, because apparently fullscreen mode is a different object. How do I receive that object and manage the same event handler on it?
Try ApplicationView instead:
private void SingleMediaElement_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
var view = ApplicationView.GetForCurrentView();
if (view.IsFullScreenMode)
view.ExitFullScreenMode();
else
view.TryEnterFullScreenMode();
}
This problem was solved by using Media element Transport controls double tapped event instead of Media Element double tapped event.

close a ContentDialog after LostFocus on it and click on the MainPage Interface

I have used a ContentDialog to create a PopUp ContentDialog like the one in the Groove App:
the problem is that,I can't close it when I click on any part of the MainPage Interface and loose focus,I have tried like this,but it doesn't work :(,it closes only after I send data from the ContentDialog
MainPage.xaml:
private void MenuButton_Click(object sender, RoutedEventArgs e)
{
AddFavoris formTask = new AddFavoris();
t = formTask.ShowAsync();
string f = formTask.Opgave;
formTask.LostFocus += new RoutedEventHandler(formTask_LostFocus);
}
private void formTask_LostFocus(object sender, RoutedEventArgs e)
{
t.Cancel();
}
so,is there any solutions can I use to have a ContrentDialog that will be closed after a Click on the MainPage interface and lost focus on it
thanks for help
Use Flyout instead of using a ContentDialog. Flyouts can be dismissed by tapping or clicking somewhere outside the flyout.
For more information: Guidelines for flyouts, Guidelines for dialog controls

How to close user control used in radgrid filtering?

I have a radgrid, for date column i have created a custom user control for filtering. I need to create a close button to close the user control. There are no close events which i can call. I don't want to make visibility collapsed. I started with something below:
public partial class DateFilterControl : UserControl, IFilteringControl
{
public event CloseEventHandler Close;
public delegate void CloseEventHandler();
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
It is throwing nullreference exception which is obvious to come. What code do i need to put to close the user control?
use Messaging Service. With this you can close the window in ViewModel so no need to give close function in Backend. Add Command property to Cancel button
<Button Content="Cancel" Command="{Binding CancelCommand}"/>
Now in the ViewModel add the RelayCommand property in that add
Messenger.Default.Send<bool>(true, typeof(XViewModel));
Now in the BackEnd of this userControl adds following in the constructor.
Messenger.Default.Register<bool>(this, typeof(ScheduleViewModel), (b) =>
{
if (b == true)
{
this.DialogResult = true;
}
});
Now u can close the Window...
This will surely helps u...

How to declare the KeyPress Event Handler in a common way to all TextBoxes?

I have 20 TextBoxes in a form. And I have a Common KeyPress Event for all of that Textboxes.
So I try to declare the keypress event like the following manner... is it possible?
for (int Cnl = 1; Cnl < 21; Cnl++)
{
((RichTextBox)Cnl).KeyPress += new KeyPressEventHandler(this.Comn_KeyPress);
}
Correct idea; but casting an int to a RichTextBox will never work. Try this:
foreach (var control in this.Controls)
{
var text = control as RichTextBox;
if (text != null)
text.KeyPress += new KeyPressEventHandler(this.Comn_KeyPress);
}
For a WPF application you can register global event handlers using the methods on the EventManager static class:
// Register the following class handlers for the TextBox XxFocus events.
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent,
new RoutedEventHandler(HandleTextBoxFocus));
Then add whatever logic you need on the event handler, for ex.:
private void HandleTextBoxFocus(Object sender, RoutedEventArgs e)
{
(sender as TextBox).SelectAll();
}

Fire parent click event when child is clicked in windows form user control

I have a user control
public partial class ButtonControl : UserControl
which has two controls of label and picturebox
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.text = new System.Windows.Forms.Label();
I have used this control in a windows form
this.appointmentButton = new DentalSoft.UI.Controls.ButtonControl();
created an event
this.appointmentButton.Click += new System.EventHandler(this.appointmentButton_Click);
but the problem is, if i click on the image or the label inside of the control, the click event doesn't fire.
I want to fire this click event no matter where the user clicks inside of the control. Is it possible?
Yes it is a simple matter. When you click on the child controls they receive the click event and the user control does not. So you can subscribe to the child control click events and when they occur simply raise the usercontrol click event and it will appear to click no matter where the mouse is positioned.
Just double click on the picturebox and the label to create the click event handlers then add a line of code to call the parent usercontrol OnClick method.
private void text_Click(object sender, EventArgs e)
{
this.OnClick(new EventArgs());
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.OnClick(new EventArgs());
}
I solved this problem the following way. I wanted to changes the background images of the parent PictureBox when the child Label was clicked. I played around some and found I could call the event handler in the following way.
private void Label_Click(object sender, EventArgs e)
{
Label label = (Label)sender;
Box_Click(label.Parent, e);
}
private void Box_Click(object sender, EventArgs e)
{
//
PictureBox box = sender as PictureBox;
//
if (isMine[int.Parse(box.Name)])
{
box.Image = Image.FromFile(#"..\..\images\BoxRedX.jpg");
MessageBox.Show("Game Over");
}
else
{
box.Image = Image.FromFile(#"..\..\images\BoxGray.jpg");
}
}
As you can see I grab the Child and using it to reference its parent and send it to the parents click event. This is the code I used to work in my project. The important method is the first on listed. The second is there for clarity to see how it passed and worked.

Resources