Password Mode of TextBox in F# - winforms

I am developing an windows application in F#. In the application I have to show the TextBox mode in Password Format. What is the code for using the password mode of TextBox in F#?
I have applied the following code:
let txtpwd = new TextBox(Top = 70, Left = 120)
From the above code the textbox is displaying. No problem. I have applied following code for password mode:
txtpwd.PasswordChar
The above code is not working properly.

You should set desired properties upon initialization of your control, for example:
txtpwd.Text <- "" // Set to no text
txtpwd.PasswordChar <-'*' // The password character is an asterisk
txtpwd.MaxLength <- 14 // The control will allow no more than 14 characters

Better yet, set the properties in your call to the constructor. One of the cool things about F# is that you can set properties in the call that you wouldn't normally be able to set in the constructor. Like this:
let txtpwd = new TextBox(Top = 70, Left = 120, Text = "", PasswordChar = '*',MaxLength = 14, Multiline = true)
This is basically equivalent to what Gene posted but, as far as I know, it's a little more idiomatic in F#.
If you check this page under the topic "Assigning Values To Properties At Initialization" (sorry can't post a direct link) although the page is discussing F# code, it holds for other .Net code as well.

Related

Concurrency Error WinForms Binding Source Navigator

I have a form with customer info that needs to be processed one transaction per page. I'm using the binding navigator to manage my pagination.
It works in all but some cases. In the cases where it doesn't work, I have to open a different window to look up information and return it to the main form. Here is the code for that:
// save current work
updateDataTable();
// Open a window and get new customer info
// CurrentCustomer is returned from the opened window
using (SqlConnection cx = new SqlConnection(GetConnectionString()))
{
DataRowView dataRow = (DataRowView)procBindingSource.Current;
dataRow.BeginEdit();
dataRow["CUSTOMER"] = CurrentCustomer;
dataRow.EndEdit();
updateDataItems();
SqlCommand cmd = new SqlCommand(
#" select acct_no from cust_processing where id = #id ", cx);
cmd.Parameters.AddWithValue("#id", (int)dataRow["ID"]);
cx.Open();
var results = cmd.ExecuteScalar();
if (results != null)
{
dataRow.BeginEdit();
dataRow["ACCT_NO"] = results.ToString();
dataRow.EndEdit();
updateDataItems(); <------ CONCURRENCY ERROR
}
}
The error I am getting is a concurrency error. I think that I have more than one version of the row possibly ? I thought I was making sure that I was on the most recent version of the row by calling updateDataTable(). I am the only user so I know I am creating the problem myself.
Here is my update method which is called when I change pages or save and exit or want to write the commit the data:
void updateDataItems()
{
this.procBindingSource.EndEdit();
this.procTableAdapter.Update(xyzDataSet);
xyzDataSet.AcceptChanges();
}
I have tried executing updateDataItems from various places such as after I assign dataRow["ACCT_NO"] = results.ToString() or before and after assigning that.
I'm pretty much down to guess and check so any thoughts, help and advice will be appreciated and +1.
Okay -- so the problem was that I was trying to update the current row from the program and also using the binding navigator. They were not working together properly.
The solution was to add a text box to the form in the forms designer and set visible = false and bind it to ACCT_NO. Once I got the results from my other form, I just needed to set the .text property of the ACCT_NO textbox to the new value and the binding navigator managed all my updates for me correctly.
txtAcct_No.text = results.ToString();

Clicking checkbox on web page using Applescript

I'm somewhat new to Applescript, and I am trying to make Applescript check a checkbox to select it. I want the checkbox to be clicked regardless of whether or not it's already checked. Here is the checkbox's location according to the Accessibility Inspector:
<AXApplication: “Safari”>
<AXWindow: “Studio”>
<AXGroup>
<AXGroup>
<AXGroup>
<AXScrollArea: “”>
<AXWebArea: “”>
<AXGroup: “”>
<AXCheckBox: “”>
Attributes:
AXRole: “AXCheckBox”
AXSubrole: “(null)”
AXRoleDescription: “check box”
AXChildren: “<array of size 0>”
AXHelp: “”
AXParent: “<AXGroup: “”>”
AXPosition: “x=1104 y=825”
AXSize: “w=18 h=19”
AXTitle: “”
AXDescription: “”
AXValue: “0”
AXFocused (W): “0”
AXEnabled: “1”
AXWindow: “<AXWindow: “Studio”>”
AXSelectedTextMarkerRange (W): “<AXTextMarkerRange 0x101937860 [0x7fff76e43fa0]>{startMarker:<AXTextMarker 0x1019378b0 [0x7fff76e43fa0]>{length = 24, bytes = 0xac01000000000000c0366e23010000001700000001000000} endMarker:<AXTextMarker 0x101938030 [0x7fff76e43fa0]>{length = 24, bytes = 0xac01000000000000c0366e23010000001700000001000000}}”
AXStartTextMarker: “<AXTextMarker 0x101938030 [0x7fff76e43fa0]>{length = 24, bytes = 0xa00000000000000098975e0d010000000000000001000000}”
AXEndTextMarker: “<AXTextMarker 0x1019378b0 [0x7fff76e43fa0]>{length = 24, bytes = 0xa200000000000000405e7812010000000000000001000000}”
AXVisited: “0”
AXLinkedUIElements: “(null)”
AXSelected: “0”
AXBlockQuoteLevel: “0”
AXTopLevelUIElement: “<AXWindow: “Studio”>”
AXTitleUIElement: “(null)”
AXAccessKey: “(null)”
AXRequired: “0”
AXInvalid: “false”
AXARIABusy: “0”
Actions:
AXPress - press
AXShowMenu - show menu
I've tried multiple methods to get this to work, and I haven't been able to. Any help is appreciated.
Your question with the Accessibility Inspector info is not very helpful I am afraid.
It would help if we could see the actual elements of the web page,
Have a look at this page which I found that shows check boxes and the code that makes it up.
Each element has a name and maybe within some other element.
on the page I can use this Applescript/Javascript to check the check1 checkbox.
Hopefully this will give you an idea of how to go about it.
But remember this code snippet is tailored to this page.
Open the web page and run this applescript
tell application "Safari"
set doc to document 1
do JavaScript "document.forms['testform']['check1'].checked = true" in doc
end tell
Update: Applescript GUI
Update:2 take into account "clicked regardless of whether or not it's already checked"
Taking a punt with your Accessibility Inspector. Which is a bit useless (not your fault)
try:
activate application "Safari"
tell application "System Events"
set theCheckbox to (checkbox 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1 of application process "Safari")
set isEnabled to value of theCheckbox as boolean
if not isEnabled then
click theCheckbox
end if
end tell

F# WPF events: "Block following this 'let' is unfinished. Expect an expression"

This is driving me nuts. I am looking here at Microsoft's function examples.
I can't see what I am doing wrong.
So, I am trying to use F# with WPF, I found a working online project template for it. Here it is .I was about to get started. Unfortunately, the designer does not work for generating events in the F# code by double clicking an element like it does in C#. But oh well, I can set what the Click does anyway. I decided I would do it all manually.
Here is my flawed attempt:
module MainApp
open System
open System.Windows
open System.Windows.Controls
open FSharpx
let mutable doc = ""
type MainWindow = XAML<"MainWindow.xaml">
let loadWindow() =
let window = MainWindow()
// Your awesome code code here and you have strongly typed access to the XAML via "window"
window.Root
let make (sender:Object, e:RoutedEventArgs) =
doc<- doc +"<?xml version=\"1.0\" standalone=\"no\"?>"
0
[<STAThread>]
(new Application()).Run(loadWindow()) |> ignore
In any event, It does not like the line with let make on it. It gives me this error:
Block following this 'let' is unfinished. Expect an expression
And yet, clearly I read on the MSDN
The compiler uses the final expression in a function body to determine the return value and type
So, it has a return, how is it an unfinished expression?
You are supposed to return window.Root from loadWindow. Right now the last bit of code inside loadWindow is the declaration of a make function, which is not valid. Remember, indentation determines scope in F#.
If you wanted to add a new function make, but leave the body of loadWindow basically empty, you need to align the indentation properly:
let loadWindow() =
let window = MainWindow()
// Your awesome code code here and you have strongly typed access to the XAML via "window"
window.Root
let make (sender:Object, e:RoutedEventArgs) =
doc<- doc +"<?xml version=\"1.0\" standalone=\"no\"?>"
0

Does anyone have a C# example of using an UltraDataSource as the DataSource to a UltraComboEditor please

Does anyone have a C# example of using an UltraDataSource as the DataSource to a UltraComboEditor please.
I can get so far but it doesn't seem to bind.
I have tried a simple project to use an UltraDataSource as datasource for a simple UltraComboEditor. Set the properties of the ComboEditor to
this.ultraComboEditor1.DataMember = "Band 0";
this.ultraComboEditor1.DataSource = this.udsTest; // <- crashed here
this.ultraComboEditor1.DisplayMember = "Description";
this.ultraComboEditor1.Name = "ultraComboEditor1";
this.ultraComboEditor1.ValueMember = "ID";
The sample program crashed with a NullReferenceException inside the InitializeComponent code where I set the UltraDataSource instance.
Then I have removed the setting of the property DataMember (Not just blanked out, but right-click and selected Reset). Now the program works.

WPF Printing Flow Document

Greetings,
I have a problem with printing in WPF.
I am creating a flow document and add some controls to that flow document.
Print Preview works ok and i have no problem with printing from a print preview window.
The problem exists when I print directly to the printer without a print preview. But what is more surprisingly - when I use XPS Document Writer as a printer
everyting is ok, when i use some physical printer, some controls on my flow document are not displayed.
Thanks in advance
Important thing to note : You can use XpsDocumentWriter even when printing directly to a physical printer. Don't make the mistake I did of avoiding it just because you're not creating an .xps file!
Anyway - I had this same problem, and none of the DoEvents() hacks seemed to work. I also wasn't particularly happy about having to use them in the first place. In my situation some of the databound controls printed fine, but some others (nested UserControls) didnt. It was as if only one 'level' was being databound and the rest wouldn't bind even with a 'DoEvents()' hack.
The solution was simple though. Use XpsDocumentWriter like this. it will open a dialog where you can choose whichever installed physical printer you want.
// 8.5 x 11 paper
Size sz = new Size(96 * 8.5, 96 * 11);
// create your visual (this is a WPF UserControl)
var template = new PackingSlipTemplate()
{
DataContext = new PackingSlipViewModel(order)
};
// arrange
template.Measure(sz);
template.Arrange(new Rect(sz));
template.UpdateLayout();
// print to XpsDocumentWriter
// this will open a dialog and you can print to any installed printer
// not just a 'virtual' .xps file
PrintDocumentImageableArea area = null;
XpsDocumentWriter xps = PrintQueue.CreateXpsDocumentWriter(ref area,);
xps.Write(template);
I found the OReilly book on 'Programming WPF' quite useful with its chapter on Printing - found through Google Books.
If you don't want a print dialog to appear, but want to print directly to the default printer you can do the following. (For me the application is to print packing slips in a warehouse environment - and I don't want a dialog popping up every time).
var template = new PackingSlipTemplate()
{
DataContext = new PackingSlipViewModel(orders.Single())
};
// arrange
template.Measure(sz);
template.Arrange(new Rect(sz));
template.UpdateLayout();
LocalPrintServer localPrintServer = new LocalPrintServer();
var defaultPrintQueue = localPrintServer.DefaultPrintQueue;
XpsDocumentWriter xps = PrintQueue.CreateXpsDocumentWriter(defaultPrintQueue);
xps.Write(template, defaultPrinter.DefaultPrintTicket);
XPS Document can be printed without a problem
i have noticed one thing:
tip: the controls that are not displayed are the controls I am binding some data, so the conclusion is that the binding doesn't work. Can it be the case that binding is not executing before sending the document to the printer?

Resources