|
As I said I my post-the value IS being set
If it's not broken, fix it until it is
|
|
|
|
|
Coder (Hired) wrote: As I said I my post-the value IS being set Sorry, I'm tired.
You should run your download-method in a background-worker * . When running it on the UI-thread, the UI-thread can't repaint the progress bar.
At least not reliably. Actually I'm a bit confused myself now. I would have assumed repainting wouldn't happen at all until your download-method finishes. But I just set up a quick test-project and the progress bar-repainting did work "partially" (stuttering) while the UI thread was executing the setprogress-sleep-loop. Maybe someone else coming along here can shed some light on that.
However, running lengthy processes in a background worker * and not on the UI-thread is advisable in any case to keep your UI responsive and will definitely solve your issue.
* or some other multithreading-flavor
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Ok, but how does the dialog fit into the BG worker? The dialog is in the UI thread. how does the worker notify it that progress changed?
If it's not broken, fix it until it is
|
|
|
|
|
|
One thing to consider is that the app cannot continue if the 2 files are not downloaded, so there's no reason why this can't be a blocking call
If it's not broken, fix it until it is
|
|
|
|
|
The "blocking nature" would have to be implemented by showing DownloadDialog modal (by calling .ShowDialog() instead of .Show()).
You can indicate success/failure along with any other result values of the download process with the Result-Property of DoWorkEventArgs and then proceed accordingly.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Why not use a MethodInvoker that wraps the download code. I could pass that to the dialog, then in the Shown event I could fire it off.
The only question then is how does that code update the UI?
Something like this:
private MethodInvoker GetConfigFileDownloadInvoker()
{
MethodInvoker invoker = new MethodInvoker(delegate
{
});
return invoker;
}
private MethodInvoker GetDatabaseDownloadInvoker()
{
MethodInvoker invoker = new MethodInvoker(delegate
{
});
return invoker;
}
private void DownloadDeviceFiles()
{
DatabaseDownloaded = false;
ConfigFileDownloaded = false;
MethodInvoker invoker1 = GetConfigFileDownloadInvoker();
MethodInvoker invoker2 = GetDatabaseDownloadInvoker();
dialog = new DownloadDialog(invoker1, invoker2);
dialog.Text = "Retrieving Mission Data";
dialog.Progress1Caption = "Config File";
dialog.Progress2Caption = "Database";
dialog.StartPosition = FormStartPosition.CenterScreen;
dialog.ShowDialog(this);
if (!ConfigFileDownloaded || !DatabaseDownloaded)
{
OnDisconnected(EventArgs.Empty);
}
}
If it's not broken, fix it until it is
modified 29-Apr-15 17:32pm.
|
|
|
|
|
The MethodInvokers don't really gain you anything - they'd just move the point where you start the download-method from your parent form to your download dialog. To achieve a responsive UI you'd still need some kind of dedicated download thread.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Ok, I can see how a background worker would work. I guess I'll have to use that
If it's not broken, fix it until it is
|
|
|
|
|
Ok, so I added a BW, and in the I now have:
private void configWorker_DoWork(object sender, DoWorkEventArgs e)
{
if (InvokeRequired)
{
var del = new configWorker_DoWorkDelegate(configWorker_DoWork);
Invoke(del, new object[] { this, e });
}
else
{
dialog.ShowDialog(this);
DownloadConfigFile();
}
}
so now it sits there until I close the dialog.
I'm not getting this. Could use some help.
Remmeber, this needs to block until BOTH files are downloaded.
If it's not broken, fix it until it is
|
|
|
|
|
Don't put any UI stuff into the BW. It should look something like the following. Not tested, obviously, and it's a bit hacky. It would actually make sense to start the BW from the DownloadDialog in order to ensure that the DownloadDialog "exists" when ProgressChanged and RunWorkerCompleted fire.
class Form1 : Form
{
BackgroundWorker worker;
DownloadDialog downloadDialog;
public Form1()
{
InitializeComponent();
worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.ProgressChanged += worker_ProgressChanged;
worker.DoWork += worker_DoWork;
worker.RunWorkerCompleted += worker_RunWorkerCompleted;
}
void DownloadStartButton_Click(object sender, EventArgs e)
{
DownloadDeviceFiles();
}
void DownloadDeviceFiles()
{
worker.RunWorkerAsync();
DownloadDialog downloadDialog = new DownloadDialog();
downloadDialog.Text = "Retrieving Mission Data";
downloadDialog.Progress1Caption = "Config File";
downloadDialog.Progress2Caption = "Database";
downloadDialog.StartPosition = FormStartPosition.CenterScreen;
downloadDialog.ShowDialog(this);
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = DownloadConfigFile() && DownloadDatabase();
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (downloadDialog != null)
downloadDialog.Progress1PercentDone = e.ProgressPercentage;
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
downloadDialog.Close();
downloadDialog.Dispose();
if (e.Result == true)
else
}
bool DownloadConfigFile()
{
while (true)
{
worker.ReportProgress(percentDone);
}
return downloadSuccess;
}
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
100% right on!
THANK YOU! THANK YOU! THANK YOU!
If it's not broken, fix it until it is
|
|
|
|
|
You're welcome
(The invoice is on its way )
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Hy, I'm new to CodeProject.
I'm trying to set text to label.
When I assign text "Lahore is the capital city of the Pakistani province of Punjab, the second largest metropolitan area in the country and an important historical center in South Asia.", It does not display full text.
I have a label with size(200, 70), font(Arial, 15pt).
I want to assign only the text which fits on label (using defined size and font, that does not dsplay (...) at the end) and save the remaining text in a string variable.
Please Help.
|
|
|
|
|
To do that, you would have to measure the string and work out from that how much of it will fit.
See here: Graphics.MeasureString[^] but to use it, you need to get a Graphics context for the label (which you are responsible for Disposing when you are finished with it): Control.CreateGraphics(v=vs.110).aspx[^]
Don't expect this to be trivial!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Can you please gave me an example???
|
|
|
|
|
Why don't you give it a try yourself first? For me figuring new stuff out myself is one of the most rewarding aspects of being a software developer. There will probably also be basic examples on those pages OriginalGriff linked for you or you can find some by googling for it.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
You have all the information you need to do your own research now.
|
|
|
|
|
The only example I could give you - other than that in the two links - is basically to do it all for you, and that isn't what we are here for!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
sir, i want to resize the controls like label,picturebox,textbox,barcode,etc proportionally in c#...
thanks in advance..
|
|
|
|
|
|
Where's the question part? How to do so? There are some examples out there, listed on Google.
I'd recommend against it though; it isn't very helpful to have a 640x480 form resize to fill the entire 1024x768.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: it isn't very helpful to have a 640x480 form resize to fill the entire 1024x768.
It's very Metro though!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi All
My goal is create a usercontrol with some childs controls enabling the editing, in design mode, of this childs, so i'll rearrange the positions of childs.
I found the (partial) solution to my problem generating another problem.
I'll try to explain my problem:
1 Create a UserControl
2 Drop on it a Label (name Label1) at the coordinates 1,1 (EXAMPLE)
3 the code of Control must be appear like this:
//--------------------------------------------------
[Designer(typeof(cntLabelDesigner))] // <-- Use of a custom designer to enable edit of the childs
public partial class cntBaseTextBox : UserControl {
// Expose the label1 creating a public property and serializing it
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Label lbl { get { return this.Label1; } }
public cntBaseTextBox() {
InitializeComponent();
}
}
// Custom class designer
class cntLabelDesigner : ControlDesigner {
public override void Initialize(IComponent comp) {
base.Initialize(comp);
if (this.Control is cntBaseTextBox) {
var uc = this.Control as cntBaseTextBox;
this.EnableDesignMode(uc.lbl, "xLabel");
}
}
}
//--------------------------------------------------
4 create a form and drop the usercontrol on it, the coordinates writed on form ..designer.cs for the label are 1,1 ....
NOW THE PROBLEM
If i move my label in another position seem to be all OK but if you see the new coordinates wrote on form ..designer.cs are relative to the forms and not relative to the parent control ... infact if i save and recall my form the label will be in another position or is disappeared because it's coordinates ar outside the usercontrol.
Can anyone help me ?
This is a normal behavior or is an IDE's Bug ?
I'm using VS community 2013 Upgrade 4 ...
Thanx in Advance and SFMBE.
Emanuele
-----------------------------------------------------------
After hour and hour of purisms ... i found a Quick & Dirty solution (bleahhh!). On UserContrl Load Events i test if label coordinates are changed (so the coordinates are referred on client area) .. if so i correct the substracting to it the coordinate of user control ... i know that this is a stink solution.
Anyoone had a better solution or can say me if this behaviour is a bug ?
private void cntBaseTextBox_Load(object sender, EventArgs e) {
if (!this.Label.Location.Equals(new Point(4, 4))){
this.Label.Location = new Point(this.Label.Location.X - this.Location.X, this.Label.Location.Y - this.Location.Y);
}
}
modified 29-Apr-15 10:31am.
|
|
|
|
|
This is a normal behavior or is an IDE's Bug ? Well, it's a "normal" behavior in the sense it is doing what your code tells it to do.
If I reproduce your code in Visual Studio 2013, compiling with FrameWork 4.5, I can reliably crash Visual Studio !
Getting the design-time functionality in a UserControl you want is very difficult, and I believe, but am not certain, that it would require writing a custom type-designer.
I'd like to mention two alternatives:
1. by exposing the internal Controls in the UserControl with Public Properties, you do get the ability at design-time ... when you drag-drop the UserControl into a Form, or Panel, or whatever ... to use the Property Browser to edit all aspects of the internal Controls exposed by your the UserControl's public properties.
2. You can enable your UserControl instances ... placed on a Form or whatever ... so you can drag and drop other controls onto/into them: see this Tip/Trick I wrote: [^].
Hope this is helpful !
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|