Vb.net mouse double click event for button [duplicate] - vb.net

Rather than making an event occur when a button is clicked once, I would like the event to occur only when the button is double-clicked. Sadly the double-click event doesn't appear in the list of Events in the IDE.
Anyone know a good solution to this problem? Thank you!

No the standard button does not react to double clicks. See the documentation for the Button.DoubleClick event. It doesn't react to double clicks because in Windows buttons always react to clicks and never to double clicks.
Do you hate your users? Because you'll be creating a button that acts differently than any other button in the system and some users will never figure that out.
That said you have to create a separate control derived from Button to event to this (because SetStyle is a protected method)
public class DoubleClickButton : Button
{
public DoubleClickButton()
{
SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, true);
}
}
Then you'll have to add the DoubleClick event hanlder manually in your code since it still won't show up in the IDE:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
doubleClickButton1.DoubleClick += new EventHandler(doubleClickButton1_DoubleClick);
}
void doubleClickButton1_DoubleClick(object sender, EventArgs e) {
}
}

Use this. Code works.
public class DoubleClickButton : Button
{
public DoubleClickButton()
{
SetStyle(ControlStyles.StandardClick |
ControlStyles.StandardDoubleClick, true);
}
}
DoubleClickButton button = new DoubleClickButton();
button.DoubleClick += delegate (object sender, EventArgs e)
{
//codes
};

i used to add MouseDoubleClick event on my object like:
this.pictureBox.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseDoubleClick);

A double click is simply two regular click events within a time t of each other.
Here is some pseudo code for that assuming t = 0.5 seconds
button.on('click' , function(event) {
if (timer is off or more than 0.5 milliseconds)
restart timer
if (timer is between 0 and 0.5 milliseconds)
execute double click handler
})

Related

Libgdx Dialog buttons cannot be clicked

I have trouble properly implementing a dialog. It does not recognize button clicks - even the button down animation does not happen. However, it does recognize key presses (e.g. enter or esc in my case). Dialog does appear to be on top of the stage objects, so I'm confused why it isn't registering my clicks.
I have an InputMultiplexer with processors InputHandler class (implements InputProcessor) and stage, in that order:
InputMultiplexer im = new InputMultiplexer();
im.addProcessor(new InputHandler(stage));
im.addProcessor(stage);//trying to make dialog work by doing this
Gdx.input.setInputProcessor(im);
Here's my showDialog method defined in stage:
public void showDialog() {
Dialog dialog = new Dialog("Quit?", skin) {
#Override
protected void result(Object object) {
boolean exit = (Boolean) object;
if (exit) {
Gdx.app.exit();
} else {
remove();
}
}
};
dialog.button("Yes", true);
dialog.button("No", false);
dialog.key(Input.Keys.ENTER, true);
dialog.key(Input.Keys.ESCAPE, false);
dialog.show(this);
}
The showDialog() method is called from InputHandler when it recognizes that the game is over (I have it set so that the game state is checked and updated on touch up, since it's a touch based game). My understanding is that since the multiplexer receives false return from the InputHandler methods when the game is over, it then goes to the stage for input, which seems to be working only when I use key presses on the dialog, i.e. enter quits the game, esc removes the dialog, but clicking the buttons do nothing.
Here is my Screen's render function in case it's relevant:
#Override
public void render(float delta) {
Gdx.gl.glClearColor(1,1,1,1);
Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND);
Gdx.graphics.getGL20().glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling?GL20.GL_COVERAGE_BUFFER_BIT_NV:0));
stage.act();
stage.getCamera().update();
stage.draw();
}

Modeless dialog created by modal dialog in Compact Framework

I am working on a Compact Framework application. This particular hardware implementation has a touchscreen, but its Soft Input Panel has buttons that are simply too small to be useful. There are more than one form where typed input is required, so I created a form with buttons laid out like a keypad. The forms that use this "keypad" form are modal dialogs. When a dialog requiring this "keypad" loads, I load the "keypad" form as modeless:
private void CardInputForm_Load(object sender, EventArgs e)
{
...
keypadForm = new KeypadForm();
keypadForm.Owner = this;
keypadForm.SetCallback(keyHandler);
keypadForm.Show();
}
The SetCallback method tells the "keypad" form where to send the keystrokes (as a Delegate).
The problem I'm having is that the modeless "keypad" form does not take input. It is displayed as I expect, but I get a beep when I press any of its buttons, and its caption is grayed-out. It seems like the modal dialog is blocking it.
I've read other posts on this forum that says modal dialogs can create & use modeless dialogs. Can anyone shed light on this situation? Is there a problem with my implementation?
I found the answer: Set the keypad form's Parent property, not its Owner property, to the form instance wanting the keystrokes. The keypad dialog's title bar stays grayed out, but the form is active.
private void CardInputForm_Load(object sender, EventArgs e)
{
// (do other work)
keypadForm = new KeypadForm();
keypadForm.Parent = this;
keypadForm.Top = 190; // set as appropriate
keypadForm.Show();
}
Be sure to clean up when done with the parent form. This can be in the parent's Closing or Closed events.
private void CardInputForm_Closing(object sender, CancelEventArgs e)
{
// (do other work)
keypadForm.Close();
keypadForm.Dispose();
}
There are two panels on the keypad form, one with numerals and one with letters and punctuation that I want. There is also an area not on a panel that is common to both, containing buttons for clear, backspace, enter/OK, and cancel. Each panel has a button to hide itself and unhide its counterpart ('ABC', '123', for example). I have all the buttons for input on the keypadForm fire a common event. All it does is send the button instance to the parent. The parent is responsible for determining what action or keystroke is desired. In my case I named the buttons "btnA", "btnB", "btn0", "btn1", "btnCancel", etc. For keystrokes, the parent form takes the last character of the name to determine what key is desired. This is a bit messy but it works. Any form wishing to use the keypad form inherits from a base class, defining a method for callback.
public partial class TimeClockBase : Form
{
public TimeClockBase()
{
InitializeComponent();
}
// (other implementation-specific base class functionality)
public virtual void KeyCallback(Button button)
{
}
}
The click event on the keypad form looks like this.
private void btnKey_Click(object sender, EventArgs e)
{
// play click sound if supported
(Parent as TimeClockBase).KeyCallback(sender as Button);
}
The method in the parent form looks like this.
public override void KeyCallback(Button button)
{
switch (button.Name)
{
case "btnCancel":
// setting result will cause form to close
DialogResult = DialogResult.Cancel;
break;
case "btnClear":
txtCardID.Text = string.Empty;
break;
// (handle other cases)
}
}

How to add clickhandler to the subrow of the celltablebuilder

I am able to build custom rows with celltablebuilder. When clicking on a particular anchor cell, I am able to build additional subrows for that row. This subrow has buttons, when clicking on the button I have do some action. I am able to add buttons with clickhandler in the subrow, but when clicking on the button nothing is happening clickhandler is not firing.
Can anybody please help.
protected void buildRowImpl(GridDTO rowValue, int absRowIndex ) {
buildRows(rowValue, absRowIndex, true);
if (showingFriends.contains(rowValue.getComponentId())) {
buildAdditonalRows( absRowIndex, gridDTO);
}
}
private void buildAdditonalRows(int index, GridDTO rowValue, ){
TableRowBuilder row = startRow();
td = row.startTD();
if(rowValue.getXpath() != null){
//td.text(rowValue.getXpath());
renderCell(td, createContext(1), cellTable.getColumn(1), rowValue);
}else{
td.text("");
}
td.endTD();
td = row.startTD();
Button button = new Button ();
button.setText("Save");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("ssss");
}
});
DivBuilder div = td.startDiv();
div.html(new afeHtmlBuilder().appendHtmlConstant(button.toString()).toSafeHtml());
div.end();
td.endTD();
row.endTR();
}
CellPreviewEvent provides subindex. You can use it to get subrow value.
Example usage :
dataGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<TreeItem>() {
#Override
public void onCellPreview(final CellPreviewEvent<TreeItem> event) {
if(event.getNativeEvent().getType().equals(BrowserEvents.CLICK)){
if(event.getContext().getSubIndex()>0){
event.getValue().getChild(event.getContext().getSubIndex()-1);
}
}
}
});
Or you can provide custom CellPreviewEvent.Handler implementation with selectionMode. For more details you can look at AbstractHasData
I had a similar situation where i needed a widget inside a cell to listen for click events... What i found out is that the widget doesn't respond to events once you inserted it into a cell (In other words, only the actual HTML that makes up for the widget gets put into the cell, any kind of event handling isn't included). The work around is to add the events to the Cell (You can make a custom cell class for that particular cell-widget and override OnBrowserEvent to listen for events.)
See GWT: On adding custom widget to celltable losing events of the custom widgets for a more eloquent explanation and example code.

Forcing Default button on a gridview

I'm using gridview with templates to show and edit some information from a sql database.
When I edit and change the data in that row and then click enter it automatically presses the highest on page button which uses submit to server set to true which means it'll try to delete instead of update.
I've have tried setting a panel round the gridview and setting the panel's default button to the "updatebutton" but it won't allow that because it can't 'see' the buttons.
I had a similar problem and I found a very simple workaround:
Place a button below the GridView and make it invisible by CSS (i.e. position: relative; left: -2000px)
Create a Panel around the GridView and give it as DefaultButton the ID of the button we just created.
Write the following line of code for the click-event of the button:
myGridView.UpdateRow(myGridView.EditIndex, false);
Whenever you press enter in the GridView now, the edited row will be confirmed.
You need to precess KeyDown or KeyPress event of the grid, and check if pressed key if Keys.Enter :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1_Click(this, EventArgs.Empty);
}
}
private void button1_Click(object sender, EventArgs e)
{
// Your logic here
}
}

SCSF: display view from another view against button click

i am facing one problem in SCSF.
I have two workspaces
MdiWorkspace
DeckWorkspace
i have two views in a module
Viewer (display in mdiworkspace)
Property Viewer (in deckworkspace)
in Viewer i have a button in toolbar whose purpose is to display PropertyViewer (another View).
how can i display this PropertyViewer in deckworkspace agaist button click event.
NOTE: i am not using Command[CommandName].AddInvoker(control, "click:) and CommandHandler
I'm going to assume your toolbar sits in a SmartPart that implements the MVP pattern. Have the button click event handler in the SmartPart fire an event that its presenter will handle. Your presenter code would look like this:
// Presenter code
protected override void OnViewSet()
{
this.View.ToolbarButtonClick += View_ToolbarButtonClick;
}
public void View_ToolbarButtonClick(object sender, EventArgs e)
{
// remove the handler so the property viewer
// will only be added the first time
this.View.OnToolbarButtonClick -= View_ToolbarButtonClick;
var propertyView = new PropertyViewer();
this.WorkItem.Workspaces[WorkspaceNames.MyDeckWorkspace].Show(propertyView);
}