WPF : How to get mouse position in Window_Loaded(object sender, RoutedEventArgs e) event - wpf

WPF : How to get mouse position in Window_Loaded(object sender, RoutedEventArgs e) event

Have you tried using PointToScreen(Mouse.GetPosition(this)) ?
(in the System.Windows.Input namespace)

Related

Routed event handlers drag drop information

If I register a class handler like so:
EventManager.RegisterClassHandler(
typeof(ListBoxItem),
DropEvent,
new RoutedEventHandler(OnListBoxItemDropEvent));
The following method signature is expected:
private void OnListBoxItemDropEvent(object sender, RoutedEventArgs e)
The standard Drop method signature is the following:
private void Drop(object sender, DragEventArgs e)
i.e. it gives you access to the DragEventArgs e
Is there a way for me to access the DragEventArgs e when registering a routed event handler?
How about creating a DragEventHandler (instead of a RoutedEventHandler)?:
EventManager.RegisterClassHandler(
typeof(ListBoxItem),
DropEvent,
new DragEventHandler(Drop));

Retrieving the state(checked/unchecked) of a checkbox column in datagridview in ADO.NET

I have added a DataGridViewCheckBoxColumn in a datagridview and want to commit changes in database on checking and unchecking this checkboxcolumn. Please assist.
Thanks.
try this:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
Debug.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
}
in CellValueChanged Event you can retrieve the changed value only if you called CommitEdit before ...

WPF path shape title

I have a path shape, i want to set a label above the path ,i put a textblock above the path then i handle the Path_MouseEnter , Path_MouseLeave and change the path background the problem is when the mouse leave the path shape to textblock the background changed the other problem when i handle the Path_MouseDown , the textblock also make a problem is there a beter way to set a label above the path shape ?
private void Path_MouseEnter(object sender, MouseEventArgs e)
{
(sender as Path).Fill = System.Windows.Media.Brushes.Yellow;
}
private void Path_MouseLeave(object sender, MouseEventArgs e)
{
(sender as Path).Fill = System.Windows.Media.Brushes.LightGray;
}
private void Path_MouseDown(object sender, MouseButtonEventArgs e)
{
}
Your question is difficult to follow, but I think you mean that you have a TextBlock overlayed on top of a Path, and when the mouse hits the textblock, your Path_MouseLeave() is triggered but your don't want it to be?
If this is the case, just set IsHitTestVisible="False" on the TextBlock to make it transparent to mouse events.

It is possible to create "new MouseButtonEventArgs" in Silverlight?

I'm newbie in Silverlight and I need to activate MouseRightButtonDown(object sender, MouseButtonEventArgs e) from an another event handler in my application.
I have found, that in WPF it is possible to do somthing like this:
public void OnContextMenuOpened(object sender, RoutedEventArgs e) {
MouseButtonEventArgs args = new MouseButtonEventArgs(
InputManager.Current.PrimaryMouseDevice,
0,
MouseButton.Right);
MouseRightButtonDown(sender, args);
}
But I have in Silverlight neither InputManager-Class nor MouseButton-Class... It is generally possible to realise something like that?
I want to do it, because I try to select an DataGridRow(within an custom control) with help of right-mouse-button. Without context menu it is easily possible, but when I switch context menu on, then context menu opens and event will not fired...
My code snippet:
public override void OnApplyTemplate() {
DataGrid = (DataGrid)GetTemplateChild("DataGrid");
DataGrid.MouseRightButtonDown += DataGridMouseRightButtonDown;
ContextMenu = (ContextMenu)GetTemplateChild("ContextMenu");
ContextMenu.Opened += OnContextMenuOpened;
}
private void DataGridMouseRightButtonDown(object sender, MouseButtonEventArgs e) {
//My code to select an DataGridRow
}
public void OnContextMenuOpened(object sender, RoutedEventArgs e) {
//This event-handler now will be always activated if I do
//right-mouse-button-click
}
Thanks a lot for help!
The Results of my research has shown, that it is impossible in silverlight -.-

What event can I change the caret in in a winforms maskedtextbox

Right now, I'm calling the win32 createcaret/showcaret in the keypress event of my masked textbox. That changes it fine. I want the caret to change when the box is entered, though, either by tab or by click.
Unfortunately the enter event or even the invalidate event aren't suitable places to change that caret. It doesn't change, maybe because they fire too early.
So anyway, how can I get the caret to change on textbox enter without handling it in the enter event?
You need to add DestroyCaret to your routine, too:
private void Form1_Load(object sender, EventArgs e)
{
textBox1.GotFocus += new EventHandler(textBox1_GotFocus);
textBox1.LostFocus += new EventHandler(textBox1_LostFocus);
}
private void textBox1_GotFocus(object sender, EventArgs e)
{
CreateCaret(textBox1.Handle, IntPtr.Zero, 6, textBox1.Height);
ShowCaret(textBox1.Handle);
}
private void textBox1_LostFocus(object sender, EventArgs e)
{
DestroyCaret();
}

Resources