|
jschell wrote: Obviously a good decision by that person because they are in fact
different. The fact that there seem to be common components between
them is NOT sufficient reason to assume that they are the same. As an example
the fact that Word and Visual Studio both allow me to type text doesn't mean
that those two code bases should be merged.
This is an entirely stupid argument.
You're saying it's ok to have 2 entirely duplicate forms and their code becuase the data they work with is different.
jschell wrote: The right way is to re-assess the decision to combine them in the first place.
Nothing you have posted here suggests that they should be combined. And in fact
what has been posted would suggest that they should NOT be combined.
Again, same form, same code, different data - There is NO good reason to have 2 identical forms.
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: This is an entirely stupid argument.
Nope. I have seen countless attempts by people to combine code based on nothing more than what they perceive as code duplication. That happens a lot with inheritance. It focuses on the duplication instead of focusing on the need.
Kevin Marois wrote: You're saying it's ok to have 2 entirely duplicate forms and their code becuase the data they work with is different
What I said was that from what you posted here that is the case.
Kevin Marois wrote: There is NO good reason to have 2 identical forms.
Actually there can be a very good reason. Because they represent two different conceptual entities. Because they are different it can mean that in the future they might go in different directions.
Again code duplication is not the sole criteria that one uses to make this decision. And I gave you a specific example which would demonstrate why one wouldn't do that.
Without more information all I can suppose is that what you really need, if indeed there is a real need at all, is a helper class. It contains the duplicated code. The current implementations would use that.
That however still supposes that there is a real need to combine this code.
|
|
|
|
|
The best way to do this is to create an interface that encapsulates the common properties of your entities:
public interface IEntity
{
string SomeProperty { get; set; }
}
public interface IAnotherInterface
{
string Name { get; set; }
}
Each entity can inherit multiple interfaces, depending on how you want it set up:
public class Entity1 : IEntity, IAnotherInterface
{
public string SomeProperty { get; set; }
public string Name { get; set; }
}
If every entity has a certain interface, then you can require it in the Form<t> definition:
public partial class Form1<T> : Form
where T : IEntity
Finally, cast to the interfaces to set properties. If only some entities implement a given interface, check first.
void SetSomeProperties()
{
(entity as IEntity).SomeProperty = "foo";
if (entity is IAnotherInterface)
{
(entity as IAnotherInterface).Name = "bar";
}
}
|
|
|
|
|
Create an abstract Form class that contains all the "shared" code; then create 2 Forms that contain only the code / properties that are unique and inherit (are subclassed from) the abstract Form.
3 Forms, but simpler and cleaner than generics, reflection, (probably less code), etc. (IMO)
|
|
|
|
|
Hi everyone.
I have a problem and i need your help guys, it may look easy but i am not an expert in WPF stuffs, so here is my problem:
I have 2 canvas and I want to move 1 child of the first canvas to the second canvas, I' ve tried this:
canvas1.Children.Add(canvas2.Children[validIndex]);
but it didn't work!! an exception is raised which said that that child has already a parent,
so i tried to modify its parent but again.. the parent property can not be modified(has a 'get' only).
oh, i forgot to mention that I want to do this operation graphicaly, i mean by draggin that visual child from
a canvas to other, if you have an idea for that too, it will be owesome from you to share.
so Thanks in advance.
salam.
|
|
|
|
|
You might have better luck asking in the WPF forum but I believe that you would have to remove the component from the first canvas before adding it to the second.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Your best solution is to create a new instance. However, it might work if you remove the item from the first canvas and then add it to the second instance.
|
|
|
|
|
I built a control which I try to send a value to, however the control doesn't update. What must I do to have the value update.
Within the main control I have a smaller numericUpDown control. I send the value to a method within the main control. Though the value is updated programtically, it does not update on my screen.
The main control is set in a tab control on my form, yet was built in a separate library where I send the value to be updated.
I made this as a control because I access it in 2 separate forms.
Any help would be greatly appreciated.
Michael
|
|
|
|
|
You didn't say what platform you are working on, but if it's WinForms, then you may need to Refresh() the control for the changes to be visible. If the program is busy doing other things, you may also need to use Application.DoEvents() to process any Windows messages that force the refreshing.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Yes I am using WinForms.
I tried the above, and it still doesn't work.
So I tried a few other things and when I tried the following:
this.numericUpDownAccount.ActiveControl.Refresh();
It said I needed to use the new command.
So I tried both the following:
NumericUpDown numericUpDownAccount = new NumericUpDown();
and
NumericUpDown numericUpDownAccount = this.numericUpDownAccount;
and it still doesn't work.
Michael
|
|
|
|
|
OK, I hope I understand you correctly. If not, please correct me or perhaps someone else will jump in.
If it said you need to use the new command, it seems you need to create the control. You'll also need to add it to Controls list of its container. Once you do that you should be able to refresh the container and it should display your added control, assuming the control, is implemented correctly. You can look at the designer code for any Form to see how the controls are created and added to the list of controls, etc.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
But, the control is all ready created I dragged it down from the tool box. I just don't think it knows what to focus on for whatever reason.
Michael
|
|
|
|
|
this.numericUpDownAccount.ActiveControl.Refresh();
numericUpDownAccount is the name of your control and points thereto. ActiveControl is the current focused control, and might be null . That's why we have a manual.
Paste the entire method if it still does not work.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I Solved the probem, I realized after you wrote the above the control I am accessing is the original not the copy I added to my form, so I did the following in the form:
this.ctrlMainControl1.numericUpDownAccount.Value = nAccountID;
this changes he value of the copy of the control not the original control.
Thanks,
Michael
|
|
|
|
|
I have questions to ask about the following C# 2008/2010 code listed below:
Process eProcess = new Process();
eDataContext rData = new eDataContext();
string[] PkgIDs = rData.Trans.Select(c => c.Package_ID ).ToArray();
foreach (string PkgID in PkgIDs)
{
eProcess.StartInfo.FileName = "app1.exe";
eProcess.StartInfo.Arguments = "10 " + " 5" + PkgID;
eProcess.Start();
eProcess.WaitForExit();
eProcess.Close();
}
My questions are the following:
1. After the
eProcess.WaitForExit();
line of code is finished waiting for the process to finish executing, is there a way to check for the condition code returned from the run. I basically want to see if the job that executed ran successfully.
If so, can you tell me how to setup that code?
2. Do I need the line of code
"eProcess.Close();"
Why or why not?
3. I am basically looping thoough calls executing a process based upon values received in PkgID that is stored in a database table. Is this code good or not? Can you tell me why or why not? If the code is not good, can you tell me a better way to
write the code?
|
|
|
|
|
Did you happen to read the documentation on the ProcessClass??
There's a little property called "ExitCode" which will contain the exit code of the process once it terminates.
You don't need to call Close. It'll be called by the Process class Dispose method automatically, which you SHOULD be calling when you're done with the Process object.
You might want to wrap that process code in a using block to take care of this for you.
|
|
|
|
|
Hi,
I am coding a utility that will ping a computer name given by the user. If ping succeeds, I need to open C$ in Windows Explorer for that computer (\\computername\c$). I expect Windows to prompt for credentials if it is able to successfully find that path.
I have ping working properly. What do I need to do to open C$? I have been searching for awhile and haven't ran across a good example so far.
In vbscript, I would shell out and run the command 'start "" /wait \\computername\c$'. There must be a way to accomplish this but I'm not having much luck in finding the solution.
Thanks,
Rob
|
|
|
|
|
Use the Process class.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Yeah, as Eddy said, but why bother pinging first? It seems a needless step.
|
|
|
|
|
I guess pinging isn't really necessary with the proper error handling in place. It might make the app a little faster too.
I haven't looked at the Process class but the example below seems to work:
System.Diagnostics.Process.Start("explorer", "file://PROG2/");
If I just drop the ping part out of there and attempt to connect to C$ on a network client computer without testing via ping first, there is a 50/50 chance that it will be able to succeed. What is the best way to handle this scenario if the client is unavailable?
modified 7-Sep-12 17:02pm.
|
|
|
|
|
I was using ping to verify that the computer was on the network before attempting to open the C$ share. If I try to open the C$ share and the computer is not on the network, the application will fail without some way of dealing with the error.
Could you give me some sort of idea what I should research (keywords or classes perhaps) in order to catch the error on the fly? I am new to C# and haven't found very many reliable resources to learn/research the language.
Thanks,
Rob
|
|
|
|
|
|
In a C# 2008 and C# 2010 desktop applications that I am working on, I have the following questions to ask about adding features to the app.config file:
1. I would like to know how to add a reference to an executable that needs to run. I do not want to hard code the path, I would prefer to have the data path be dynamic.
2. I would like to add 2 entires to the app.config file where the location points to two different locations where output files are placed.
Thus can you tell me and/or point me to a reference that will show me how to make the coding changes to use and app.config file and what to add to the app.config file for my goals to be accomplished? (I basically would like to know what ‘tag(s)’ in the app.config I would need to place these new references.)
|
|
|
|
|
Here is an article right here on CodeProject.
Read/Write App.Config File with .NET 2.0[^]
It should still work for future versions of .NET as well.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
The basic use of the config file is so your app can load data.
Presumably that is what you intend to do with the data once it is in there.
However ignoing how you add it to the config file, exactly when do think you are going to do this?
|
|
|
|