|
First of all, there is no need for the ref for your parameter. Form is a class and therefore passed by reference anyway.
Secondly, passing Forms around and making instances of them public to external classes is a BAD idea.
Ask yourself - what object owns what?
1. If the Form is owned by the other object, then when it creates the form it can store a reference to it for later use.
2. If the Form owns the other object , then the other object should raise events which the Form subscribes to after instanciation of the object.
3. If there is no direct relationship between the Form and the other object then I would recommend a 'manager' class that can instanciate the form and the other object, store references to them and subscribe to their events so it can handle communication between them.
Edit: A little diagram to show what I mean:
One and Two:
|---------------------------------------------------------------|
Parent V Child |
=================================== =================================== |
|-----------Subscriptions---------| |-----------Subscriptions---------| |
|Properties ============= Events | |-->|Properties ============= Events | >---|
|-----------| OBJECT |---------| | |-----------| OBJECT |---------|
|Methods ============= Call/Set| --|-->|Methods ============= Call/Set|
=================================== ===================================
Three:
|--------------------------------------------|
Manager V |
=================================== |
|-----------Subscriptions---------| |
|Properties ============= Events | |
|-----------| OBJECT |---------| |
|Methods ============= Call/Set| >---| |
=================================== | |
|---------------------------------------------|-------------------| |
| | |
| | |
| =================================== | =================================== |
| |-----------Subscriptions---------| | |-----------Subscriptions---------| |
|-->|Properties ============= Events | >--| |-->|Properties ============= Events | >--|
| |-----------| OBJECT |---------| | | |-----------| OBJECT |---------| |
|-->|Methods ============= Call/Set| | |-->|Methods ============= Call/Set| |
=================================== | =================================== |
|---------------------------------------------|
modified on Thursday, October 22, 2009 3:24 PM
|
|
|
|
|
Wow - you created a diagram and all and got no response, and no 5 ? I corrected it.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
fived
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Pleaseeee...help me!!i'm so confused find the right code to copy my image from my picturebox,to new page at Adobe Photoshop.And i want the picture that i move with original type of files.(ex.if the image in .png,then when i drag to photoshop,it still in .eps format.)
i don't know how to do it.Can anyone help me solve this problem?i need it very much.thx
|
|
|
|
|
You have no control whatsoever over what Photoshop does when you drag and drop a picture. However, the picture will be a bitmap in memory, Photoshop is just trying to save in it's default format when you try to save a file.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
OK, so I have my TabControl, which is by the way owner drawn, and I have my TabPages. I want to make the user able to, when a TabPage is clicked and the mouse is moving, move the contents of the TabPage. Now, the moving is working, but my MouseMove event is firing even though my mouse isn't moving!
This is the code:
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
bool foundItem = false;
int index = -1;
foreach (TabPage page in this.TabPages)
{
index++;
if (this.GetTabRect(index).Contains
(e.Location) == true)
{
_hoverIndex = index;
this.Invalidate();
foundItem = true;
if (this.TabMouseEnter != null)
{
TabMouseEventArgs tabArgs = new TabMouseEventArgs();
tabArgs.TabPage = page;
this.TabMouseEnter(this, tabArgs);
}
}
else if (foundItem == false)
{
_hoverIndex = -1;
this.Invalidate();
if (this.TabMouseLeave != null)
{
TabMouseEventArgs tabArgs = new TabMouseEventArgs();
tabArgs.TabPage = page;
this.TabMouseLeave(this, tabArgs);
}
}
}
if (e.Button == MouseButtons.Left)
{
if (_hoverIndex != -1)
{
DockStyle dockStyle = this.DockPanel.Dock;
this.DockPanel.DockPane.HideDockRectangles();
DockForm dockForm = new DockForm();
DockPanel dockPanel = this.DockPanel;
this.DockPanel.DockPane.Controls.Remove(dockPanel);
dockPanel.Dock = DockStyle.Fill;
dockForm.Location = Cursor.Position;
dockForm.Controls.Add(dockPanel);
dockForm.Renderer = this.Renderer;
dockForm.Show();
this.DockPanel.DockForm = dockForm;
List<TabPage> removePages = new List<TabPage>();
foreach (TabPage page in this.TabPages)
{
if (page != this.DockPanel.MainTabPage)
removePages.Add(page);
}
foreach (TabPage page in removePages)
{
foreach (Control control in page.Controls)
{
if (control is DockContainer)
{
DockContainer container = control as DockContainer;
this.DockPanel.DockPane.CreatePanel(container.Form, dockStyle);
this.TabPages.Remove(page);
}
}
}
}
}
}
This is really the only related code. Any ideas?
|
|
|
|
|
Theodor Storm Kristensen wrote: Any ideas?
It seems to be designed that way[^].
I are Troll
|
|
|
|
|
Thanks for the link, it works now.
|
|
|
|
|
I can't believe I'm doing this...
In my job, I have to digitally sign .MSI files before deployment. Previously, this was done using the CAPICOM 2.1 library and a manual wizard-based process to sign the .MSI.
Seeing an opportunity for process improvement, I scripted this process into a drag-and-drop operation where you just drop the .MSI file on the script and it would use the CAPICOM COM objects to find the appropriate code-signing certificate and sign the file for you, baking the signed hash into the file. When you went out to Explorer, you get the properties on the file and click the Digital Signatures tab, whaalaa, you can see the signature!
This process worked great under Windows XP...
Now, move to Windows 7 (we're skipping Vista! ). CAPICOM is no longer in the Windows SDK and is no longer supported as it is offically deprecated by MS. MS says that the same functionality CAPICOM provided can be cobbled together using managed code and the .NET Framework.
I've tried to get CAPICOM to work under Windows 7, but I haven't been able to get any of the COM objects to instantiate. So, now I'm trying to poke around the classes under the System.Security.Cryptography namespace and put together a process to digitally sign an .MSI file (or any other file for that matter,) but do it the with the signature in the file. Having a seperate signed hash in a p7s file does me no good. It must be baked into the .MSI just like the old CAPICOM process did it.
Anyone got any clues or research points to rebuilding this process in managed code? Which classes am I looking at?? I can see the the X509 certificates using the classes in the System.Security.Cryptography.X509Certificates namespace, but can't seem to piece together the signing process. What am I missing?
|
|
|
|
|
For the offical word on CAPICOM support under Windows 7, read this[^].
After about 90 minutes of excersizing my Google Fu, I finally found this[^], which states that I'll have to resort to P/Invoking the Win32 functions I need to get the files signed with an embedded signature. Yuk! Why couldn't they provide an entirely managed solution to replace CAPICOM?!
|
|
|
|
|
Hi,
I need to write a program which can copy a file simply from a source folder to a destination folder.
Please include the codes for a simple program doing so.
|
|
|
|
|
Below is the sample VB.NET Code. Hope you can convert it easily using C#.
using System.IO
Public Sub CopyDir(ByVal strSrc As String, ByVal strDest As String)
Dim dirInfo As New DirectoryInfo(strSrc)
Dim fsInfo As FileSystemInfo
If Not Directory.Exists(strDest) Then
Directory.CreateDirectory(strDest)
End If
For Each fsInfo In dirInfo.GetFileSystemInfos
Dim strDestFileName As String = Path.Combine(strDest, fsInfo.Name)
If TypeOf fsInfo Is FileInfo Then
File.Copy(fsInfo.FullName, strDestFileName, True)
'This will overwrite files that already exist
Else
CopyDir(fsInfo.FullName, strDestFileName)
End If
Next
End Sub
Source : http://abhijitjana.blogspot.com/2007/10/copy-files-from-one-directory-to.html[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
If you keep writing their code for them the will pass the exams, and one day you may end you having to mantain some of their code - even worse, I may end up having to fix it
Give a hint, but please refrain from giving code for something as trivial as this otherwise they will never learn that one of the more important aspects of development is learning how to work things out for yourself. I mean, how difficult is it to go to google and put in file copy c# and look at the top few of the 815,000 hits.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Ashfield wrote: Give a hint,
Most of the cases I did the same. Just give the hint so that they can take it forward.
Ashfield wrote: how difficult is it to go to google and put in file copy c# and look at the top few of the 815,000 hits.
I do the same and Got the link from my Old Blog and I put it over here.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
use
System.IO.File.Copy(src,dest)
where src and dest are source and target respectively.
|
|
|
|
|
If I were to invent a company policy about when programmers should or shouldn't override the Equals() function, what should that policy be and why?
I know when to do it on a case by case basis, but how would I establish a that in terms of a company policy or coding standards document?
Your thoughts?
|
|
|
|
|
When (not) to override Equals()[^].
Don't know if this actually helps you but I found it a couple of days ago.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Whenever a reference type's equality should be determined by something else (such as a field/property's value or reference) rather than the class' reference itself.
|
|
|
|
|
sory thet my english in is not good
i need to convert class i build to byte [] array,
for send it over socket .
after i received the byte i wona convert it again to my class
thenk for help
bar !
my class :
namespace WindowsFormsApplication1
{
public class Class1
{
private string a;
public Class1()
{ }
public Class1(string a)
{ this.a = a; }
public void set (string a)
{ this.a = a; }
public string get()
{ return this.a; }
}
}
|
|
|
|
|
|
who i can make it ?
you can send me a code?
tenks!
|
|
|
|
|
b.sahahf wrote: you can send me a code?
If you pay for it, yes. Otherwise, you'll have to write it yourself. The documentation is usually a good place to start, the link to the BinaryFormatter contains a sample that can almost be copied literally. It contains this sample;
static void Serialize()
{
Hashtable addresses = new Hashtable();
addresses.Add("Jeff", "123 Main Street, Redmond, WA 98052");
addresses.Add("Fred", "987 Pine Road, Phila., PA 19116");
addresses.Add("Mary", "PO Box 112233, Palo Alto, CA 94301");
FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, addresses);
}
catch (SerializationException e)
{
Console.WriteLine("Failed to serialize. Reason: " + e.Message);
throw;
}
finally
{
fs.Close();
}
} Good luck with your project
I are Troll
|
|
|
|
|
|
I wrote a program that will find all links to PDF's on a site and download them. However when I look at the downloaded PDF's they are all the same size and corrupted. If I download them via IE they are differnt sizes and they open just fine.
My download code is:
Webclient wc = new WebClient();
wc.DownLoadFile("http://www.somesite.com/somepage/somefile.pdf", "c:\site\somefile.pdf");
I get no errors. I'm not sure if this makes a difference but if I look at the source of the site they have the href to the pdf as href="/somepage/somefile.pdf" I string the hostname to the front of the URL.
I know I can do an httpwebrequest but how will I know how big to make my buffer.
Suggestions?
Thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Have you ever looked what is in those corrupted PDFs? Maybe you will find a html-site that tells you that the file wasn't found on this server or you maybe haven't the right to access to file directly.
|
|
|
|