|
|
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"
|
|
|
|
|
Thanks for the answer.
I tried the code on sharp-develop and the behavior is the same so isn't an IDE behavior.
My primary goal "WAS" move various controls inside the usercontrol visually. The exposure of property was relatively a secondary problem for me ...
But i noticed that when i enabledign for subcontrols and i move that subcontrols, they loose the "coordinate-link" with the usercontrol, so if i move the user control the subcontrols don't follows .... this aspect have destroyed my dreams 8))) ... so i now i had a classic usercontrol with some subcontrols and an associated smart tags window with a visual configuration style property that change the positions of subcontrols ...
|
|
|
|
|
Recently with the precious help of some forum users i have developed a search application of folders and subfolders. Here's the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace Procura_Desenhos1._1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txt_procura_TextChanged(object sender, EventArgs e)
{
}
private void btn_procura_Click(object sender, EventArgs e)
{
string toFind = txt_procura.Text;
var root = new DirectoryInfo(@"c:\");
var matchingDirectories = SafeEnumerateDirectories(root)
.Where(d => string.Equals(d.Name, toFind, StringComparison.OrdinalIgnoreCase))
;
foreach (DirectoryInfo directory in matchingDirectories)
{
Process.Start(new ProcessStartInfo
{
FileName = directory.FullName,
UseShellExecute = true,
Verb = "open"
});
}
}
public static IEnumerable<DirectoryInfo> SafeEnumerateDirectories(DirectoryInfo root)
{
if (root == null) throw new ArgumentNullException("root");
if (!root.Exists) return Enumerable.Empty<DirectoryInfo>();
return SafeEnumerateDirectoriesCore(root);
}
private static IEnumerable<DirectoryInfo> SafeEnumerateDirectoriesCore(DirectoryInfo root)
{
var searchPaths = new Stack<DirectoryInfo>();
searchPaths.Push(root);
while (searchPaths.Count != 0)
{
DirectoryInfo currentPath = searchPaths.Pop();
yield return currentPath;
DirectoryInfo[] subFolders = null;
try
{
foreach (var subDirectory in currentPath.EnumerateDirectories())
{
searchPaths.Push(subDirectory);
}
}
catch (UnauthorizedAccessException)
{
}
}
}
}
}
However the path C: it was only for testing (var root = new DirectoryInfo (@ "C: \");) the goal is that the application search folders on a local server (var root = new DirectoryInfo (@ "\ vgst \ clients \ ");). Inside the folder clients there are hundreds and hundreds of subdirectories with a unique ID that is not repeated, this ID is the reference sale. Already tested and the application works however is very slow in searching ,sometimes takes several minutes to open the folder that we sent to search. Is there any way to accelerate this search?
Thanks again,
|
|
|
|
|
Member 11401516 wrote: Is there any way to accelerate this search
Yes store you data in a database instead of the file system. This is a classic reason why file systems are NOT use to store voluminous data.
Never underestimate the power of human stupidity
RAH
|
|
|
|