Trying to get object reference from FixedDocument via click - c#

I am populating a FixedDocument as part of a reporting feature. I do not have control over the hows or whys of the approach, just that this is the approach used.
So I programmatically add rows to the page grid, add text controls to show the data, etc. It works.
Now I am trying to add support so that a user can click on an item in the report and I can open that item in an edit window. The only problem I am having is identifying what the user clicked on.
The FixedDocument captures the mouse clicks and ignored the mouseclick event added to the textbox.
As I add the textboxes, if I can keep track of the actual coordinates of the item added, then I can reference that via the code in the FixedDocument click event (since I have the coordinates or where the user clicked.)
What is an easy way for me to get an object reference or information about the item over which the user clicked?
I tried searching , but nothing seemed to address this given all the search terms I could think of using.
Thanks

Try listening to PreviewMouseLeftButtonUp event of your fixed document. It exposes MouseButtonEventArgs parameter from where you can lookup OriginalSource and compare it with your textbox and perform the necessary action.
You can choose to use any other Preview prefixed event for your benefit wherever you have a similar need.

Related

TextBox receiving focus when clicking on ListView

I'm struggling to make a custom autocomplete style control for my application using a list view. In one form, the custom control is working as expected, however in another, when clicking on the ListView, rather than the ListViewItem being selected, the first TextBox in the form is selected instead.
Rather than clog up the question with a wall of code, here is the code for the AutoCompleteListView.
Here is an image of the form. Items are redacted due to data protection:
Also, here is a .gif showing the behaviour of the form. What I'm doing in the aformentioned gif is attempting to click on the first item within the ListView, however, as I do that, focus changes to the first text box in the form. This same behaviour occurs when clicking on any item, in any of the 3 text boxes.
I have attempted to trace the events using RuntimeFlow to watch as events fire, but it has not provided any clarity as to what is actually happening. If anyone could point me in the right direction, that'd be greatly appreciated.
My first guess is in ItemClick you are setting visibility to false, which means something else in the form needs focus, ie the textbox. So do a textbox.focus() in ItemClick to the desired textbox. And given that you will not have access to the parent form in this class, I recommend you make an OnClose event in the AutoCompleteListView and subscribe to it in the parent form, to set the focus to somewhere.

visual studio c# windows form checkBox

I need your help
as you can see from the screenshot image
I am trying to make a font dialog where i have:
a Label to test the change that will happen when I
click in the checkbox .as you can see I have 3 checkboxs.
the problem is that I cant make all the checkboxs work together
so the text changed to Bold,Italic and underline..help me please
.....
my Form design
i try to use if else statement
and also switch one and still I don't know how to do it that is why i m here
It's a bit unclear, as others have noted, but.. if you are wanting to combine the results of checked and/or unchecked options to display the results of a user's font styling choices?
THEN:
1.) double-click in your V.S. form designer one of the checkboxes, this will create an event handler in your form's C# code file. The function created will be something like checkbox1_checked(object sender, EventArgs e)
2.) In the event handler function that Visual Studio has scaffolded for you, write all the code necessary to consider the .Checked state of all checkbox controls and update your Label1 control appropriately (depending on your goal, this may require custom .NET painting logic that is too much for a beginner to think about)
3.) Go back to the other controls on your design surface, now select them.. keeping an eye on your lower-right 'Properties' panel, (make sure its switched to the 'events' tab - i.e. click the 'lightning bolt' button). Ensure that each of the other radio buttons that do not yet have an event handler get mapped: Find the row in the Properties panel that shows the word "click" (err.. 'checked' event?). When you click into the white space on the row, next to the word 'checked', it will allow you to select the pre-existing "checkbox1_checked" event handler than you created in step 1.
UPDATED:
4.) the end goal is to wire all checkbox controls to the same event handler function in your form's code-behind.. if you double-click each checkbox at design time.. you'll create separate event handlers.. but with some learning (or following my directions above) you can point them all to the same event handler.

WPF item list for telegram-logger like Windows Media Player playlist

I want to create a data Logger for bus-communication in wpf. The bus-communication consists of telegrams that contain source adress, target adress, type of command, length of telegram and the actual data.
I want to represent those telegrams in an ListBox that looks like a media player playlist. The ListBox should be divided into columns for source adress, target adress etc.
By clicking on an element you should select the complete row.
If you click on an element twice slowly you should be able to select the contained text of the row.
If you doubleclick on an element fast a window with detailed data should open.
The first Row should contain the name of the columns with the ability to sort the data by clicking on it (with highlighting only the element on mouse over).
Is such an Control already availiable for WPF (with source code)? IF not how can i create an Control like the windows media playlist in wpf?
Thanks,
kyon
The control you want is the DataGrid. It will do many of the things you requested out of the box, but not all.
To enable opening a details dialog, you will need to handle the MouseDoubleClick event. In the handler, cast the sender as a DataGrid and get the SelectedItem or SelectedIndex property to determine which telegram to show in the details dialog.
There is a built in editing capability, which would allow you to select the text in a cell, but the user could also change this text. I'm not sure if this is what you wanted, but there is probably a way you could just cancel any change to the text if you wanted read-only.

Windows 8 UI: how can I handle right clicks?

I am making a small program for Windows 8, and I would like to let users with mouses the opportunity to right-click elements of a GridView.
While GridViews have the ItemClick event, these don't convey mouse buttons. They have a RightTapped (what does that even mean?) event, but it doesn't convey the clicked item, just the event source.
How can I tell which model object was right-clicked?
I didn't think for very long before asking this question. The target object can be accessed through event.OriginalSource.DataContext (once every bit in it has been casted to the appropriate class).
Extra care must be taken because right-clicking in the margins between grid elements still triggers the event, but on the GridView itself.

How do I trap a double-click event on a ListView that has no items?

In my C# app, I have a ListView on a Form. I want the user to be able to double-click on a section of the ListView when no items are selected in order to pop up a "New Item" dialog. The problem is that the DoubleClick event for the ListView only fires if an item is selected.
Is there a way to do this?
There is a way to do this, but you have to do some low-level drilling into the Windows machinery. It's generally not a good idea to spend a great deal of time trying to get a standard Windows control to behave in a non-standard manner.
A simpler way is to just put a "New Item" button next to your ListView. If screen real estate is an issue, you could just add an extra row at the bottom that says "{click here to add new item}", and show your dialog when the user clicks this last row.
Add an event handler for the List view's MouseDoubleClick event.
Assuming Windows Forms:
Perhaps a good workaround would be to use a ContextMenu.

Categories