ClickEvent in message - c#

I am trying to write a tooltip which is clickable. Currently i am thinking about a usercontrol which derives from IButtonControl and ToolTip.
public partial class JLToolTip : ToolTip, IButtonControl
As far as I can see it does everything a normal tooltip should do but if I click it
, the window loses shortly the focus until it gets it after a half second or so back.
The first thing i am trying to accomplish is this.
public void PerformClick()
{
MessageBox.Show("CLICK");
}
I know it looks dead simple but I can't find the proper solution or why it won't work
I hope anybody of you does have an answer.

If all you want is clickable and composable tooltip control, I recomment Simple Popup Control. You can easily extend it and adopt it to your needs.
I don't fully understand your question, but I think this is what you are looking for.

Related

How to set the blinking cursor to WPF Editable ComboBox?

In my WPF program I have a standard ComboBox (Editable). My desired behavior is that upon FormLoad, I would like the user to be able to type into the ComboBox and select from the list. (At FormLoad I've already populated it with some strings.) So I set comboBox.Focus(), and since I have IsTextSearchEnabled="True", which is the default behavior, this works fine.
My problem is, when comboBox.Focus() is set, it does indeed focuses the control, but I do not get the blinking cursor inside it. This is what it looks like:
This in theory gets the job done, but I believe it's not very user-friendly. I would like the ComboBox to be focused, and also have the blinking cursor.
I get the blinking cursor when I click on the editable ComboBox, so I looked up what event gets fired when I do that. Turns out it's PreviewMouseLeftButtonDown, so I tried programmatically firing this event (although this is something I usually try to avoid) to see if that will be an option. This is my code:
comboBox.RaiseEvent
(
new MouseButtonEventArgs
(
Mouse.PrimaryDevice,
Environment.TickCount,
MouseButton.Left
)
{
RoutedEvent = PreviewMouseLeftButtonDownEvent
}
);
I used a Console.WriteLine() to print a simple message to verify in Output Window if the event gets fired, and indeed it does. However, I still do NOT get the blinking cursor in my ComboBox.
Then I looked through SO, and found this question and the OP's edited fix seems to work. However this seems like quite a bit round-about way to get a seemingly simple task done, so I'm wondering if there's a rather straightforward or simpler way that I can achieve the desired result.
Calling the Focus() method once the window has loaded seems to work just fine for me:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
this.Loaded += (s,e) => comboBox.Focus();
}
}
If it doesn't work for you, then please provide a reproducible sample of your issue: https://stackoverflow.com/help/mcve

How to wait for a response from a wpf mvvm popup

I've searched but cannot find an answer to this question, and maybe that means there is a better way to do what I'm attempting.
In a WPF application, using MVVM design pattern: I've created a UserControl that is a box. This popup box has two options (buttons) on it, "Okay" and "Cancel". This user control has it's own view model to supply it's message data. Creating and showing this popup is simple enough. My trouble is I would like to wait for the users choice. Something similar to a DialogReponse? Ideally I would like to do something like this:
if (MyPopup.Show())
{
//do something
}
else
{
//do something else
}
Maybe there is a better approach to what I'm trying to do. I don't want to use a message box as I have the custom popup I've made. But maybe popup is the wrong control? Thanks ahead of time for any help.
If you want to have the functionality of a Window, why not use one?
new MyCustomDialogWindow().ShowDialog();
Use ShowDialog() method. For more information read MSDN

ToolStrip with custom ToolStripControlHost makes tab order focus act weird

I'm experiencing some strange behavior. Let me try to explain, I stripped my code down to the bare minimum and I'm still having the problem. So first of all, I'm using VS2013 with .NET 4.0 and I'm on Windows 8.1.
So I have a custom UserControl with a TextBox that's being used through a ToolStripControlHost, if I focus on this textbox and hit TAB, it only cycles through the controls to the LEFT of this textbox. If I have it focused and hit SHIFT+TAB, it cycles through the buttons to the right of it.
So this is an example of my form. The textbox in the middle is a custom control. My code (as simplified as possible) looks like:
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
public class ToolStripTestControl : ToolStripControlHost
{
public ToolStripTestControl() : this(new TestControl()) { }
public ToolStripTestControl(Control c) : base(c) { }
}
public class TestControl : UserControl
{
private TextBox _textBox = new TextBox();
public TestControl()
{
_textBox.Dock = DockStyle.Fill;
this.Controls.Add(_textBox);
}
protected override Size DefaultMinimumSize { get { return new Size(100, 22); } }
}
Simply creating a new WinForms (.NET4) project and following these steps will allow you to replicate the problem:
Add new class file and paste the code above.
Build
Add a ToolStrip to your form
On the ToolStrip add a Button, my custom control, and another Button (through the designer is how I've been doing it)
Run
Once running...
Focus in the custom control
Hit TAB a few times, it should only focus on controls to the left.
Hit SHIFT+TAB a few times and it will only focus to the right.
Does anyone know what the problem is - or how I can fix this? I've been tearing my hair out all day trying to fix this. I finally stripped my code down and I can't seem to get it to work. I even tried overriding much of the OnEnter/OnGotFocus functionality and doing it myself, but that became a nightmare.
Thanks!
Update1: So a few extra tid-bits.
If I change the custom control to inherit from TextBox instead of UserControl, tabbing/focus works as expected.
If I change it to be a Control instead of a UserControl the tabbing works fine, as well, however the focus never gets inside my inner TextBox - the focus seems to be lost (or presumably on the outer parent control but not being passed down to the inner TextBox).
I do see a MS Connect item added that describes this problem from 2009, but this link only seems to work if I'm NOT logged in to Microsoft Connect. Which means, I can't vote on it or comment... http://connect.microsoft.com/VisualStudio/feedback/details/472592/tab-cycling-through-controls-with-usercontrol-on-toolstrip-doesnt-perform-as-expected
The .NET 2.0 ToolStripItem classes have been a major bug factory. They are window-less controls, but reproducing the exact behavior of a Windows window isn't that easy. There is an enormous amount of code underneath, most of it internal so you can't tinker with it. And with quirks when they don't emulate the behavior of a window perfectly. You could call them "airspace" issues, pretty similar to the kind of problems that WPF has.
The airspace issue here is focus, entirely unambiguous for a true window but it needs to be faked for a ToolStripItem. It is actually the item's parent that has the focus, it needs to be emulated for the item. It is the transition that bytes, ToolStrip expects a window-based control to have a reliable Focus property.
Trouble is, your custom host doesn't. It is the inner control that has the focus. This could arguably be blamed on an omission in the ToolStripControlHost class. Probably. The trouble with emulating a window, there's never enough code :)
Anyhoo, fix your problem by adding this sliver of code to your host:
public override bool Focused {
get { return _textBox.Focused; }
}

Looking for controls on parent page from DevExpress ASPXPopUpControl

good sirs!
I've been messing around with the next scenario:
First, I have a webform structured as a WebForm containing a DevExpress ASPXPopUpControl and some other controls. Inside the PopUpControl there is a UserControl (lets call it ucA) containing some other controls and a UserControl (called ucB) that contains a cursed ASPxHtmlEditor (added because it's a new requirement).
When the user hits a button on main webform I show the PopUp (originally was a jQuery dialog but since HTMLEditor messes up with jQuery I've been forced to break the standard and use the popup) which contains the ucA. The user fills some fields in ucA and hit the save button. After user hits, I save some dataz and at this point I need to recover a textbox value placed in the webform.
I'm using Parent.FindControl["myTextBox"] but it considers the popupcontrol as parent. When I was using jQuery (before implementing the editor) it worked like a charm.
I feel it's something trivial but thrust me when I say that this stole many hours of research.
Thanks in advance.
EDIT I forgot to mention that I want to look for another UserControl at main webform. This uc its used to display core messages to the user so when he hits the save button, save happens, popup is closed and i look (Parent.FindControl("myUCMessageBoard")) from the ucA for the usercontrol to display a "Transaction complete" message.
I'm thinking you're going to have to do something a little hacky, by using ViewState. If I understand correctly, you are trying to get access to a TextBox's Text on the Web Form, from a UserControl nested within a PopupControl (so you can't traverse all the way up to Web Form Level).
So, what I'd do at some point in the process is store the text in a ViewState variable that you can access from the User Control. It's not optimal, but since you're already hacking to get it to work, what's a little more hacking?
You should expose all controls from ucA as properties, then look for the control inside the DevxPopup the same way you doing. Given that all the controls that you need at the ucA has properties to access them, you could do all the logic you need!
Example:
public ucA : UserControl
{
public string myTextBoxText
{
get
{
return ((TextBox)Controls.FindControl("myTextBox")).Text;
}
}
/*And lot of controls*/
}
Then you looking for the popup at the Form
var ucA = (UcA)Form.Controls.FindControl("myPopup").Controls.FindControl("myucA");
ucA.myTextBoxText = /*Do stuff here with the text*/
Hopes this help you!

tabbed document interface in WPF using only on-board means?

I've seen two threads here about TDI & C#. Both of them didn't really answer the questions I have ...
Since TDIs are pretty much like a standard nowadays, I can hardly imagine, that I have to buy a special control (like AvalonDock or SandDock).
This must be possible with built in the tab-control(?) somehow! I don't need special features like dock- and draggable tabitems. Just open every form in a new tab. Thats it.
Like putting every forms content controls into user controls and by request (button, menu click ...) add a new tab and put the corresponding user control on it ... something like this.
How would you do it? This can't be THAT complicated (even for me) or am I missing something?!
thanks a lot!
Maybe Josh Smith's article on MVVM can give you an idea how to design such user interface. Example being built there is kinda tabbed document interface so you can use it as a starting block.
It's not that hard. It seems hard because there are a lot of different ways to do it.
Try this:
<TabControl x:Name="documentArea"/>
Handler for AddForm button:
private void AddFormClick(object sender, RoutedEventArgs e)
{
object form = GetNewForm();
documentArea.Items.Add(form);
}
That's it. You have to implement GetNewForm() in one of two ways. Have it return a user control that displays the form.
OR better yet, have it return your document that you want to display. Use a DataTemplate to select the controls to use for displaying this document. This method is going to be more complex to set up.

Categories

Resources