How to bring a form in the top of desktop? - winforms

I want to pop up a form in C# .net 2.0 which should be in front of the desktop (topmost) until the user clicks the close button.
How to do so?
I tried the code from here:
http://dotnet-snippets.de/dns/fenster-wirklich-in-den-vordergrund-des-desktops-bringen-SID1005.aspx
But it didn't work.
My system is Win7.

Set the form's TopMost property to true and MinimizeBox property to false.

Code below will create MessageBox with TopMost property making it on Top until user clicks No or Yes.
DialogResult result = DialogResult.No;
try {
result = MessageBox.Show(new Form {
TopMost = true, MinimizeBox = false,
}, "some text", "some topic", MessageBoxButtons.YesNo, MessageBoxIcon.Stop);
} finally {
if (result == DialogResult.No) {
}
}

Related

How handle click event of remove item button in multiselect combobox vaadin 14

Would like to show confirmation dialog when any of the selected items is removed from multi select combo box. We have this token remove button and its click event I would like to know how we can handle its click event in java ?
There's no Java API for the click listener of the items. However, if you want to add a confirmation step for deselection, you can use a workaround with a selection listener, as the selection event knows the previous selection set and the new selection set:
MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
multiselectComboBox.setLabel("Select items");
multiselectComboBox.setItems("Item 1", "Item 2", "Item 3", "Item 4");
multiselectComboBox.addSelectionListener(event -> {
if (!event.isFromClient()) {
return;
}
Set<String> removedSelection = event.getRemovedSelection();
if (removedSelection.isEmpty()) {
return;
}
String itemsAsString = String.join(",", removedSelection);
ConfirmDialog confirmDialog = new ConfirmDialog();
confirmDialog.setHeader("Are you sure you want to remove " + itemsAsString);
confirmDialog.setConfirmButton("Ok", null);
confirmDialog.setCancelButton("Cancel", e -> {
multiselectComboBox.select(event.getOldSelection());
});
confirmDialog.open();
});
This won't preserve the order of the selection, but that might be doable as well with a little bit of effort.

Why is getValue() always returning false?

I filled a list with a CheckBox. This Checkbox is screnning on the page. Then i will find out, if the Checkbox is checked or not. But this is Always returning false, even when the Checkbox is pressed. But why?
ArrayList<TutorialAnswerCheckbox> cbList = new ArrayList<>();
cbList.add(new TutorialAnswerCheckbox(false, "Zuweisungsoperatoren"));
Here the Checkbox is created.
public TutorialAnswerCheckbox(boolean isCorrectAnswer, String text)
{
this.isCorrectAnswer = isCorrectAnswer;
setText(text);
getElement().getStyle().setColor("black");
getElement().getStyle().setProperty("float", "left");
}
Here im adding the box to my HTMLPanel to a answer div.
html.add(cbList.get(0), "answer9");
This works. Then when the user hits a button i will check if the checkbox is pressed or not.
#UiHandler("abgabe")
void done(ClickEvent e)
{
Window.alert(cbList.get(0).isAnswerCorrectly.toString());
}
public boolean isAnswerCorrectly()
{
return this.getValue();
}
But the window alert is Always false
This Returns also false even when it is checked.
Window.alert(cbList.get(0).isAnswerCorrectly.toString());
you have to set the fireEvents checkbox.setValue(value, fireEvents);

WPF services for YES/NO MessageBox

With reference to What exactly are "WPF services"? and its attachment https://digitaltapestry.wordpress.com/2009/07/21/services-%E2%80%93-your-viewmodel-death-star/ .
Using services in WPF MVVM application, Can i use this type of service in ViewModel even to display MessageBox with Yes No Cancel buttons?
If yes, whitch data type should i return in ViewModel (Boolean Yes=> true No/Cancel => false) (MessageBoxResult)?
Can i use this type of service in ViewModel even to display MessageBox with Yes No Cancel buttons?
Yes.
If yes, whitch data type should i return in ViewModel (Boolean Yes=> true No/Cancel => false) (MessageBoxResult)?
The service should return a bool?, .e.g.:
public class DisplayMessageService : IDisplayMessage
{
public bool? ShowDialog(string message)
{
MessageBoxResult result = MessageBox.Show(message, "title...", MessageBoxButton.YesNoCancel);
switch (result)
{
case MessageBoxResult.Yes:
return true;
case MessageBoxResult.No:
return false;
default:
return null;
}
}
}
If you simply display a MessageBox without any "Yes" or "No" button, you shouldn't return anything from the method.

Popup on popup, the popup below disappears

I am using the following listeners on the showwindowpopup to grey out(opaque) the background so that nothing is seen. But when I try to close this window, a confirmation window has to appear to confirm from user, but when this confirmation window appears the showwindowpopup behind it which is behind it gets greyed out as well and is not seen.
show: function(win) {
if (this.modal) {
var dom = Ext.dom.Query.select('.x-mask');
for(var i=0; i<dom.length;i++){
Ext.get(dom[i]).setStyle('opacity',1);
}
}
},
close: function(win) {
if (this.modal) {
var dom = Ext.dom.Query.select('.x-mask');
for(var i=0; i<dom.length;i++){
Ext.get(dom[i]).setStyle('opacity',0);
}
}
}
Can someone tell me how can I resolve this? I want the background to be greyed out except the showwindowpopup and the confirmation window. I want the showwindowpopup to be seen whene the confirmation window is open.
Can you Constrain the "show window popup" to the parent panel?

How do I get a context menu to work on a Telerik RadGridView column?

I have the following method which adds a new column to a Telerik RadGridView:
private void CreateNewColumn(FieldDescriptor fd, uint fieldno) {
fieldGrid.Columns.Add(new GridViewDataColumn() {
UniqueName = fd.fieldName,
Header = fd.displayName,
DataMemberBinding = new Binding("Fields[" + fieldno + "]"),
ContextMenu = new ContextMenu() {
Tag = fieldno,
Items = {
new MenuItem() {
Header = "Field Properties",
Command = Commands.FieldProperties,
CommandBindings = { new CommandBinding(Commands.FieldProperties, FieldProperties_Execute) }
},
new MenuItem() {
Header = "Delete Field",
Command = Commands.DeleteField,
CommandBindings = { new CommandBinding(Commands.DeleteField, DeleteField_Execute) }
}
}
}
});
}
The problem I'm having is that the context menu never appears when I right click anywhere on the grid. If I bind the context menu directly to the grid, i.e.
fieldGrid.ContextMenu = new ContextMenu() { ...
then the context menu shows up, but I have no way of determining which column the user right-clicked on. Has anyone gotten context menus to work on individual columns or column headers?
I cannot speak for Telerik's grid, but with the Infragistics grid you would attach the context menu to the grid, and then use the mouse location to determine what the user right clicked on in the grid. The Infragistics grid has some decent helper methods to facilitate the hit testing.
You can check my answer on your forum post:
http://www.telerik.com/community/forums/wpf/gridview/column-contextmenu.aspx

Resources