How to capture "#" and "#" key pressed - Silverlight Textbox Keyup Event - silverlight-4.0

I wrote below code for capturing "#" and "#" pressed or not. And working perfectly fine on Emulator and Samsung Focus. But when deploy to Nokia Lumia 800 and pressed "#" it wont resulted in Key.D2 and below code not working.
if (e.Key == System.Windows.Input.Key.D2)
{
myAutocompleteBox.Text = "#";
updateAutocompleteBox = true;
}
else if (e.Key == System.Windows.Input.Key.D3)
{
myAutocompleteBox.Text = "#";
updateAutocompleteBox = true;
}
else if (e.Key == System.Windows.Input.Key.Back)
{
if (myAutocompleteBox.Text != String.Empty && updateAutocompleteBox == true)
{
string autoCompleteText = myAutocompleteBox.Text;
myAutocompleteBox.Text = autoCompleteText.Substring(0, autoCompleteText.Length - 1);
}
}
Please guide me how can i capture "#" and "#" key pressed on my textbox. Thanks in Advance.

I think the value of D2 or D3 depends on the keyboard layout in use. In the EN-US Layout SHIFT+2 is # in DE-DE SHIFT+2 is doublequotes and D0 - D9 are variable based on the layout used. In your code you might have to take that into account when translating the key pressed to the String value.

Have a look at this.
It's got all the Key Enumeration for Windows Phone 7, had a look but couldn't spot # or #.
What value is being returned for e.Key?

Related

Photoshop action for changing text number and saving with variable

I have a lot of graphic buttons that I need to make. I have 2 layers
TEXT (This is going to be numbers 1-48 for instance)
White Button image
I'm not sure how to go about writing this action or if I need a script. I need to have the text layer start at 1 and follow this progression.
save file w1.png (this yields a png with a button labeled with a "1"
change text to 2
save file w2.png (this yields a png with a button labeled with a "2"
change text to 3
. . . .
ect. . .all the way to 48. So this would make 48 images automatically. Can this be done with "actions" or do I need to learn scripting?
Save
You'll need a script for this, but it's going to be a rather simple one
function main() {
//this just checks if you have a text layer selected
try {
var textLayer = activeDocument.activeLayer.textItem
} catch (e) {
alert("active layer isn't a text layer");
return
};
var loops = 48,
pngSaveOptions = new PNGSaveOptions(),
outputFolder = Folder.selectDialog('', Folder.desktop); //this will ask for an output folder
for (var i = 0; i < loops; i++) {
var myNum = i + 1;
textLayer.contents = myNum; //this will change layer contents to number only. if you need some text here, write it in quotes like textLayer.contents = "my text" + myNum;
activeDocument.saveAs(new File(outputFolder + "/w" + myNum + ".png"), pngSaveOptions, true, Extension.LOWERCASE);
}
}
app.activeDocument.suspendHistory("temp", "main()");

How To Validate a Devexpress Textbox inside an Devexpress Gridview in Javasacript

i am not able to figure out why the focusout validation that uses the assigned regex is not working in the devex textbox. when i am using the textbox out of the grid it starts working as required. Kindly suggest the solution.
#Html.DevExpress().GridView(settings =>
{
settings.Columns.Add(column =>
{
column.FieldName = "InYear";
column.Caption = "In Year";
column.Width = 100;
column.ColumnType = MVCxGridViewColumnType.TextBox;
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending; // Default
column.SortIndex = 1;
column.CellStyle.HorizontalAlign = HorizontalAlign.Left;
var txtProperties = column.PropertiesEdit as TextBoxProperties;
txtProperties.Width = Unit.Percentage(100);
txtProperties.MaxLength = 4;
txtProperties.DisplayFormatInEditMode = true;
txtProperties.ValidationSettings.RequiredField.IsRequired = true;
txtProperties.ValidationSettings.ValidateOnLeave = true;
txtProperties.ValidationSettings.RegularExpression.ValidationExpression = #"\d{4}";
txtProperties.ValidationSettings.RegularExpression.ErrorText = "Expected format is: YYYY";
txtProperties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, e, '{0}', {1}); }}", "InYear", "0");
column.SetDataItemTemplateContent(c =>
{
if (!(bool)DataBinder.Eval(c.DataItem, "ReadOnly"))
{
Html.DevExpress().TextBox(txtSettings =>
{
txtSettings.Name = "txtInYear_" + c.KeyValue.ToString();
txtSettings.Width = Unit.Percentage(100);
txtSettings.Properties.MaxLength = 4;
txtSettings.Properties.DisplayFormatInEditMode = true;
txtSettings.Properties.ValidationSettings.ValidateOnLeave = true;
txtSettings.Properties.ValidationSettings.ValidationGroup = c.KeyValue.ToString();
txtSettings.Properties.ValidationSettings.RegularExpression.ValidationExpression = #"[0-9]{4}";
txtSettings.Properties.ValidationSettings.RegularExpression.ErrorText = "Expected format is: YYYY";
txtSettings.Properties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, e, '{0}', {1}); }}", c.Column.FieldName, c.KeyValue);
}).Bind(DataBinder.Eval(c.DataItem, c.Column.FieldName)).Render();
}
else
Html.DevExpress().Label(lblSettings =>
{
lblSettings.Name = "lblInYear_" + c.KeyValue.ToString();
lblSettings.Width = Unit.Percentage(100);
}).Bind(DataBinder.Eval(c.DataItem, c.Column.FieldName).ToString()).Render();
});
});
}).Bind(Model).GetHtml()
EDIT : I am using a button out of the gridview to trigger the update command. How can i trigger only validate event of the EditRow. Please view attached image.
Thanks in advance
When do you need to validate the TextBox? In browser mode or when editing? Currently your TextBox is required when you edit a row. Try to set the IsRequired property for your TextBox in the template as well.
txtSettings.Properties.ValidationSettings.RequiredField.IsRequired = true;
It should work.
Go through this thread - MVC GridView - Client validation in default EditForm.
In case if you are working with ajax form then i suggest you use
built-in validation instead:GridView - How to use Microsoft
validation with an AJAX form to validate the Model properties on the
client side.
More References:
GridView - How to enable the client-side validation in the Edit Form
How to correctly enable Model, Unobtrusive or jQuery Client validation
Client Validation in MVC3 with Gridview Template Form
After a long struggle i got the following answer :
Assign a validation group property to the nested controls as below
txtSettings.Properties.ValidationSettings.ValidationGroup = c.KeyValue.ToString();
Iterate through the keyvalues on client side and call the devexpress validate function ASPxClientEdit.ValidateEditorsInContainer as following, i represent validation group name
var isValid =!ASPxClientEdit.ValidateEditorsInContainer(GridName.GetMainElement(), i)
My approach might not be the best but it helped me a lot, i think this would also be helpful for others having the same issue.
Thanks.....

Kindle Silk browser having issues with keypress event?

I'm trying to restrict a text box to numeric entry only in a project using knockout.js and MVC.
I'm doing a data-bind on the keypress event to call a function from the VM that looks like this:
this.NumbersOnly = function (data,evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode != 46 && (charCode < 48 || charCode > 57)))
return false;
return true;
}
This will allow only numbers and decimals in to the input text box. This works great in every browser I've tested except that I'm having issues in Kindle's Silk browser, as I can still type alpha characters in. If anyone has any ideas to get Silk to agree, please let me know!

Adobe 9 Check box required field

I've created reports in Adboe that have checkobxes and set then to required fields.
But when i click the submit button all fields but the check boxes are validated.
I.e
If i dont complete the required textbox field the report will not submit, but when i do and the required checkbox fields are not checked it still submits.
This only appears to be happening on Adobe 9
Any ideas?
Thanks
Sp
Here is a link to a test page
http://www.mediafire.com/?mnkmmlime2f
If you fill the text box with anything it will submit regardless of the check box status (which is also a required field)
I have figured it out.
Adobe Reader checkbox allows has a value (default "false") so when the form validates it sees the checkbox as having a value.
I've had to write some java to stop the form submitting if the checkbox has a null/False/false value
This works like a dream
Thanks for trying to help wit hthis post all
var f;
var Valid = "1";
for (var i = 0; i < this.numFields; i++)
{
f = this.getField(this.getNthFieldName(i));
if (f.type == 'checkbox')
{
if(f.required == true)
{
if(f.value == "false" || f.value == "False" || f.value == "null")
{
Valid = "0";
}
}
}
};
if(Valid == "1")
{
this.submitForm('');
}
else
{
app.alert("Please complete all required fields");
}

Opening an MS-Cash Drawer, Wrong Code? Bad Code?

Humbling expierence here and I think this one will make a fool of me, but...I'm trying to convert an ancient cash register program to .net. Conquered everything else, but I can't pop open the cash register. Its connected to COM1, you are supposed to send a "trigger" text down COM1 that will cause the register to open.
Here is the .net code.
MsgBox("Opening Drawer")
Dim port As System.IO.Ports.SerialPort
port = New System.IO.Ports.SerialPort("Com1")
port.PortName = "COM1"
port.BaudRate = 9600
port.Parity = IO.Ports.Parity.None
port.DataBits = 8
port.StopBits = IO.Ports.StopBits.One
'port.Handshake = IO.Ports.Handshake.RequestToSend
port.RtsEnable = True
'port.DtrEnable = True
port.Open()
If port.IsOpen Then
'MsgBox("Attempt 1")
port.Write("####################")
MsgBox("Signal Sent: " & Chr(65))
Else
MsgBox("Port is not open")
End If
port.Close()
MsgBox("Pop, durn it!")
I get msgboxes "Signal Sent", "Done Pop Drawer"
Dang thing, just won't pop. It's an MS-Cash Drawer (EP125KC). Definitely connected to COM1, definitely has power. Chr(65) is the old code used to pop drawer and it works:
Open drawerComPort For Output Access Write As #1
Print #1, Chr$(65); "A";
Close #1
NOTE: The above code worked successfully. The root problem was caused by a reveresed power cord (negative was on the wrong side).
Thanks for all the help guys!
You've set your handshake to None but the cash drawer probably has its own idea. Also set DtrEnable to True. Chr(65) is the ASCII code for an "A", your VB code suggests the real command is "AA".
The manual documents that the cash drawer auto-tunes its baudrate. It recommends sending at least 20 # characters. And that the real command is Ctrl+G (Chr(7)). The "AA" command might have worked previously due to a baudrate mismatch. Perhaps.
If I remember my very rusty BASIC.
Print #1, Chr$(65); "A";
means print to port1 the character 65 followed by the string "A", Now the character 65 is 'A', so this looks to me like you should be sending "AA" to port1
port.Write("AA");
or alternately,
port.Write(new byte[]{65,'A'}, 0, 2);
It might be sending Unicode 65, which would be 0065, which would not end well.
Just a thought, can you try sending a raw int?
I dont use .net, but is the port buffered? do you need to send a flush/fflush()?
Are you sure you're supposed to send out this code? I would have always thought that the code is prefixed by ESC i.e. 0x1b hexadecimal...for cash drawers...
"\x1bA"
Interesting that double 'A' is used...oh well... :)
Edit: After thinking about this I realized there is another way of doing it, read on...
I have modified your original BASIC code with a bit of bullet-proofing...save it to opendrawer.bas
Sub OpenDrawer()
drawerComPort = "COM1"
Open drawerComPort For Output Access Write As #1
REM ADDED ERROR HANDLING
ON ERROR GOTO ErrHandler
Print #1, Chr$(65); "A";
Close #1
print "Drawer Ok"
OpenDrawer_Exit:
On Error Goto 0
Exit Sub
ErrHandler:
print "Oops, Write Failed"
Goto OpenDrawer_Exit
End Sub
REM The Main....
OpenDrawer
Download the old QB4.5 MS-Quick Basic compiler, and compile that to an executable, into opendrawer.exe, the QB4.5 can be found here. Now, the onus is on you to make this bulletproof, i.e. what happens if writing to COM1 fails, issue a message like in the example BASIC code I modified
Then you can use the System.Diagnostics.Process to shell out using a hidden window
public class TestDrawer
{
private StringBuilder sbRedirectedOutput = new StringBuilder();
public string OutputData
{
get { return this.sbRedirectedOutput.ToString(); }
}
public void Run()
{
System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo();
ps.FileName = "opendrawer";
ps.ErrorDialog = false;
ps.CreateNoWindow = true;
ps.UseShellExecute = false;
ps.RedirectStandardOutput = true;
ps.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
{
proc.StartInfo = ps;
proc.Exited += new EventHandler(proc_Exited);
proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(proc_OutputDataReceived);
proc.Start();
proc.WaitForExit();
proc.BeginOutputReadLine();
while (!proc.HasExited) ;
}
}
void proc_Exited(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("proc_Exited: Process Ended");
if (this.sbRedirectedOutput.ToString().IndexOf("Oops, write failed") > -1){
MessageBox.Show(this, "Error in opening Cash Drawer");
}
if (this.sbRedirectedOutput.ToString().IndexOf("Drawer Ok") > -1){
MessageBox.Show(this, "Drawer Ok");
}
}
void proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
if (e.Data != null) this.sbRedirectedOutput.Append(e.Data + Environment.NewLine);
//System.Diagnostics.Debug.WriteLine("proc_OutputDataReceived: Data: " + e.Data);
}
The process shells out to a hidden window and all output is redirected and handled in the event handler...that should do the trick. Notice, how the redirected output goes into the sbRedirectedOutput (a StringBuilder instance). In the proc_ProcExited event handler, it checks the sbRedirectedOutput for the message 'Oops Write failed' which would be issued from the QB4.5 program.
Be aware, that you may need to include the QB4.5's run-time library in the same directory...not 100% sure...it's being years...
What do you think?
Hope this helps,
Best regards,
Tom.