|
clearly it's a friday, because I'm still not getting it . I've posted the code from files.cs which is loaded by the main form (FrmMain.cs)...
using System;
using System.IO;
using System.Threading;
namespace BMWImageCopier
{
public class Files
{
public Files()
{
}
public string sMediaDir = "";
public string sBuildDir = "";
public string sFoldersCopied = "";
public string sMediaFoldersFilter = "";
public bool bIsBMW = true;
private void CheckFolderExists(string sFolder) {
try
{
if (!Directory.Exists(sFolder)) {
Directory.CreateDirectory(sFolder);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to create build directories\n" + err.Message + "\n";
}
}
private void updateLabel(string sText) {
FrmMain oFrmMain = new FrmMain();
BeginInvoke (new MethodInvoker(
delegate() {oFrmMain.updateStatusLabel(sText);}
));
Thread.Sleep(1000);
oFrmMain = null;
}
public void GetFolders(string sDir) {
try
{
string sBuildFolder = "";
string[] folders = Directory.GetDirectories(sDir);
bool bFilteredFolder = false;
foreach(string folder in folders)
{
if (sMediaFoldersFilter == "All")
{
bFilteredFolder = true;
}
else {
string[] sFolderFilters = sMediaFoldersFilter.Split(new char[] {','});
foreach (string filterFolder in sFolderFilters)
{
if (folder.IndexOf(filterFolder) > -1)
{
bFilteredFolder = true;
break;
}
}
}
if (bFilteredFolder) {
string sFolder = folder.Substring(folder.LastIndexOf("\\") + 1);
CheckFolderExists(sBuildFolder);
CopyFiles(folder,sBuildFolder);
}
bFilteredFolder = false;
GetFolders(folder);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to read directories\n" + err.Message + "\n";
}
}
private void CopyFiles(string sMediaDir, string sBuildDir) {
try
{
string[] files = Directory.GetFiles(sMediaDir);
foreach (string file in files)
{
updateLabel("copying : " + sMediaDir.ToString());
string name = Path.GetFileName(file);
string dest = Path.Combine(sBuildDir,name);
File.Copy(file,dest,true);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to copy files\n" + err.Message + "\n";
}
}
}
}
p.s. thanks for bearing with me .
|
|
|
|
|
liamderice wrote: thanks for bearing with me
No problem
I think I know where your problem is - you're trying to update from another class and from another thread?
If so, you need to have an event in the Files.cs that FormMain can subscribe to. Give me a few minutes and I'll knock up some demo code for you. In the meantime, have a look at my article Events Made Simple. It covers most of this.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
This works.
using System;
using System.Threading;
using System.Windows.Forms;
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
Shown += new EventHandler(Form1_Shown);
}
void Form1_Shown(object sender, EventArgs e)
{
Thread CopyThread = new Thread(new ThreadStart(DoStuff));
CopyThread.Start();
}
void UpdateLabel(string text)
{
label1.Text = text;
}
void DoStuff()
{
Files files = new Files();
files.TextUpdate += new EventHandler<TextEventArgs>(files_TextUpdate);
files.CountToTen();
files.TextUpdate -= files_TextUpdate;
}
void files_TextUpdate(object sender, TextEventArgs e)
{
BeginInvoke(new MethodInvoker(
delegate() { UpdateLabel(e.Text); })
);
}
}
public class Files
{
public event EventHandler<TextEventArgs> TextUpdate;
public void CountToTen()
{
for (int i = 0; i <= 10; i++)
{
OnTextUpdate(new TextEventArgs(String.Format("Counted to {0}", i)));
Thread.Sleep(1000);
}
}
protected virtual void OnTextUpdate(TextEventArgs e)
{
EventHandler<TextEventArgs> eh = TextUpdate;
if (eh != null)
eh(this, e);
}
}
public class TextEventArgs : EventArgs
{
private string _Text;
public TextEventArgs(string text)
{
_Text = text;
}
public string Text
{
get { return _Text; }
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
try
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
|
|
|
|
|
yuxuanji wrote: CheckForIllegalCrossThreadCalls = false
and spend the next three weeks debugging when your app keeps hanging and crashing all of a sudden.
Very bad advice!
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:21 AM
|
|
|
|
|
I have a struct Range that wraps a couple of Int32s with appropriate methods and properties.
I also have a class RangeControl : Control that uses a couple of these.
I've extended both of these to generic versions so they can work with different types and everything is working fine except as soon as I change to RangeControl<T> : Control it disappears from the toolbox and I'm unable to manipulate the control in the designer.
I can do it all from code - but I was wondering if there's a way to get the designer/toolbox to play nice with the generic version?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi,
I don't think you can, the way I understand it the compiler generates the code on the fly, but it needs to know the T type before it can do so. How could the Designer get around that?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Thursday, February 19, 2009 5:46 PM
modified on Sunday, June 12, 2011 8:22 AM
|
|
|
|
|
That's what I figured but I though it was worth asking.
I can work around it by having a Type field that is set to a default value in the parameterless constructor and pass that around internally but it's a messy solution.
Stuff the designer - real men do it in code anyway!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: but it's a messy solution
yes, that is where you can outsmart Visual Designer
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:22 AM
|
|
|
|
|
hello I have a problem whit this programe i need the arry to send text of textbox to dtagrid of the diferent form
this is site were is th programme http://rapidshare.com/files/200128782/Programa_do_Stand_automoveis_2.zip.html
tanks for your help.
|
|
|
|
|
If you would like to receive an anwser on your question, please post some code with explicit bugs/flaws. If you can do that, we can help you, because nobody will download a file (to dangerous + to time consuming).
Second, make up a good topic-name, people have to see what they can expect.
|
|
|
|
|
Yep you are having real trouble with this, 3 weeks, 3 questions and you still have not moved, I suggest you give up and try some other form of entertainment, C# is obviously beyond your capabilities.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
OK - this is the last time. I had a quick look and I think I see what you want.
To attempt translation... you have several TextBoxes on a MdiChild Form. On a ButtonClick on that Form you want to send the contents of all the TextBoxes to a different MdiChild Form so you can populate a DataGridView. Is that correct?
If so, the first step is to get the data from the textboxes into a useable format in the Button's Click event handler. I would recommend a class instance with properties to hold each piece of data, but a string array or List<string> would do.
Next, you need to create a custom event like I showed you before. Raise that event like I showed you, also in the Button's Click event handler.
Next, in the MdiParent, after you have instanciated but before it's shown, subscribe to your custom event (the handling method should be created automatically for you).
You will also need a field to hold the reference to the form with the DataGridView.
In the form with the DataGridView, create a method or property that takes data in whatever format you decided in the first step and updates the DataGridView.
In the MdiParent's custom event handler method, call the other form's method/property (assuming it's not null) passing the received data.
Colin Mackay has a great article[^] - look at the section called Sibling to Sibling.
Now you have the principle, go ahead and try it, and post back with any specific problem.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Please please help with this simple Q from a C newbie....I spent hours trying to find the answer online...
I want to run this on a linux box. Open a file containing a list of file names and then run a linux commands on each of the list for example:
The file contains a list of files names eg:
test
test1
test2
test3
How do I code in C so that it opens the file and then foreach of the elements do a system command eg: ls
in perl it would be something like:
#!/usr/local/bin/perl
while(<>){
chomp;
$cmd="ls $_";
system($cmd);
print "$cmd\n";
}
Thanks in advance!
|
|
|
|
|
Hi,
this is the C# forum, C# is one of the .NET languages.
For plain old C you should post on the C++/MFC forum.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Thursday, February 19, 2009 5:47 PM
modified on Sunday, June 12, 2011 8:23 AM
|
|
|
|
|
Hi Evryone
I build WebService on Windows server 2003
when i try to connect from my C# program, it wright:
"Unable to download following files from http://11.11.11..."
is someone know whay ?
|
|
|
|
|
Impossible to say considering you don't show any of the code that is calling the web service, nor anything about the method you're calling, what it does, what it's supposed to do, ...
|
|
|
|
|
I only try to add web reference to my WS - and this is the message
|
|
|
|
|
In that case, you Google the error message ("web service add reference Unable to download following files from http")and you get this[^].
|
|
|
|
|
Does the .NET framework contain any classes that assist with caching data locally, and then automatically synchronizing that data with a website as soon as the machine is connected to the internet?
Adobe Air has direct support for this. I wonder if .NET has anything addressing this.
|
|
|
|
|
Nope. You either have to use a third party solution, or roll your own.
|
|
|
|
|
In a pc contain default hardware components. If i have add addtional components. while if the checking process will be taken on every booting time & detect any device add, if u have added to check and mismatched, the system will be come a shutdown. they matched means continue to loading OS.
And as what type of devices should be add to list out in the form of label.
To checking process using an serial number of products.
if u have use any type of database or various technique(registry, text file).
for example: already a pc contain 2 HDD normal. add another one will not boot the system.
|
|
|
|
|
Uhhh... what???
I didn't understand anything you said.
Are you asking if you can prevent Windows from booting if the hardware in the machine changes??
|
|
|
|
|
hai Dave Kreskowiak,
But i have Sorry for u haven't understand this question.very sorry for my poor English communication & and sending Questions.
my point is - simply say for - if anybody can change for my system parts, the system will not Boot. The default parts may be placed to return means no problem to boot&contiued,if any parts add or change my system set never boot.
my option is - each hardware parts contain a unique number.so i have used this NO to protect my system, unnecessary to anybody add an additonal parts or change it detect to use the serial no.
For Example: motherboard changed same brand, add 1 more Hard drive & cd drives or changing......
|
|
|
|
|
Basically, you're trying to copy protect your software. In my humble opinion, a fruitless effort.
If you're trying to use hardware serial numbers, you're wasting your time. Most manufacturer don't put serial numbers in their hardware, save for hard drives. But even using hardware is too unreliable and if your software breaks because someone had to replace a motherboard, you just lost a customer because you introduced more downtime to the system than was necessary.
If security is that big of a concern, look into USB security dongles.
|
|
|
|