Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple WinForms app with LA
#1
(Caution: After I reread this, it sounds like it'll be about SharpDocx, but that's just the motivation for the post. I'm trying to use LibreAutomate with SharpDocx. SharpDocx allows use of C# code with a Word file, which is executed when the doc is generated. See the SharpDocx github repo for more if you're interested. )

Ideally I would use wpfBuilder to interact with SharpDocx. For now, I'm getting namespace and assembly errors from my flailing around, so for now I'm using Winforms. To that end, I created a simple Winform that does in fact run from SharpDocx, though I'm just posting the Winform itself that runs directly from LA. No main() method, just top-level statements. I'm sure there's a better way, and if I find one I'll share it.

That said, here's a link to a standalone Winforms designer, no documentation in any language I speak of, but it works: SWD4CS. Caveats for that program is are a) you'll have to build it, and b) once you have it compiled you can make nice Winforms with code to copy, but you'll get a Form1.Designer.cs that you'll have to tweak (read: mangle).

Hopefully this code can serve as a starting point for creating your own Winforms to use with LibreAutomate.
 
Code:
Copy      Help
using System;
using System.Windows.Forms;

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Form Form1 = new Form();
Form1.Text = "Form1";
Form1.Size = new System.Drawing.Size(480, 400);

var Button0 = new Button {
    Text = "MyButton",
    Location = new System.Drawing.Point(48, 48),
    Size = new System.Drawing.Size(104, 23)
};


var TextBox1 = new TextBox {
    Multiline = true,
    Text = "TextBox1",
    Location = new System.Drawing.Point(60, 84),
    Size = new System.Drawing.Size(320, 80),
    TabIndex = 1
};

var ListBox2 = new ListBox {
    ItemHeight = 15,
    Location = new System.Drawing.Point(64, 180),
    Size = new System.Drawing.Size(316, 154),
    TabIndex = 2
};

Form1.Controls.Add(Button0);
Form1.Controls.Add(TextBox1);
Form1.Controls.Add(ListBox2);

// ? Add a Click event handler
Button0.Click += (sender, e) => {
    // Example: write to the textbox and listbox
    TextBox1.AppendText("\r\nButton clicked at " + DateTime.Now);
    ListBox2.Items.Add("Clicked at " + DateTime.Now.ToLongTimeString());
    // Or show a popup:
    // MessageBox.Show("Button was clicked!");

};

Application.Run(Form1);

Best regards,
burque505

P.S. I forgot mention. the attached screenshot is from the Winform being run as part of the generation of a docx file with SharpDocx. Looks exactly the same and runs the same when executed standalone.


Attached Files Image(s)
   


Forum Jump:


Users browsing this thread: 1 Guest(s)