Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help needed: Set DefaultButton for dialog
#1
Hello, I see in the Library section of the docs that there is a way to set a dialog's DefaultButton, but I didn't find any examples and my experimenting hasn't worked.
Might I trouble you for a short example?
Best regards,
burque505
#2
Code:
Copy      Help
var d = new dialog();
d.SetText("Main text.", "More text.\nSupports <a href=\"link data\">links</a> if you subscribe to HyperlinkClicked event.");
d.SetButtons("1 OK|2 Cancel|3 Custom|4 Custom2");
d.SetIcon(DIcon.Warning);
d.SetExpandedText("Expanded info\nand more info.", true);
d.CanBeMinimized = true;
d.SetCheckbox("Check");
d.SetRadioButtons("1 r1|2 r2");
d.SetTimeout(30, "OK");
d.HyperlinkClicked += e => { dialog.show("link clicked", e.LinkHref, owner: e.hwnd); };
d.ButtonClicked += e => { print.it(e.Button); if(e.Button == 4) e.DontCloseDialog = true; };
d.ProgressBar = true; d.Timer += e => { e.d.Send.Progress(e.TimerTimeMS / 100); };
d.DefaultButton=4;
var r = d.ShowDialog();
print.it(r, d.Controls.IsChecked, d.Controls.RadioId);
switch(r) { case 1: print.it("OK"); break; case dialog.Timeout: print.it("timeout"); break; }

or set as argument of dialog.show
Code:
Copy      Help
switch(dialog.show("Save?", "More info.", "1 Save|2 Don't save|0 Cancel" , 0, 0, default, "", "", "Test", null, 2)) {
case 1: print.it("save"); break;
case 2: print.it("don't"); break;
default: print.it("cancel"); break;
}
#3
Thank you, Kevin, that's certainly helpful. What I'm actually trying to do is accomplish the same thing thing with a wpfBuilder dialog's only button.
For example:
Code:
Copy      Help
var b = new wpfBuilder("Select").Width(185);
b.R.Add(out Button btn1, "Number of Sections").Add(out TextBox tb1).Width(80).Focus();
Can you tell me how I can make 'btn1' the default button?
Best regards,
burque505
#4
Found one way to do it with wpfBuilder: XAML. Don't have a way to do it just in code yet. Seems like there should be a way to do that. But this serves my purpose. Thanks again for your help, Kevin!
 
Code:
Copy      Help
var xaml = """
<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
Name="btnDefault" IsDefault="true"> OK</Button>
"""
;
Button myButton = System.Windows.Markup.XamlReader.Parse(xaml) as Button;


Best regards,
burque505
#5
Code:
Copy      Help
// script ""
using System.Windows;
using System.Windows.Controls;

var b = new wpfBuilder("Window").WinSize(400);

//add button Test and set default
b.R.AddButton("Test", 3);
((
Button)b.Last).IsDefault = true;

//set OK non-default. Without it need to press Enter 2 times to close the window.
b.R.AddOkCancel(out var bOK, out _, out _);
bOK.IsDefault = false;

b.End();
if (!b.ShowDialog()) return;
print.it(b.ResultButton);
#6
Thanks, Gintaras, very nice. Solved!
Best regards,
burque505


Forum Jump:


Users browsing this thread: 1 Guest(s)