Is it possible to update the winform after it has started.
for example.
import clr
clr.AddReference("System")
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import (Application, Form, StatusBar)
form = Form()
form.sb = StatusBar()
form.sb.Parent = form
form.sb.Text = "Demo"
Application.Run(form)
form.sb.Text = "Test"
I am able to see "Demo" but not the "Test".
How to change the status bar after Application.Run?
Just add code into the load event
private void Form_Load(object sender, EventArgs e)
{
sb.Text = "Test";
Application.DoEvents();
}
Call do events to force a repaint of the form.
VB
Private Sub Form_Load(Byval Sender As Object, Byval e As EventArgs)
sb.Text = "Test"
Application.DoEvents()
End Sub
Application.Run(form) starts a standard application loop on the current thread. That means the line form.sb.Text = "Test" won't actually do anything until the form is closed. You can show the form by using form.Show(), and it would be possible to update it then.
You could do one of two things. First, as Wheels73 suggested, add an event handler on the form load event. You can accomplish that with the following lines.
def form_load(sender, e):
sender.sb.Text = 'Test'
form.Load += form_load
Application.Run(form)
You could also create a class for the form and add event handlers in there. I would recommend giving this a read: http://www.voidspace.org.uk/ironpython/winforms/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With