vb net: How to handle a Gecko.DOM.GeckoInputElement click event - vb.net

Is there a way to handle Gecko.DOM.GeckoInputElement click event?
I have a submit button in a tag and I'd like to rise an event when I click it with the mouse. The website is open in a Gecko Browser.
I'm useing xulrunner-29.0b2.en-US.win32 and GeckoFx-Windows-29.0-0.1
My code is:
Friend WithEvents inputElement As Gecko.DOM.GeckoInputElement
Private Sub inputElement_click() Handles inputElement.Click
MsgBox("a")
End Sub
but obviously "inputElement.Click" doesn't exists.

The easiest way to do this is to add a DomClick Handler to the main control.
C#
browser.DomClick += click;
Then inside the handler look for your button and responded appropriately.
C#
click( object sender, DomEventArgs e )
{
if ( sender == null ) return;
if ( e == null ) return;
if ( e.Target == null ) return;
var element = e.Target.CastToGeckoElement();
GeckoHtmlElement clicked = element as GeckoHtmlElement;
if ( clicked == null ) return;
if ( clicked.TagName.ToLowerInvariant() == "input" && clicked.GetAttribute("type").ToLowerInvariant() == "submit" )
{
e.Handled = true;
MessageBox.Show("a");
}

Related

How to make a ToolStripMenuItem hold a variable value to be recalled later?

I have a form that has a MenuStrip at the top. I only have one ToolStripMenuItem called Dates. I have written code that executes when an "Add" button is clicked which adds a new menu item underneath "Dates". This menu item is named by concatenating some variables which store user input. Here is everything I have for the "Add" button click event. It all works, but I want display the same info that gets displayed in the label when the click event happens to be saved to the submenu item too. So I want to be able to click that sub-menu item that is created and be able to see what input was saved to it when the Add button is clicked.
private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e)
{
//add the input to the variables
String^ month = txtMonth->Text;
String^ day = txtDay->Text;
String^ year = txtYear->Text;
double tips = Double::Parse(txtTips->Text);
//make sure the date input is correct
if (txtMonth->Text == "" || txtDay->Text == "" || txtYear->Text == "" || Double::Parse(month) < 1 || Double::Parse(month) > 12
|| Double::Parse(day) < 1 || Double::Parse(day) > 31 /*|| Double::Parse(year)!=*/)
{
//show message box
MessageBox::Show("Please enter the date in the correct format.", "Error", MessageBoxButtons::OK,
MessageBoxIcon::Error);
//clear the boxes
txtMonth->Clear();
txtDay->Clear();
txtYear->Clear();
}
else
{
//for the menu bar
String^ date = month + "/" + day + "/" + year;
datesToolStripMenuItem->DropDownItems->Add(date)->Equals(date);
//print to label
lblPrint->Text = month + "/" + day + "/" + year + " - " + tips.ToString("c");
//clear the boxes
txtMonth->Clear();
txtDay->Clear();
txtYear->Clear();
txtTips->Clear();
}
}
FYI. I haven't written any code to do what I want to do. I just have no idea where to start for that, so I've shared what I have before that.

Distinguish between clicks on two wxWidgets Property Grid buttons

I can write
wxPropertyGrid * pg;
...
wxStringProperty * pA = new wxStringProperty("A",
wxPG_LABEL,"");
wxStringProperty * pB = new wxStringProperty("B",
wxPG_LABEL,"");
pg->Append( pA );
pg->Append( pB );
pg->SetPropertyEditor( pA, wxPGEditor_TextCtrlAndButton );
pg->SetPropertyEditor( pB, wxPGEditor_TextCtrlAndButton );
Bind( wxEVT_COMMAND_BUTTON_CLICKED,
&cFrame::OnPropertyButton, this );
...
void cFrame::OnPropertyButton( wxCommandEvent& event )
{
wxMessageBox(wxString::Format("button %d", event.GetId()));
}
and it works, quite well - the button message pops up when I click on the button in either property A or B
But, how do I distinguish, in the event handler, between clicks on A and B.
Normally, I would get the button id from the event, but these buttons do not appear to have IDs - the message shows the same ID for both.
I found that I can grab the label from the currently active property, and so use that to make the distinction
void cFrame::OnPropertyButton( wxCommandEvent& event )
{
wxMessageBox(wxString::Format("button %s",
pg->GetSelection()->GetLabel()));
}

Set the cursor of a readonly RichtTextBox

The following code avoids the Richtextbox of being focused. So the user can not edit the text or select it. To avoid the Cursor of changing to IBeam I also also catch the SETCURSOR message. But the Problem is, the richtextbox also contains links and I want the cursor to change to Hand, if I move the mouse over a link. So I have to distinguish between IBeam and Hand. For this I could not find a solution, altough I think this can not be so difficult.
Const WM_SETFOCUS = &H0007
Const WM_KILLFOCUS = &H0008
Const WM_SETCURSOR = &H0020
Const WM_NULL = &H0000
Protected Overrides Sub WndProc(ByRef _M As Message)
Select Case _M.Msg
Case WM_SETFOCUS, WM_KILLFOCUS
_M.Msg = WM_NULL
Case WM_SETCURSOR
'Here I need your help: How can I check the cursor?
'If Cursor is IBeam Then
' _M.Msg = WM_NULL
'End If
End Select
MyBase.WndProc(_M)
End Sub
This is for C# but you should be able to convert it:
protected override void OnMouseMove(MouseEventArgs e)
{
if (SelectionLength > 0)
{
int position = GetCharIndexFromPosition(e.Location);
if (position > SelectionStart && position < SelectionStart+SelectionLength)
this.Cursor = Cursors.Arrow;
else
this.Cursor = Cursors.IBeam;
}
base.OnMouseMove(e);
}

ManipulationDelta on pivot item only fires once

I am trying to animate an image based on the select pivoted items position.
I am currently using the ManipulationDelta event to try and see which direction the user is swiping so that I can fade out or fade in an animated image based on the position of the pivot item.
My problem is with the ManipulationDelta event, this event is only ever called once on a pivot item, regardless of how much manipulation of the pivot control is occurring.
Does anyone know a way to make it so the pivot items ManpulationDelta event is constantly called when it is being manipulated?
Probably your Pivot is intercepting further events. You may try to do such a thing - disable Pivot (then your Manipulations should work) and change PivotItems manually for example using TouchPanel and Touch.FrameReported. Sample code:
public MainPage()
{
InitializeComponent();
myPivot.IsHitTestVisible = false; // disable your Pivot
Touch.FrameReported += Touch_FrameReported;
TouchPanel.EnabledGestures = GestureType.HorizontalDrag;
}
TouchPoint first;
private const int detectRightGesture = 20;
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint mainTouch = e.GetPrimaryTouchPoint(this);
if (mainTouch.Action == TouchAction.Down)
first = mainTouch;
else if (mainTouch.Action == TouchAction.Up && TouchPanel.IsGestureAvailable)
{
if (mainTouch.Position.X - first.Position.X < -detectRightGesture)
{
if (myPivot.SelectedIndex < myPivot.Items.Count - 1) myPivot.SelectedIndex++;
else myPivot.SelectedIndex = 0;
}
else if (mainTouch.Position.X - first.Position.X > detectRightGesture)
{
if (myPivot.SelectedIndex > 0) myPivot.SelectedIndex--;
else myPivot.SelectedIndex = myPivot.Items.Count - 1;
}
}
}

How to render a GWT widget with a clickhandler GWT with a custom table builder?

I'm trying to use a GWT 2.5rc1 custom tablebuilder to render a subtable for each row in my datagrid. I've followed the example in the 2.5 rc1 showcase (url: http://showcase2.jlabanca-testing.appspot.com/#!CwCustomDataGrid).
I'm able to see the newly added sub-rows, but the problem comes when I want to add a clickhandler to a subrow anchor element.. the clickhandler is never invoked, which it seems also quite clear to me since I'm not "registering" the event handler anywhere.
Here the code I'm using now, "relevant part":
private void buildRegRow(Registrazione rowValue,final int absRowIndex, boolean isCommentRow) {
// Calculate the row styles.
SelectionModel<? super Registrazione> selectionModel = cellTable.getSelectionModel();
boolean isSelected =
(selectionModel == null || rowValue == null) ? false : selectionModel
.isSelected(rowValue);
boolean isEven = absRowIndex % 2 == 0;
StringBuilder trClasses = new StringBuilder(rowStyle);
if (isSelected) {
trClasses.append(selectedRowStyle);
}
// Calculate the cell styles.
String cellStyles = cellStyle;
if (isSelected) {
cellStyles += selectedCellStyle;
}
if(isCommentRow)
cellStyles += childCell;
TableRowBuilder row = startRow();
row.className(trClasses.toString());
/*
* Checkbox column.
*
* This table will uses a checkbox column for selection. Alternatively,
* you can call dataGrid.setSelectionEnabled(true) to enable mouse
* selection.
*/
TableCellBuilder td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if (!isCommentRow) {
renderCell(td, createContext(0), cellTable.getColumn(0), rowValue);
}
td.endTD();
/*
* View children column.
*
* Displays a link to "show children". When clicked, the list of friends is
* displayed below the contact.
*/
td = row.startTD();
td.className(cellStyles);
if(!isCommentRow) {
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if(rowValue.hasComments())
//td.className(CellTableResource.INSTANCE.dataGridStyle().showChildren());
renderCell(td, createContext(1), cellTable.getColumn(1), rowValue);
} else {
td.colSpan(getColumns().size() - 1);
// // Draw sub-table header
TableBuilder subTable = td.startTable();
TableSectionBuilder subTableSection = subTable.startTHead();
TableRowBuilder tr2 = subTableSection.startTR();
TableCellBuilder td2 = tr2.startTH();
td2.text(msgs.date());
tr2.endTH();
td2 = tr2.startTH();
td2.text(msgs.username());
tr2.endTH();
td2 = tr2.startTH();
td2.text(msgs.comment());
tr2.endTH();
td2 = tr2.startTH();
td2.text(msgs.actions());
tr2.endTH();
subTableSection.endTR();
subTable.endTHead();
subTableSection = subTable.startTBody();
for(final EntityComment ec : rowValue.getCommentList()) {
tr2 = subTableSection.startTR();
// Date
td2 = tr2.startTD();
td2.text(DateUtil.getDefaultDateTimeFormat().format(ec.getCreationDate()));
tr2.endTD();
// Username
td2 = tr2.startTD();
td2.text(ec.getUsername());
tr2.endTD();
// Text
td2 = tr2.startTD();
td2.text(ec.getText());
tr2.endTD();
// Actions
td2 = tr2.startTD();
// Remove
Anchor removeAnchor = new Anchor("remove");
removeAnchor.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("clicked");
}
});
td2.html(new SafeHtmlBuilder().appendHtmlConstant(removeAnchor.toString()).toSafeHtml());
tr2.endTD();
subTableSection.endTR();
}
subTable.endTBody();
td.endTable();
}
td.endTD();
for(int i = 2; i <= 6; i++) {
// Recorded, list name, callcenter, msisdn
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if(!isCommentRow) {
renderCell(td, createContext(i), cellTable.getColumn(i), rowValue);
}
td.endTD();
}
row.endTR();
}
The subtable shows up, with an anchor at the correct position, but the clickhandler is never invoked. I do not know how to write the handler code to the page, like I've done to render the anchor.
Thanks for any help.
I have tried custom tablebuilder and created a grid. You can add any element using the proper structure. Make sure you set the Unique Id to each element you create. Then through code access the element through the following code,
Element e = DOM.getElementById( id );
Cast the element to its proper widget i.e, if you are using text input element you can always cast it to textbox. To cast the element there is one more step which you can google out. Then add the clickhandler or whichever handler you want.